UNPKG

configuru

Version:

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

57 lines 4.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var path_1 = require("path"); var loader_1 = require("../lib/loader"); var polishers_1 = require("../lib/polishers"); var config = { string: 'string', number: 42, boolean: false, null: null, }; var stringLoader = (0, loader_1.createAtomLoaderFactory)(config)(function (x) { return String(x); }); describe('loader', function () { var _a = (0, loader_1.createLoader)({ defaultConfigPath: (0, path_1.resolve)(__dirname, './sandbox/loader.jsonc'), }), string = _a.string, custom = _a.custom; var schema = { foo: string('FOO'), stamp: custom(function (foo) { return "".concat(foo, "bar"); })('FOO'), expanded: custom(function (x) { return x .split('') .map(function (letter) { return ({ s: letter, foo: string('FOO') }); }); })('FOO'), }; var _b = (0, polishers_1.values)(schema), foo = _b.foo, stamp = _b.stamp, expanded = _b.expanded; expect(foo).toMatchInlineSnapshot('"foo"'); expect(stamp).toMatchInlineSnapshot('"foobar"'); expect(expanded).toMatchInlineSnapshot("\n Array [\n Object {\n \"foo\": \"foo\",\n \"s\": \"f\",\n },\n Object {\n \"foo\": \"foo\",\n \"s\": \"o\",\n },\n Object {\n \"foo\": \"foo\",\n \"s\": \"o\",\n },\n ]\n "); }); describe('atomLoader', function () { describe('string loader', function () { test('number', function () { expect(stringLoader('number')).toMatchInlineSnapshot("\n Object {\n \"__CONFIGURU_LEAF\": true,\n \"hidden\": false,\n \"nullable\": false,\n \"rawValue\": 42,\n \"value\": \"42\",\n }\n "); }); test('nullable', function () { // empty throws on default expect(function () { return stringLoader('null'); }).toThrow(/missing/i); expect(function () { return stringLoader('undefined'); }).toThrow(/missing/i); // empty valid on nullable expect(stringLoader.nullable('null')).toMatchInlineSnapshot("\n Object {\n \"__CONFIGURU_LEAF\": true,\n \"hidden\": false,\n \"nullable\": true,\n \"rawValue\": null,\n \"value\": null,\n }\n "); expect(stringLoader.nullable('undefined')).toMatchInlineSnapshot("\n Object {\n \"__CONFIGURU_LEAF\": true,\n \"hidden\": false,\n \"nullable\": true,\n \"rawValue\": undefined,\n \"value\": null,\n }\n "); }); test('nullable & hidden', function () { // empty throws on hidden expect(function () { return stringLoader.hidden('null'); }).toThrow(/missing/i); expect(function () { return stringLoader.hidden('undefined'); }).toThrow(/missing/i); // empty valid on nullable expect(stringLoader.hidden.nullable('null')).toMatchInlineSnapshot("\n Object {\n \"__CONFIGURU_LEAF\": true,\n \"hidden\": true,\n \"nullable\": true,\n \"rawValue\": null,\n \"value\": null,\n }\n "); expect(stringLoader.hidden.nullable('undefined')).toMatchInlineSnapshot("\n Object {\n \"__CONFIGURU_LEAF\": true,\n \"hidden\": true,\n \"nullable\": true,\n \"rawValue\": undefined,\n \"value\": null,\n }\n "); }); test('hidden', function () { expect(stringLoader.hidden('string')).toMatchInlineSnapshot("\n Object {\n \"__CONFIGURU_LEAF\": true,\n \"hidden\": true,\n \"nullable\": false,\n \"rawValue\": \"string\",\n \"value\": \"string\",\n }\n "); }); }); }); //# sourceMappingURL=loader.test.js.map