Skip to content

Commit d119202

Browse files
committed
Move tests into 0-util.js from:
- 4-array-merging.js - 7-unicode-situations.js Note: this fixes a test that was silently failing after earlier refactoring - x-config-js-test-transpiled.js - x-config-test-ts.js - x-config-test-ts-module-exports.js To reduce use of requireUncached for #860
1 parent f816027 commit d119202

File tree

6 files changed

+66
-218
lines changed

6 files changed

+66
-218
lines changed

test/0-util.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,28 @@ describe('Tests for util functions', function () {
369369
var result = util.extendDeep({}, orig, {baz: undefined});
370370
assert.strictEqual(Object.keys(result).length, 3);
371371
});
372+
373+
describe('arrays', function () {
374+
it('An empty array replaced by a full array should be replaced', function() {
375+
var orig = {e1: "val1", e3: []};
376+
var extWith = {e2: {elem1: "val1"}, e3: ["val6", "val7"]};
377+
var shouldBe = {e1: "val1", e2: {elem1: "val1"}, e3: ["val6", "val7"]};
378+
var ext = util.extendDeep({}, orig, extWith);
379+
380+
assert.deepEqual(ext, shouldBe);
381+
assert.deepEqual(orig.e3, []);
382+
});
383+
384+
it("An array replaced by an empty array should be replaced wholesale", function () {
385+
var orig = {e1: "val1", e3: ["val6", "val7"]};
386+
var extWith = {e2: {elem1: "val1"}, e3: []};
387+
var shouldBe = {e1: "val1", e2: {elem1: "val1"}, e3: []};
388+
var ext = util.extendDeep({}, orig, extWith);
389+
390+
assert.deepEqual(ext, shouldBe);
391+
assert.deepEqual(orig.e3, ["val6", "val7"]);
392+
});
393+
});
372394
});
373395

374396
describe('Util.toObject() tests', function() {
@@ -678,6 +700,12 @@ describe('Tests for util functions', function () {
678700
assert.deepEqual(load.config.staticArray, [2,1,3]);
679701
});
680702

703+
it('can handle files with BOM Unicode characters', function () {
704+
assert.doesNotThrow(function () {
705+
load.loadFile(Path.join(__dirname, './7-config/defaultWithUnicodeBOM.json'));
706+
}, 'config file with BOM has a parse error');
707+
});
708+
681709
it('uses an optional transform on the data', function() {
682710
load.loadFile(Path.join(__dirname, './config/default-3.json'), () => { return { foo: "bar" } });
683711

@@ -1311,6 +1339,14 @@ describe('Tests for util functions', function () {
13111339
assert.strictEqual(config.AnotherModule.parm3, 'value3');
13121340
});
13131341

1342+
it('loading from transpiled ESM files is correct', function() {
1343+
let actual = util.loadFileConfigs({
1344+
configDir: Path.join(__dirname, 'x-config-js-transpiled')
1345+
}).config;
1346+
1347+
assert.strictEqual(actual.title, 'Hello config!');
1348+
});
1349+
13141350
it('loading from a Hjson file is correct', function() {
13151351
assert.strictEqual(config.AnotherModule.parm8, 'value8');
13161352
});
@@ -1323,6 +1359,36 @@ describe('Tests for util functions', function () {
13231359
assert.strictEqual(config.AnotherModule.parm10, 'value10');
13241360
});
13251361

1362+
describe('for .ts files', function() {
1363+
it('loading from a TS file is correct', function() {
1364+
let actual = util.loadFileConfigs({
1365+
configDir: Path.join(__dirname, 'x-config-ts')
1366+
}).config;
1367+
1368+
assert.strictEqual(actual.siteTitle, 'New Instance!');
1369+
});
1370+
1371+
it('reuses existing .ts file handler', function() {
1372+
let existingHandler = require.extensions['.ts'];
1373+
1374+
assert.ok(existingHandler, 'Existing handler is defined by the environment');
1375+
1376+
let actual = util.loadFileConfigs({
1377+
configDir: Path.join(__dirname, 'x-config-ts')
1378+
}).config;
1379+
1380+
assert.strictEqual(require.extensions['.ts'], existingHandler, 'Should not overwrite existing handler');
1381+
});
1382+
1383+
describe('can process module exports', function() {
1384+
let actual = util.loadFileConfigs({
1385+
configDir: Path.join(__dirname, 'x-config-ts-module-exports')
1386+
}).config;
1387+
1388+
assert.strictEqual(actual.siteTitle, 'New Instance!');
1389+
});
1390+
});
1391+
13261392
describe('for .toml files', function () {
13271393
it('loading from a TOML file is correct', function() {
13281394
assert.strictEqual(config.AnotherModule.parm7, 'value7');

test/4-array-merging.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

test/7-unicode-situations.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/x-config-js-test-transpiled.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

test/x-config-test-ts-module-exports.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

test/x-config-test-ts.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)