Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(configuration): Remove environment variable substitution (#1942)
BREAKING CHANGE: Falls back to node-config instead of adding additional functionality like path replacements and automatic environment variable insertion.
- Loading branch information
Showing
6 changed files
with
20 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
packages/configuration/test/config/custom-environment-variables.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,27 @@ | ||
import assert from 'assert'; | ||
import { join } from 'path'; | ||
import { strict as assert } from 'assert'; | ||
import feathers, { Application } from '@feathersjs/feathers'; | ||
import plugin from '../src'; | ||
|
||
describe('@feathersjs/configuration', () => { | ||
const originalEnv: { [key: string]: any } = {}; | ||
let app: Application; | ||
let plugin: any; | ||
const app: Application = feathers().configure(plugin()); | ||
|
||
before(() => { | ||
originalEnv.NODE_ENV = process.env.NODE_ENV; | ||
originalEnv.NODE_CONFIG_DIR = process.env.NODE_CONFIG_DIR; | ||
|
||
process.env.NODE_ENV = 'testing'; | ||
process.env.NODE_CONFIG_DIR = join(__dirname, 'config'); | ||
process.env.PATH_ENV = '../something'; | ||
|
||
plugin = require('../lib'); | ||
app = feathers().configure(plugin()); | ||
it('exports default', () => { | ||
assert.ok(typeof require('../lib') === 'function'); | ||
}); | ||
|
||
after(() => { | ||
process.env.NODE_ENV = originalEnv.NODE_ENV; | ||
process.env.NODE_CONFIG_DIR = originalEnv.NODE_CONFIG_DIR; | ||
it('initialized app with default.json', () => { | ||
assert.equal(app.get('port'), 3030); | ||
assert.deepEqual(app.get('array'), [ | ||
'one', 'two', 'three' | ||
]); | ||
assert.deepEqual(app.get('deep'), { base: false }); | ||
assert.deepEqual(app.get('nullish'), null); | ||
}); | ||
|
||
it('exports default', () => | ||
assert.strictEqual(plugin, plugin.default) | ||
); | ||
|
||
it('initialized app with default data', () => | ||
assert.strictEqual(app.get('port'), 3030) | ||
); | ||
|
||
it('initialized with <env>', () => | ||
assert.strictEqual(app.get('from'), 'testing') | ||
); | ||
|
||
it('initialized with <env> derived data module', () => | ||
assert.strictEqual(app.get('derived'), 'Hello World') | ||
); | ||
|
||
it('initialized property with environment variable', () => | ||
assert.strictEqual(app.get('environment'), 'testing') | ||
); | ||
|
||
it('initialized property with environment variable from <env>', () => | ||
assert.strictEqual(app.get('testEnvironment'), 'testing') | ||
); | ||
|
||
it('initialized property with derived environment variable from <env> module', () => | ||
assert.strictEqual(app.get('derivedEnvironment'), 'testing') | ||
); | ||
|
||
it('uses an escape character', () => | ||
assert.strictEqual(app.get('unescaped'), 'NODE_ENV') | ||
); | ||
|
||
it('normalizes relative path names', () => | ||
assert.strictEqual(app.get('path'), join(__dirname, 'something')) | ||
); | ||
|
||
it('normalizes relative path names from environment variable', () => | ||
assert.strictEqual(app.get('pathFromEnv'), join(__dirname, 'something')) | ||
); | ||
|
||
it('converts environment variables recursively', () => | ||
assert.strictEqual(app.get('deeply').nested.env, 'testing') | ||
); | ||
|
||
it('converts arrays as actual arrays', () => | ||
assert.ok(Array.isArray(app.get('array'))) | ||
); | ||
|
||
it('works when called directly', () => { | ||
const fn = plugin(); | ||
const conf = fn() as any; | ||
|
||
assert.strictEqual(fn().port, 3030); | ||
}); | ||
|
||
it('deep merges properties', () => | ||
assert.deepStrictEqual(app.get('deep'), { | ||
base: false, | ||
merge: true | ||
}) | ||
); | ||
|
||
it('supports null value', () => { | ||
assert.strictEqual(app.get('nullish'), null); | ||
assert.strictEqual(conf.port, 3030); | ||
}); | ||
}); |