1 | const path = require('path'),
|
2 | assert = require('assert'),
|
3 | common = require('./common'),
|
4 | { get, getConfigPath } = require('../src/lib');
|
5 |
|
6 | const CONFIG_PATH = path.join(__dirname, '../src/index.js');
|
7 | let packageJSON = require(path.join(process.cwd(), 'package.json'));
|
8 | let configPath = getConfigPath();
|
9 |
|
10 | describe('Config path', function() {
|
11 | let packageJSONConfigPath = get(packageJSON, "config.config path");
|
12 | it('set in package.json', function() {
|
13 | assert.ok(packageJSONConfigPath);
|
14 | });
|
15 |
|
16 | it(`=== ${configPath}`, function() {
|
17 | let resolvedConfigPath = path.resolve(packageJSONConfigPath);
|
18 | assert.strictEqual(
|
19 | resolvedConfigPath,
|
20 | configPath);
|
21 | });
|
22 | });
|
23 |
|
24 | describe('index.js', function() {
|
25 | let config = require(CONFIG_PATH);
|
26 |
|
27 | it("NODE_ENV=development", function() {
|
28 | assert.strictEqual(process.env.NODE_ENV, "development");
|
29 | });
|
30 |
|
31 | it("TEST=true", function() {
|
32 | assert(process.env.TEST);
|
33 | });
|
34 |
|
35 | it('default config validates', function() {
|
36 | common.assert_development_plus_TEST_config(config);
|
37 | });
|
38 |
|
39 | it(`get({ env: 'development' } validates`, function() {
|
40 | let config = require(CONFIG_PATH);
|
41 | let { get } = config[Symbol.for('utils')];
|
42 |
|
43 | config = get({ env: 'development' });
|
44 |
|
45 | common.assert_development_plus_TEST_config(config);
|
46 | });
|
47 |
|
48 | it(`get({ env: 'staging' } validates`, function() {
|
49 | let config = require(CONFIG_PATH);
|
50 |
|
51 | config = config({ env: 'staging' });
|
52 |
|
53 | common.assert_staging_config(config);
|
54 | });
|
55 |
|
56 | it(`use({ env: 'staging' } validates`, function() {
|
57 | let config = require(CONFIG_PATH);
|
58 | let { use } = config[Symbol.for('utils')];
|
59 |
|
60 | config = use({ env: 'staging' });
|
61 |
|
62 | common.assert_staging_config(config);
|
63 | });
|
64 | }); |
\ | No newline at end of file |