2018-08-13 00:09:37 +02:00
|
|
|
import * as path from 'path';
|
2025-08-14 07:20:05 +00:00
|
|
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
2022-07-28 10:09:01 +02:00
|
|
|
import * as qenv from '../ts/index.js';
|
|
|
|
|
2023-08-08 19:08:25 +02:00
|
|
|
import * as smartpath from '@push.rocks/smartpath';
|
2022-07-28 10:09:01 +02:00
|
|
|
|
2022-07-28 10:10:39 +02:00
|
|
|
export { smartpath };
|
2022-07-28 10:09:01 +02:00
|
|
|
|
2022-08-02 14:50:18 +02:00
|
|
|
const testDir = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
2022-07-28 10:09:01 +02:00
|
|
|
|
2018-08-13 00:09:37 +02:00
|
|
|
process.env['key1'] = 'original';
|
2016-06-20 10:45:43 +02:00
|
|
|
|
2019-01-15 23:54:29 +01:00
|
|
|
let testQenv: qenv.Qenv;
|
2016-06-20 10:45:43 +02:00
|
|
|
|
2017-05-12 17:56:51 +02:00
|
|
|
tap.test('should create a new class', async () => {
|
2022-08-02 14:50:18 +02:00
|
|
|
testQenv = new qenv.Qenv(path.join(testDir, 'assets'), path.join(testDir, 'assets'), false);
|
2022-07-28 10:09:01 +02:00
|
|
|
expect(testQenv).toBeInstanceOf(qenv.Qenv);
|
2018-08-13 00:09:37 +02:00
|
|
|
});
|
2017-05-12 17:56:51 +02:00
|
|
|
|
|
|
|
tap.test('key1 should be not be overwritten since it is already present', async () => {
|
2023-08-09 13:24:49 +02:00
|
|
|
expect(await testQenv.getEnvVarOnDemand('key1')).toEqual('original');
|
|
|
|
expect(await testQenv.getEnvVarOnDemand('key1')).toEqual('original');
|
2018-08-13 00:09:37 +02:00
|
|
|
});
|
2016-06-20 10:45:43 +02:00
|
|
|
|
2017-05-12 17:56:51 +02:00
|
|
|
tap.test('key2 should be read from Yml', async () => {
|
2023-08-09 13:24:49 +02:00
|
|
|
expect(await testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
|
|
|
|
expect(await testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
|
2018-08-13 00:09:37 +02:00
|
|
|
});
|
2017-05-12 17:56:51 +02:00
|
|
|
|
|
|
|
tap.test('keyValueObjectArray should hold all retrieved values', async () => {
|
2023-08-09 13:24:49 +02:00
|
|
|
expect(await testQenv.keyValueObject.key1).toEqual('original');
|
|
|
|
expect(await testQenv.keyValueObject.key2).toEqual('fromJson');
|
2018-08-13 00:09:37 +02:00
|
|
|
});
|
2017-05-12 17:56:51 +02:00
|
|
|
|
2018-08-13 00:09:37 +02:00
|
|
|
tap.start();
|