2018-08-12 22:09:37 +00:00
|
|
|
import * as path from 'path';
|
|
|
|
import { tap, expect } from '@pushrocks/tapbundle';
|
2022-07-28 08:09:01 +00:00
|
|
|
import * as qenv from '../ts/index.js';
|
|
|
|
|
|
|
|
import * as smartpath from '@pushrocks/smartpath';
|
|
|
|
|
|
|
|
export {
|
|
|
|
smartpath
|
|
|
|
}
|
|
|
|
|
|
|
|
const __dirname = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
|
|
|
|
2016-06-20 08:45:43 +00:00
|
|
|
|
2018-08-12 22:09:37 +00:00
|
|
|
process.env['key1'] = 'original';
|
2016-06-20 08:45:43 +00:00
|
|
|
|
2019-01-15 22:54:29 +00:00
|
|
|
let testQenv: qenv.Qenv;
|
2016-06-20 08:45:43 +00:00
|
|
|
|
2017-05-12 15:56:51 +00:00
|
|
|
tap.test('should create a new class', async () => {
|
2019-08-06 15:37:07 +00:00
|
|
|
testQenv = new qenv.Qenv(path.join(__dirname, 'assets'), path.join(__dirname, 'assets'), false);
|
2022-07-28 08:09:01 +00:00
|
|
|
expect(testQenv).toBeInstanceOf(qenv.Qenv);
|
2018-08-12 22:09:37 +00:00
|
|
|
});
|
2017-05-12 15:56:51 +00:00
|
|
|
|
|
|
|
tap.test('key1 should be not be overwritten since it is already present', async () => {
|
2022-07-28 08:09:01 +00:00
|
|
|
expect(testQenv.getEnvVarRequired('key1')).toEqual('original');
|
|
|
|
expect(testQenv.getEnvVarOnDemand('key1')).toEqual('original');
|
2018-08-12 22:09:37 +00:00
|
|
|
});
|
2016-06-20 08:45:43 +00:00
|
|
|
|
2017-05-12 15:56:51 +00:00
|
|
|
tap.test('key2 should be read from Yml', async () => {
|
2022-07-28 08:09:01 +00:00
|
|
|
expect(testQenv.getEnvVarRequired('key2')).toEqual('fromJson');
|
|
|
|
expect(testQenv.getEnvVarOnDemand('key2')).toEqual('fromJson');
|
2018-08-12 22:09:37 +00:00
|
|
|
});
|
2017-05-12 15:56:51 +00:00
|
|
|
|
|
|
|
tap.test('keyValueObjectArray should hold all retrieved values', async () => {
|
2022-07-28 08:09:01 +00:00
|
|
|
expect(testQenv.keyValueObject.key1).toEqual('original');
|
|
|
|
expect(testQenv.keyValueObject.key2).toEqual('fromJson');
|
2018-08-12 22:09:37 +00:00
|
|
|
});
|
2017-05-12 15:56:51 +00:00
|
|
|
|
2018-08-12 22:09:37 +00:00
|
|
|
tap.start();
|