|
1 | | -import assert from 'assert'; |
2 | | -import { join } from 'path'; |
| 1 | +import { strict as assert } from 'assert'; |
3 | 2 | import feathers, { Application } from '@feathersjs/feathers'; |
| 3 | +import plugin from '../src'; |
4 | 4 |
|
5 | 5 | describe('@feathersjs/configuration', () => { |
6 | | - const originalEnv: { [key: string]: any } = {}; |
7 | | - let app: Application; |
8 | | - let plugin: any; |
| 6 | + const app: Application = feathers().configure(plugin()); |
9 | 7 |
|
10 | | - before(() => { |
11 | | - originalEnv.NODE_ENV = process.env.NODE_ENV; |
12 | | - originalEnv.NODE_CONFIG_DIR = process.env.NODE_CONFIG_DIR; |
13 | | - |
14 | | - process.env.NODE_ENV = 'testing'; |
15 | | - process.env.NODE_CONFIG_DIR = join(__dirname, 'config'); |
16 | | - process.env.PATH_ENV = '../something'; |
17 | | - |
18 | | - plugin = require('../lib'); |
19 | | - app = feathers().configure(plugin()); |
| 8 | + it('exports default', () => { |
| 9 | + assert.ok(typeof require('../lib') === 'function'); |
20 | 10 | }); |
21 | 11 |
|
22 | | - after(() => { |
23 | | - process.env.NODE_ENV = originalEnv.NODE_ENV; |
24 | | - process.env.NODE_CONFIG_DIR = originalEnv.NODE_CONFIG_DIR; |
| 12 | + it('initialized app with default.json', () => { |
| 13 | + assert.equal(app.get('port'), 3030); |
| 14 | + assert.deepEqual(app.get('array'), [ |
| 15 | + 'one', 'two', 'three' |
| 16 | + ]); |
| 17 | + assert.deepEqual(app.get('deep'), { base: false }); |
| 18 | + assert.deepEqual(app.get('nullish'), null); |
25 | 19 | }); |
26 | 20 |
|
27 | | - it('exports default', () => |
28 | | - assert.strictEqual(plugin, plugin.default) |
29 | | - ); |
30 | | - |
31 | | - it('initialized app with default data', () => |
32 | | - assert.strictEqual(app.get('port'), 3030) |
33 | | - ); |
34 | | - |
35 | | - it('initialized with <env>', () => |
36 | | - assert.strictEqual(app.get('from'), 'testing') |
37 | | - ); |
38 | | - |
39 | | - it('initialized with <env> derived data module', () => |
40 | | - assert.strictEqual(app.get('derived'), 'Hello World') |
41 | | - ); |
42 | | - |
43 | | - it('initialized property with environment variable', () => |
44 | | - assert.strictEqual(app.get('environment'), 'testing') |
45 | | - ); |
46 | | - |
47 | | - it('initialized property with environment variable from <env>', () => |
48 | | - assert.strictEqual(app.get('testEnvironment'), 'testing') |
49 | | - ); |
50 | | - |
51 | | - it('initialized property with derived environment variable from <env> module', () => |
52 | | - assert.strictEqual(app.get('derivedEnvironment'), 'testing') |
53 | | - ); |
54 | | - |
55 | | - it('uses an escape character', () => |
56 | | - assert.strictEqual(app.get('unescaped'), 'NODE_ENV') |
57 | | - ); |
58 | | - |
59 | | - it('normalizes relative path names', () => |
60 | | - assert.strictEqual(app.get('path'), join(__dirname, 'something')) |
61 | | - ); |
62 | | - |
63 | | - it('normalizes relative path names from environment variable', () => |
64 | | - assert.strictEqual(app.get('pathFromEnv'), join(__dirname, 'something')) |
65 | | - ); |
66 | | - |
67 | | - it('converts environment variables recursively', () => |
68 | | - assert.strictEqual(app.get('deeply').nested.env, 'testing') |
69 | | - ); |
70 | | - |
71 | | - it('converts arrays as actual arrays', () => |
72 | | - assert.ok(Array.isArray(app.get('array'))) |
73 | | - ); |
74 | | - |
75 | 21 | it('works when called directly', () => { |
76 | 22 | const fn = plugin(); |
| 23 | + const conf = fn() as any; |
77 | 24 |
|
78 | | - assert.strictEqual(fn().port, 3030); |
79 | | - }); |
80 | | - |
81 | | - it('deep merges properties', () => |
82 | | - assert.deepStrictEqual(app.get('deep'), { |
83 | | - base: false, |
84 | | - merge: true |
85 | | - }) |
86 | | - ); |
87 | | - |
88 | | - it('supports null value', () => { |
89 | | - assert.strictEqual(app.get('nullish'), null); |
| 25 | + assert.strictEqual(conf.port, 3030); |
90 | 26 | }); |
91 | 27 | }); |
0 commit comments