2025-08-15 12:12:26 +00:00
|
|
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
2016-07-17 01:23:22 +02:00
|
|
|
|
2017-07-09 19:05:03 +02:00
|
|
|
// module to test
|
2026-03-24 14:56:23 +00:00
|
|
|
import * as smartconfig from '../ts/index.js';
|
2016-09-23 22:13:06 +02:00
|
|
|
|
2026-03-24 14:56:23 +00:00
|
|
|
let testSmartconfig: smartconfig.Smartconfig;
|
2016-09-24 16:44:48 +02:00
|
|
|
|
2026-03-24 14:56:23 +00:00
|
|
|
tap.test('should create a new Smartconfig instance', async () => {
|
|
|
|
|
testSmartconfig = new smartconfig.Smartconfig('./test/');
|
|
|
|
|
expect(testSmartconfig).toBeInstanceOf(smartconfig.Smartconfig);
|
2018-08-31 01:11:09 +02:00
|
|
|
});
|
2017-07-09 19:05:03 +02:00
|
|
|
|
2026-03-24 14:56:23 +00:00
|
|
|
tap.test('should state wether a smartconfig.json exists', async () => {
|
2017-07-09 19:05:03 +02:00
|
|
|
// tslint:disable-next-line:no-unused-expression
|
2026-03-24 14:56:23 +00:00
|
|
|
expect(testSmartconfig.smartconfigJsonExists).toBeTrue();
|
2018-08-31 01:11:09 +02:00
|
|
|
});
|
2017-07-09 19:05:03 +02:00
|
|
|
|
2025-08-15 12:12:26 +00:00
|
|
|
tap.test(
|
|
|
|
|
'should pass through default value, if not overriden by config from file',
|
|
|
|
|
async () => {
|
2026-03-24 14:56:23 +00:00
|
|
|
let testData = testSmartconfig.dataFor('testTool', { someKey2: 'someValue2' });
|
2025-08-15 12:12:26 +00:00
|
|
|
console.log(testData);
|
|
|
|
|
expect(testData).toHaveProperty('someKey2');
|
|
|
|
|
},
|
|
|
|
|
);
|
2017-07-09 19:05:03 +02:00
|
|
|
|
|
|
|
|
tap.test('should read a config file', async () => {
|
2026-03-24 14:56:23 +00:00
|
|
|
let testData = testSmartconfig.dataFor<any>('testTool', {
|
2021-01-27 21:00:49 +00:00
|
|
|
someKey2: 'someValue2',
|
2018-08-31 01:11:09 +02:00
|
|
|
});
|
2023-08-03 19:22:34 +02:00
|
|
|
expect(testData).toHaveProperty('someKey2');
|
|
|
|
|
expect(testData.testValue).toEqual(2);
|
2018-08-31 01:11:09 +02:00
|
|
|
});
|
2017-07-09 19:05:03 +02:00
|
|
|
|
2018-08-31 01:11:09 +02:00
|
|
|
tap.start();
|