Skip to content

Commit 3bc443c

Browse files
authored
Merge pull request #52 from SecJS/fix/len-reload-config-files
fix(config): set version on config file import to not cache
2 parents b8510db + 43365f3 commit 3bc443c

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.9.3",
3+
"version": "1.9.4",
44
"description": "Utils functions and classes for Node.js",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",

src/Helpers/Config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export class Config {
9999
}
100100

101101
Debug.log(`Loading ${path} configuration file`, 'api:configurations')
102-
Config.configs.set(name, (await import(file.href)).default)
102+
Config.configs.set(
103+
name,
104+
(await import(`${file.href}?version=${Math.random()}${ext}`)).default,
105+
)
103106
}
104107
}

tests/Stubs/config/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99

1010
export default {
1111
name: 'SecJS',
12+
env: process.env.NODE_ENV,
1213
}

tests/Unit/ConfigTest.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
*/
99

1010
import { test } from '@japa/runner'
11-
import { Path, Config, Folder } from '#src/index'
11+
import { Config, Folder, Path } from '#src/index'
1212
import { RecursiveConfigException } from '#src/Exceptions/RecursiveConfigException'
1313
import { ConfigNotNormalizedException } from '#src/Exceptions/ConfigNotNormalizedException'
1414

1515
test.group('ConfigTest', group => {
1616
group.each.setup(async () => {
17+
process.env.NODE_ENV = 'test'
18+
1719
Config.configs.clear()
1820

1921
const config = new Config()
@@ -59,4 +61,19 @@ test.group('ConfigTest', group => {
5961

6062
assert.equal(Config.get('app.name'), 'SecJS')
6163
})
64+
65+
test('should be able to reload configuration values', async ({ assert }) => {
66+
assert.equal(Config.get('app.env'), 'test')
67+
68+
process.env.NODE_ENV = 'example'
69+
70+
Config.configs.clear()
71+
72+
const config = new Config()
73+
74+
await config.safeLoad(Path.config('app.js'))
75+
await config.safeLoad(Path.config('database.js'))
76+
77+
assert.equal(Config.get('app.env'), 'example')
78+
})
6279
})

0 commit comments

Comments
 (0)