Skip to content

Commit e3f2e16

Browse files
authored
tests: split monolithic test.mjs into focused modules (#201)
- Add helpers.mjs with fixtures() path helper and mock setup functions - Split into dependency-tree, formats, to-list, resolvers, node-modules, and config test files - Add coverage for Sass nonExistent partials, _getDependencies parse errors, flat/scoped node_modules, requirejs nonExistent aliases, ES6 lazy/dynamic imports, nodeModulesConfig.entry, tsconfig/tsx/allowJs integration - Flatten nested describes, inline single-use beforeEach() mocks, lift helpers to module scope, fix shadowed variables
1 parent 949c082 commit e3f2e16

File tree

9 files changed

+1168
-1076
lines changed

9 files changed

+1168
-1076
lines changed

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"scripts": {
1717
"lint": "xo",
1818
"fix": "xo --fix",
19-
"mocha": "mocha",
19+
"mocha": "mocha \"test/*.test.mjs\"",
2020
"test": "npm run lint && npm run mocha",
2121
"test:ci": "c8 npm run mocha"
2222
},
@@ -103,6 +103,14 @@
103103
"unicorn/prefer-module": "off",
104104
"unicorn/prefer-top-level-await": "off",
105105
"unicorn/prevent-abbreviations": "off"
106-
}
106+
},
107+
"overrides": [
108+
{
109+
"files": "test/**/*.{c,m}js",
110+
"envs": [
111+
"mocha"
112+
]
113+
}
114+
]
107115
}
108116
}

test/config.test.mjs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { strict as assert } from 'node:assert';
2+
import path from 'node:path';
3+
import Config from '../lib/config.js';
4+
import dependencyTree from '../index.js';
5+
import { fixtures } from './helpers.mjs';
6+
7+
describe('noTypeDefinitions', () => {
8+
const directory = fixtures('noTypeDefinitions');
9+
const filename = path.join(directory, 'entrypoint.ts');
10+
11+
it('resolves to definition files when set to false', () => {
12+
const list = dependencyTree.toList({
13+
filename,
14+
directory,
15+
noTypeDefinitions: false
16+
});
17+
18+
assert.ok(list.includes(path.join(directory, 'required.d.ts')));
19+
assert.ok(!list.includes(path.join(directory, 'required.js')));
20+
});
21+
22+
it('resolves to JavaScript files when set to true', () => {
23+
const list = dependencyTree.toList({
24+
filename,
25+
directory,
26+
noTypeDefinitions: true
27+
});
28+
29+
assert.ok(list.includes(path.join(directory, 'required.js')));
30+
assert.ok(!list.includes(path.join(directory, 'required.d.ts')));
31+
});
32+
});
33+
34+
describe('Config', () => {
35+
it('pre-parses tsconfig for performance', () => {
36+
const tsConfigPath = fixtures('ts', '.tsconfig');
37+
const config = new Config({
38+
filename: 'foo',
39+
directory: 'bar',
40+
tsConfig: tsConfigPath
41+
});
42+
43+
assert.equal(typeof config.tsConfig, 'object');
44+
});
45+
46+
it('includes tsConfigPath so filing-cabinet can resolve compilerOptions.paths', () => {
47+
const tsConfigPath = fixtures('ts', '.tsconfig');
48+
const config = new Config({
49+
filename: 'foo',
50+
directory: 'bar',
51+
tsConfig: tsConfigPath
52+
});
53+
54+
assert.equal(config.tsConfigPath, tsConfigPath);
55+
});
56+
57+
it('retains detective config in the clone', () => {
58+
const detectiveConfig = {
59+
es6: {
60+
mixedImports: true
61+
}
62+
};
63+
64+
const config = new Config({
65+
detectiveConfig,
66+
filename: 'foo',
67+
directory: 'bar'
68+
});
69+
70+
const clone = config.clone();
71+
72+
assert.deepEqual(clone.detectiveConfig, detectiveConfig);
73+
});
74+
});

0 commit comments

Comments
 (0)