UNPKG

configuru

Version:

Manage the configuration of your Nodejs application with multiple environments and custom preferences, utilizing Configuru in CI and development as well!

79 lines 4.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* eslint-disable sonarjs/no-duplicate-string */ var path_1 = require("path"); var storage_1 = require("../lib/storage"); describe('storage', function () { test('Empty', function () { expect((0, storage_1.createConfigStorage)({})).toEqual({}); }); test('Non-existent file throws error', function () { expect(function () { return (0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/dayum'), }); }).toThrow(/exist/); }); test('Non-valid file throws error', function () { expect(function () { return (0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/invalid'), }); }).toThrow(/valid/); }); test('Extension not required', function () { var def = (0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/default'), }); var defJson = (0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/default.json'), }); var defJsonc = (0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/default.jsonc'), }); expect(def).toStrictEqual(defJson); expect(defJson).toStrictEqual(defJsonc); }); test('Default', function () { expect((0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/default.json'), })).toMatchInlineSnapshot("\n Object {\n \"bar\": 1,\n \"baz\": 2,\n \"defaultConfig\": true,\n \"foo\": \"default\",\n }\n "); }); test('Default (jsonc)', function () { expect((0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/default.jsonc'), })).toMatchInlineSnapshot("\n Object {\n \"bar\": 1,\n \"baz\": 2,\n \"defaultConfig\": true,\n \"foo\": \"default\",\n }\n "); }); test('Default & user', function () { expect((0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/default.json'), userConfigPath: (0, path_1.resolve)(__dirname, './sandbox/user.json'), })).toMatchInlineSnapshot("\n Object {\n \"bar\": 1,\n \"baz\": 2,\n \"defaultConfig\": true,\n \"foo\": \"user\",\n \"quix\": false,\n \"userConfig\": true,\n }\n "); }); test('Default & user & env', function () { process.env.foo = 'env'; process.env.bar = '3'; expect((0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/default.json'), userConfigPath: (0, path_1.resolve)(__dirname, './sandbox/user.json'), envMode: 'default', })).toMatchInlineSnapshot("\n Object {\n \"bar\": \"3\",\n \"baz\": 2,\n \"defaultConfig\": true,\n \"foo\": \"env\",\n \"quix\": false,\n \"userConfig\": true,\n }\n "); }); test('Default configuration can be inline', function () { expect((0, storage_1.createConfigStorage)({ defaultConfigPath: JSON.stringify({ inlinesecret: 'secret', }), })).toMatchInlineSnapshot("\n Object {\n \"inlinesecret\": \"secret\",\n }\n "); }); test('User configuration can be inline', function () { expect((0, storage_1.createConfigStorage)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/default.json'), userConfigPath: JSON.stringify({ bar: 'inline', inlinesecret: 'secret', }), })).toMatchInlineSnapshot("\n Object {\n \"bar\": \"inline\",\n \"baz\": 2,\n \"defaultConfig\": true,\n \"foo\": \"default\",\n \"inlinesecret\": \"secret\",\n }\n "); }); }); //# sourceMappingURL=storage.test.js.map