diff --git a/src/test/esm-loader.spec.ts b/src/test/esm-loader.spec.ts index 44626a38d..022f9c9f8 100644 --- a/src/test/esm-loader.spec.ts +++ b/src/test/esm-loader.spec.ts @@ -51,14 +51,14 @@ test.suite('esm', (test) => { expect(r.err).not.toBe(null); // on node 20, this will be a path. prior versions, a file: url // on windows in node 20, it's a quasi-url like d:/path/to/throw%20error.ts - expect(r.err!.message).toMatch( + expect(r.err!.message.replace(/\r\n/g, '\n')).toMatch( /[\\\/]throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/ ); // the ^ and number of line-breaks is platform-specific // also, node 20 puts the type in here when source mapping it, so it // shows as Foo.Foo.bar - expect(r.err!.message).toMatch(/^ at (Foo\.){1,2}bar \(/m); - expect(r.err!.message).toMatch(/^ at (Foo\.){1,2}bar ([^\n]+[\\\/]throw( |%20)error\.ts:100:17)`/m); + expect(r.err!.message.replace(/\r\n/g, '\n')).toMatch(/^ at (Foo\.){1,2}bar \(/m); + expect(r.err!.message.replace(/\r\n/g, '\n')).toMatch(/^ at (Foo\.){1,2}bar ([^\n\)]+[\\\/]throw( |%20)error\.ts:100:17)/m); }); test.suite('supports experimental-specifier-resolution=node', (test) => { @@ -96,7 +96,7 @@ test.suite('esm', (test) => { }); expect(r.err).not.toBe(null); // expect error from node's default resolver, has a few different names in different node versions - expect(r.stderr).toMatch( + expect(r.stderr.replace(/\r\n/g, '\n')).toMatch( /Error \[ERR_UNSUPPORTED_ESM_URL_SCHEME\]:.*(?:\n.*){0,10}\n *at (default|next)(Load|Resolve)/ ); }); @@ -106,7 +106,7 @@ test.suite('esm', (test) => { cwd: join(TEST_DIR, './esm-import-cache'), }); expect(r.err).toBe(null); - expect(r.stdout).toBe('log1\nlog2\nlog2\n'); + expect(r.stdout.replace(/\r\n/g, '\n')).toBe('log1\nlog2\nlog2\n'); }); test('should support transpile only mode via dedicated loader entrypoint', async () => { diff --git a/src/test/index.spec.ts b/src/test/index.spec.ts index ff22c837b..f23c662ac 100644 --- a/src/test/index.spec.ts +++ b/src/test/index.spec.ts @@ -181,7 +181,9 @@ test.suite('ts-node', (test) => { throw new Error('Command was expected to fail, but it succeeded.'); } - expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/); + expect(r.err.message.replace(/\r\n/g, '\n')).toMatch( + /throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/ + ); }); test('should work with source maps in --transpile-only mode', async () => { @@ -190,7 +192,9 @@ test.suite('ts-node', (test) => { throw new Error('Command was expected to fail, but it succeeded.'); } - expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/); + expect(r.err.message.replace(/\r\n/g, '\n')).toMatch( + /throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/ + ); }); test('eval should work with source maps', async () => { @@ -199,7 +203,9 @@ test.suite('ts-node', (test) => { throw new Error('Command was expected to fail, but it succeeded.'); } - expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/); + expect(r.err.message.replace(/\r\n/g, '\n')).toMatch( + /throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/ + ); }); for (const flavor of [ diff --git a/src/test/register.spec.ts b/src/test/register.spec.ts index b6e4cfa08..2cae6de32 100644 --- a/src/test/register.spec.ts +++ b/src/test/register.spec.ts @@ -109,7 +109,7 @@ test.suite('register(create(options))', (test) => { } catch (error: any) { // on windows in node 20, this is printed as a quasi-url, like // d:/path/to/throw%20error.ts - exp(error.stack).toMatch(/Error: this is a demo\n at Foo\.bar \([^)]+[\\\/]throw( %20)error\.ts:100:17\)\n/); + exp(error.stack).toMatch(/Error: this is a demo\n at Foo\.bar \([^)]+[\\\/]throw( |%20)error\.ts:100:17\)\n/); } });