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 " ;
33import path from "node:path" ;
4+ import test , { describe } from "node:test" ;
45import ts from "typescript" ;
56import * 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 } ) ;
0 commit comments