Skip to content

Commit f180d15

Browse files
committed
WIP migrating to node test
1 parent 5373696 commit f180d15

File tree

4 files changed

+373
-34
lines changed

4 files changed

+373
-34
lines changed

test/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"license": "MIT",
44
"scripts": {
55
"test": "jest",
6+
"test:node": "node --test --watch '**/*.test.ts'",
67
"g:ts-node": "cd $INIT_CWD && ts-node",
78
"postinstall": "node prepare.mjs"
89
},
@@ -12,13 +13,17 @@
1213
"@nrwl/node": "^15.9.7",
1314
"@nrwl/workspace": "^15.9.7",
1415
"@tsconfig/node18": "^18.2.4",
16+
"@tsconfig/node22": "^22.0.2",
1517
"@types/jest": "^29.5.14",
18+
"@types/node": "^24.3.0",
1619
"@types/ts-expose-internals": "npm:ts-expose-internals@^4.9.5",
20+
"escape-string-regexp": "^5.0.0",
1721
"jest": "^29.7.0",
1822
"nx": "^15.9.7",
1923
"ts-jest": "^29.2.4",
2024
"ts-node": "^10.9.2",
2125
"ts-patch": "^3.3.0",
26+
"tsx": "^4.20.4",
2227
"typescript": "^5.7.2",
2328
"typescript-transform-paths": "portal:../"
2429
},

test/tests/extras.test.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { createTsProgram, getEmitResultFromProgram, ModuleNotFoundError } from "../utils";
2-
import { projectsPaths } from "../config";
1+
import escapeStringRegexp from "escape-string-regexp";
2+
import { execSync } from "node:child_process";
33
import path from "node:path";
4+
import test, { describe } from "node:test";
45
import ts from "typescript";
56
import * as config from "../config";
6-
import { execSync } from "node:child_process";
7+
import { projectsPaths } from "../config";
8+
import { createTsProgram, getEmitResultFromProgram, ModuleNotFoundError } from "../utils";
9+
import { stripVTControlCharacters } from "node:util";
710

811
/* ****************************************************************************************************************** *
912
* Tests
@@ -16,38 +19,33 @@ describe(`Extra Tests`, () => {
1619

1720
describe(`Built Tests`, () => {
1821
// see: https://github.com/LeDDGroup/typescript-transform-paths/issues/130
19-
test(`Transformer works without ts-node being present`, () => {
20-
jest.doMock(
21-
"ts-node",
22-
() => {
23-
throw new ModuleNotFoundError("ts-node");
24-
},
25-
{ virtual: true },
26-
);
27-
try {
28-
const program = createTsProgram({ tsInstance: ts, tsConfigFile }, config.builtTransformerPath);
29-
const res = getEmitResultFromProgram(program);
30-
expect(res[indexFile].js).toMatch(`var _identifier_1 = require("./id")`);
31-
} finally {
32-
jest.dontMock("ts-node");
33-
}
34-
});
22+
// test(`Transformer works without ts-node being present`, (t) => {
23+
// jest.doMock(
24+
// "ts-node",
25+
// () => {
26+
// throw new ModuleNotFoundError("ts-node");
27+
// },
28+
// { virtual: true },
29+
// );
30+
// try {
31+
// const program = createTsProgram({ tsInstance: ts, tsConfigFile }, config.builtTransformerPath);
32+
// const res = getEmitResultFromProgram(program);
33+
// t.assert.match(res[indexFile].js, new RegExp(escapeStringRegexp(`var _identifier_1 = require("./id")`)));
34+
// expect(res[indexFile].js).toMatch(`var _identifier_1 = require("./id")`);
35+
// } finally {
36+
// jest.dontMock("ts-node");
37+
// }
38+
// });
3539

3640
describe(`ts-node register script`, () => {
37-
/** Yarn sometimes outputs bold text, which makes these tests flakey */
38-
function stripAnsi(str: string) {
39-
// eslint-disable-next-line no-control-regex
40-
return str.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, "");
41-
}
42-
43-
test(`Works with --transpileOnly`, () => {
41+
test(`Works with --transpileOnly`, (t) => {
4442
const res = execSync("yarn g:ts-node --transpileOnly src/index.ts", { cwd: projectRoot }).toString();
45-
expect(stripAnsi(res.trim())).toEqual("null");
43+
t.assert.equal(stripVTControlCharacters(res.trim()), "null");
4644
});
4745

48-
test(`Works with --typeCheck`, () => {
46+
test(`Works with --typeCheck`, (t) => {
4947
const res = execSync("yarn g:ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString();
50-
expect(stripAnsi(res.trim())).toEqual("null");
48+
t.assert.equal(stripVTControlCharacters(res.trim()), "null");
5149
});
5250
});
5351
});

test/tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"extends": "@tsconfig/node18",
2+
"extends": "@tsconfig/node22",
33
"include": ["tests", "utils"],
4-
54
"compilerOptions": {
6-
"types": ["jest", "node", "ts-expose-internals"],
5+
"types": ["node", "ts-expose-internals"],
76
"noEmit": true,
87
"strict": true,
98
"esModuleInterop": true

0 commit comments

Comments
 (0)