Skip to content

Commit b614b1b

Browse files
committed
test: allow win32 line endings, path displays
1 parent ed07dd9 commit b614b1b

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/test/esm-loader.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ test.suite('esm', (test) => {
5151
expect(r.err).not.toBe(null);
5252
// on node 20, this will be a path. prior versions, a file: url
5353
// on windows in node 20, it's a quasi-url like d:/path/to/throw%20error.ts
54-
expect(r.err!.message).toMatch(
54+
expect(r.err!.message.replace(/\r\n/g, '\n')).toMatch(
5555
/[\\\/]throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/
5656
);
5757
// the ^ and number of line-breaks is platform-specific
5858
// also, node 20 puts the type in here when source mapping it, so it
5959
// shows as Foo.Foo.bar
60-
expect(r.err!.message).toMatch(/^ at (Foo\.){1,2}bar \(/m);
61-
expect(r.err!.message).toMatch(/^ at (Foo\.){1,2}bar ([^\n]+[\\\/]throw( |%20)error\.ts:100:17)`/m);
60+
expect(r.err!.message.replace(/\r\n/g, '\n')).toMatch(/^ at (Foo\.){1,2}bar \(/m);
61+
expect(r.err!.message.replace(/\r\n/g, '\n')).toMatch(/^ at (Foo\.){1,2}bar ([^\n\)]+[\\\/]throw( |%20)error\.ts:100:17)/m);
6262
});
6363

6464
test.suite('supports experimental-specifier-resolution=node', (test) => {
@@ -96,7 +96,7 @@ test.suite('esm', (test) => {
9696
});
9797
expect(r.err).not.toBe(null);
9898
// expect error from node's default resolver, has a few different names in different node versions
99-
expect(r.stderr).toMatch(
99+
expect(r.stderr.replace(/\r\n/g, '\n')).toMatch(
100100
/Error \[ERR_UNSUPPORTED_ESM_URL_SCHEME\]:.*(?:\n.*){0,10}\n *at (default|next)(Load|Resolve)/
101101
);
102102
});
@@ -106,7 +106,7 @@ test.suite('esm', (test) => {
106106
cwd: join(TEST_DIR, './esm-import-cache'),
107107
});
108108
expect(r.err).toBe(null);
109-
expect(r.stdout).toBe('log1\nlog2\nlog2\n');
109+
expect(r.stdout.replace(/\r\n/g, '\n')).toBe('log1\nlog2\nlog2\n');
110110
});
111111

112112
test('should support transpile only mode via dedicated loader entrypoint', async () => {

src/test/index.spec.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ test.suite('ts-node', (test) => {
181181
throw new Error('Command was expected to fail, but it succeeded.');
182182
}
183183

184-
expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/);
184+
expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(
185+
/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/
186+
);
185187
});
186188

187189
test('should work with source maps in --transpile-only mode', async () => {
@@ -190,7 +192,9 @@ test.suite('ts-node', (test) => {
190192
throw new Error('Command was expected to fail, but it succeeded.');
191193
}
192194

193-
expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/);
195+
expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(
196+
/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/
197+
);
194198
});
195199

196200
test('eval should work with source maps', async () => {
@@ -199,7 +203,9 @@ test.suite('ts-node', (test) => {
199203
throw new Error('Command was expected to fail, but it succeeded.');
200204
}
201205

202-
expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/);
206+
expect(r.err.message.replace(/\r\n/g, '\n')).toMatch(
207+
/throw( |%20)error\.ts:100\n bar\(\) \{ throw new Error\('this is a demo'\); \}/
208+
);
203209
});
204210

205211
for (const flavor of [

src/test/register.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ test.suite('register(create(options))', (test) => {
109109
} catch (error: any) {
110110
// on windows in node 20, this is printed as a quasi-url, like
111111
// d:/path/to/throw%20error.ts
112-
exp(error.stack).toMatch(/Error: this is a demo\n at Foo\.bar \([^)]+[\\\/]throw( %20)error\.ts:100:17\)\n/);
112+
exp(error.stack).toMatch(/Error: this is a demo\n at Foo\.bar \([^)]+[\\\/]throw( |%20)error\.ts:100:17\)\n/);
113113
}
114114
});
115115

0 commit comments

Comments
 (0)