Skip to content

Commit

Permalink
Merge pull request #52 from SecJS/fix/len-reload-config-files
Browse files Browse the repository at this point in the history
fix(config): set version on config file import to not cache
  • Loading branch information
jlenon7 authored Jun 29, 2022
2 parents b8510db + 43365f3 commit 3bc443c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@secjs/utils",
"version": "1.9.3",
"version": "1.9.4",
"description": "Utils functions and classes for Node.js",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
5 changes: 4 additions & 1 deletion src/Helpers/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export class Config {
}

Debug.log(`Loading ${path} configuration file`, 'api:configurations')
Config.configs.set(name, (await import(file.href)).default)
Config.configs.set(
name,
(await import(`${file.href}?version=${Math.random()}${ext}`)).default,
)
}
}
1 change: 1 addition & 0 deletions tests/Stubs/config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

export default {
name: 'SecJS',
env: process.env.NODE_ENV,
}
19 changes: 18 additions & 1 deletion tests/Unit/ConfigTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
*/

import { test } from '@japa/runner'
import { Path, Config, Folder } from '#src/index'
import { Config, Folder, Path } from '#src/index'
import { RecursiveConfigException } from '#src/Exceptions/RecursiveConfigException'
import { ConfigNotNormalizedException } from '#src/Exceptions/ConfigNotNormalizedException'

test.group('ConfigTest', group => {
group.each.setup(async () => {
process.env.NODE_ENV = 'test'

Config.configs.clear()

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

assert.equal(Config.get('app.name'), 'SecJS')
})

test('should be able to reload configuration values', async ({ assert }) => {
assert.equal(Config.get('app.env'), 'test')

process.env.NODE_ENV = 'example'

Config.configs.clear()

const config = new Config()

await config.safeLoad(Path.config('app.js'))
await config.safeLoad(Path.config('database.js'))

assert.equal(Config.get('app.env'), 'example')
})
})

0 comments on commit 3bc443c

Please sign in to comment.