Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
})