Skip to content

Commit b89d0ef

Browse files
committed
test: replace jest with node test runner
1 parent 372a1e2 commit b89d0ef

File tree

11 files changed

+1242
-9353
lines changed

11 files changed

+1242
-9353
lines changed

src/utils/get-relative-path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function getIsFsCaseSensitive() {
4747
}
4848

4949
/** @private The Export is only for unit tests */
50-
export function getMatchPortion(from: string, to: string) {
50+
export function getMatchPortion(from: string, to: string): string {
5151
const lowerFrom = from.toLocaleLowerCase();
5252
const lowerTo = to.toLocaleLowerCase();
5353

test/jest.config.ts

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

test/package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@
22
"private": true,
33
"license": "MIT",
44
"scripts": {
5-
"test": "jest",
6-
"g:ts-node": "cd $INIT_CWD && ts-node",
5+
"test": "node --test --import tsx 'tests/**/*.test.ts'",
76
"postinstall": "node prepare.mjs"
87
},
98
"devDependencies": {
10-
"@nrwl/cli": "^15.9.7",
11-
"@nrwl/js": "^15.9.7",
12-
"@nrwl/node": "^15.9.7",
13-
"@nrwl/workspace": "^15.9.7",
149
"@tsconfig/node18": "^18.2.4",
15-
"@types/jest": "^29.5.14",
10+
"@tsconfig/node22": "^22.0.2",
11+
"@types/node": "^24.3.0",
1612
"@types/ts-expose-internals": "npm:ts-expose-internals@^4.9.5",
17-
"jest": "^29.7.0",
18-
"ts-jest": "^29.2.4",
19-
"ts-node": "^10.9.2",
13+
"escape-string-regexp": "^5.0.0",
2014
"ts-patch": "^3.3.0",
15+
"tsx": "^4.20.4",
2116
"typescript": "^5.7.2",
2217
"typescript-transform-paths": "portal:../"
2318
},

test/prepare.mjs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
// @ts-check
2-
import { existsSync } from "node:fs";
3-
import { symlink } from "node:fs/promises";
42
import { dirname, resolve } from "node:path";
53
import { fileURLToPath } from "node:url";
64
import { patch } from "ts-patch";
75

86
const __dirname = dirname(fileURLToPath(import.meta.url)); // https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules
97

10-
async function symlinkTsNode() {
11-
// we need to patch the root package node_modules in order for it to locate ts-node for the register tests.
12-
// installing ts-node as a depenency in the root is not an option since it would create two copies of ts-node
13-
// thus messing with the mocks in the tests
14-
const target = resolve(__dirname, "node_modules/ts-node");
15-
const path = resolve(__dirname, "../node_modules/ts-node");
16-
17-
if (!existsSync(path)) await symlink(target, path, "junction");
18-
}
19-
208
function patchTsModules() {
219
const rootDir = __dirname;
2210

@@ -30,4 +18,3 @@ function patchTsModules() {
3018
}
3119

3220
patchTsModules();
33-
await symlinkTsNode();
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { describe, test } from "node:test";
12
import { getMatchPortion } from "../../src/utils/get-relative-path";
23

34
describe(`getMatchPortion`, () => {
4-
it("works in a simple case", () => {
5-
expect(getMatchPortion("/foo/bar", "/foo/quux")).toBe("/foo/");
5+
test("works in a simple case", (t) => {
6+
t.assert.equal(getMatchPortion("/foo/bar", "/foo/quux"), "/foo/");
67
});
78

89
// We use the function getMatchPortion to generate a new path for “to”, so let’s preserve
@@ -11,8 +12,8 @@ describe(`getMatchPortion`, () => {
1112
// their file is named Foo, but we rewrite the path to foo.
1213
// Although the file is still accessible in the file system, other tools might reasonably
1314
// complain about the unexpected case mismatch.
14-
it("prioritizes the casing of the “to” parameter", () => {
15-
expect(getMatchPortion("/foo/bar", "/foO/quux")).toBe("/foO/");
16-
expect(getMatchPortion("/foo/bar", "/foo/Bonk")).toBe("/foo/B");
15+
test('prioritizes the casing of the "to" parameter', (t) => {
16+
t.assert.equal(getMatchPortion("/foo/bar", "/foO/quux"), "/foO/");
17+
t.assert.equal(getMatchPortion("/foo/bar", "/foo/Bonk"), "/foo/B");
1718
});
1819
});

test/tests/project-ref.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// noinspection ES6UnusedImports
22
import * as path from "node:path";
3+
import { describe, test, before } from "node:test";
34
import { createTsSolutionBuilder, EmittedFiles } from "../utils";
45
import { projectsPaths, ts } from "../config";
56

@@ -19,18 +20,18 @@ const indexFile = ts.normalizePath(path.join(projectDir, "lib/b/index.ts"));
1920
describe(`Project References`, () => {
2021
let emittedFiles: EmittedFiles;
2122

22-
beforeAll(() => {
23+
before(() => {
2324
const builder = createTsSolutionBuilder({ tsInstance: ts, projectDir });
2425
emittedFiles = builder.getEmitFiles();
2526
});
2627

27-
test(`Specifier for referenced project file resolves properly`, () => {
28-
expect(emittedFiles[indexFile].js).toMatch(`export { AReffedConst } from "../a/index"`);
29-
expect(emittedFiles[indexFile].dts).toMatch(`export { AReffedConst } from "../a/index"`);
28+
test(`Specifier for referenced project file resolves properly`, (t) => {
29+
t.assert.match(emittedFiles[indexFile].js, /export { AReffedConst } from "..\/a\/index"/);
30+
t.assert.match(emittedFiles[indexFile].dts, /export { AReffedConst } from "..\/a\/index"/);
3031
});
3132

32-
test(`Specifier for local file resolves properly`, () => {
33-
expect(emittedFiles[indexFile].js).toMatch(`export { LocalConst } from "./local/index"`);
34-
expect(emittedFiles[indexFile].dts).toMatch(`export { LocalConst } from "./local/index"`);
33+
test(`Specifier for local file resolves properly`, (t) => {
34+
t.assert.match(emittedFiles[indexFile].js, /export { LocalConst } from ".\/local\/index"/);
35+
t.assert.match(emittedFiles[indexFile].dts, /export { LocalConst } from ".\/local\/index"/);
3536
});
3637
});
Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// noinspection ES6UnusedImports
22
import * as path from "node:path";
3+
import { describe, before, test } from "node:test";
34
import { createTsProgram, EmittedFiles, getEmitResultFromProgram } from "../../utils";
45
import { ts, tsModules, projectsPaths } from "../../config";
56

@@ -30,33 +31,36 @@ describe(`Transformer -> General Tests`, () => {
3031
const projectRoot = path.join(projectsPaths, "general");
3132
const tsConfigFile = path.join(projectRoot, "tsconfig.json");
3233

33-
describe.each(tsModules)(`TypeScript %s`, (s, tsInstance) => {
34-
let originalFiles: EmittedFiles = {};
35-
let transformedFiles: EmittedFiles = {};
34+
for (const [s, tsInstance] of tsModules)
35+
describe(`TypeScript ${s}`, () => {
36+
let originalFiles: EmittedFiles = {};
37+
let transformedFiles: EmittedFiles = {};
3638

37-
const program = createTsProgram({ tsInstance: tsInstance as typeof ts, tsConfigFile, disablePlugin: true });
38-
const programWithTransformer = createTsProgram({ tsInstance: tsInstance as typeof ts, tsConfigFile });
39-
const fileNames = program.getRootFileNames() as string[];
39+
const program = createTsProgram({ tsInstance: tsInstance as typeof ts, tsConfigFile, disablePlugin: true });
40+
const programWithTransformer = createTsProgram({ tsInstance: tsInstance as typeof ts, tsConfigFile });
41+
const fileNames = program.getRootFileNames() as string[];
4042

41-
beforeAll(() => {
42-
originalFiles = getEmitResultFromProgram(program);
43-
transformedFiles = getEmitResultFromProgram(programWithTransformer);
44-
});
43+
before(() => {
44+
originalFiles = getEmitResultFromProgram(program);
45+
transformedFiles = getEmitResultFromProgram(programWithTransformer);
46+
});
4547

46-
describe.each(fileNames!.map((p) => [p.slice(projectRoot.length), p]))(`%s`, (_, file) => {
47-
let expected: EmittedFiles[string];
48-
let transformed: EmittedFiles[string];
48+
for (const file of fileNames!) {
49+
describe(file, () => {
50+
let expected: EmittedFiles[string];
51+
let transformed: EmittedFiles[string];
4952

50-
beforeAll(() => {
51-
transformed = transformedFiles[file];
52-
expected = {
53-
js: getExpected(tsInstance, file, originalFiles[file].js, projectRoot),
54-
dts: getExpected(tsInstance, file, originalFiles[file].dts, projectRoot),
55-
};
56-
});
53+
before(() => {
54+
transformed = transformedFiles[file];
55+
expected = {
56+
js: getExpected(tsInstance, file, originalFiles[file].js, projectRoot),
57+
dts: getExpected(tsInstance, file, originalFiles[file].dts, projectRoot),
58+
};
59+
});
5760

58-
test(`js matches`, () => expect(transformed.js).toEqual(expected.js));
59-
test(`dts matches`, () => expect(transformed.dts).toEqual(expected.dts));
61+
test(`js matches`, (t) => t.assert.strictEqual(transformed.js, expected.js));
62+
test(`dts matches`, (t) => t.assert.strictEqual(transformed.dts, expected.dts));
63+
});
64+
}
6065
});
61-
});
6266
});

0 commit comments

Comments
 (0)