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
5 changes: 2 additions & 3 deletions src/backend/model/extension/ExtensionConfigWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ export class ExtensionConfigWrapper {
// make sure the config file exists by the time we load it.
// TODO: remove this once typeconfig is fixed and can properly load defaults in arrays
if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) {
await pc.save();
await pc.load();
}

await pc.load(); // loading the basic configs, but we do not know the extension config hierarchy yet

// TODO make sure that all extensions are present even after loading them from file
Expand All @@ -47,7 +46,7 @@ export class ExtensionConfigWrapper {
// make sure the config file exists by the time we load it.
// TODO: remove this once typeconfig is fixed and can properly load defaults in arrays
if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) {
pc.saveSync();
pc.loadSync();
}
pc.loadSync(); // loading the basic configs, but we do not know the extension config hierarchy yet
// TODO make sure that all extensions are present even after loading them from file
Expand Down
2 changes: 1 addition & 1 deletion src/common/config/private/PrivateConfigClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const isTesting = process.env['NODE_ENV'] == true || ['afterEach', 'after', 'bef
.every((fn) => (global as any)[fn] instanceof Function);

@ConfigClass<IConfigClass<TAGS> & ServerConfig>({
configPath: path.join(__dirname, !isTesting ? './../../../../config.json' : './../../../../test/backend/tmp/config.json'),
configPath: path.join(__dirname, !isTesting ? './../../../../config.json' : './../../../../test/tmp/config.json'),
crateConfigPathIfNotExists: isTesting,
saveIfNotExist: true,
attachDescription: true,
Expand Down
25 changes: 25 additions & 0 deletions test/common/unit/config/Config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {expect} from 'chai';
import {ConfigClassBuilder} from 'typeconfig/node';
import {ExtensionConfigWrapper} from '../../../../src/backend/model/extension/ExtensionConfigWrapper';
import {TestHelper} from '../../../TestHelper';
import * as fs from 'fs';


describe('Config', () => {
beforeEach(async () => {
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
});
afterEach(async () => {
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
});
it('should load default from env', () => {
process.env['default-Media-tempFolder'] = 'test/test';
const conf = ExtensionConfigWrapper.originalSync();
expect(conf.Media.tempFolder).to.be.equal('test/test');
expect(ConfigClassBuilder.attachPrivateInterface(conf.Media).__defaults.tempFolder).to.be.equal('test/test');
expect(process.env['default-Media-tempFolder']).to.be.equal('test/test');
const conf2 = ExtensionConfigWrapper.originalSync();
expect(ConfigClassBuilder.attachPrivateInterface(conf2.Media).__defaults.tempFolder).to.be.equal('test/test');
expect(conf2.Media.tempFolder).to.be.equal('test/test');
});
});