Skip to content

Commit

Permalink
test: allow win32 line endings, path displays
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Sep 7, 2023
1 parent ed07dd9 commit b614b1b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/test/esm-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)/
);
});
Expand All @@ -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 () => {
Expand Down
12 changes: 9 additions & 3 deletions src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion src/test/register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
}
});

Expand Down

0 comments on commit b614b1b

Please sign in to comment.