Skip to content

Commit 6b8323e

Browse files
authored
add to sourcemap tests: --transpile-only and spaces in filenames (#1329)
* add to sourcemap tests: --transpile-only and spaces in filenames * explain why filenames have spaces so they are not removed in future refactoring * turns out stack traces from esm uses spaces instead of %20s * fix linter failures * update shell invocations to quote correctly for windows * fix
1 parent e993623 commit 6b8323e

File tree

5 files changed

+49
-16
lines changed

5 files changed

+49
-16
lines changed

.prettierignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
!/src
88
!/tests
99
tests/main-realpath/symlink/tsconfig.json
10-
tests/throw.ts
11-
tests/throw-react-tsx.tsx
12-
tests/esm/throw.ts
10+
tests/throw error.ts
11+
tests/throw error react tsx.tsx
12+
tests/esm/throw error.ts

src/test/index.spec.ts

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,30 @@ test.suite('ts-node', (test) => {
276276
});
277277

278278
test('should work with source maps', async () => {
279-
const { err } = await exec(`${cmd} throw`);
279+
const { err } = await exec(`${cmd} "throw error"`);
280280
if (err === null) {
281281
throw new Error('Command was expected to fail, but it succeeded.');
282282
}
283283

284284
expect(err.message).to.contain(
285285
[
286-
`${join(TEST_DIR, 'throw.ts')}:100`,
286+
`${join(TEST_DIR, 'throw error.ts')}:100`,
287+
" bar() { throw new Error('this is a demo'); }",
288+
' ^',
289+
'Error: this is a demo',
290+
].join('\n')
291+
);
292+
});
293+
294+
test('should work with source maps in --transpile-only mode', async () => {
295+
const { err } = await exec(`${cmd} --transpile-only "throw error"`);
296+
if (err === null) {
297+
throw new Error('Command was expected to fail, but it succeeded.');
298+
}
299+
300+
expect(err.message).to.contain(
301+
[
302+
`${join(TEST_DIR, 'throw error.ts')}:100`,
287303
" bar() { throw new Error('this is a demo'); }",
288304
' ^',
289305
'Error: this is a demo',
@@ -292,14 +308,14 @@ test.suite('ts-node', (test) => {
292308
});
293309

294310
test('eval should work with source maps', async () => {
295-
const { err } = await exec(`${cmd} -pe "import './throw'"`);
311+
const { err } = await exec(`${cmd} -pe "import './throw error'"`);
296312
if (err === null) {
297313
throw new Error('Command was expected to fail, but it succeeded.');
298314
}
299315

300316
expect(err.message).to.contain(
301317
[
302-
`${join(TEST_DIR, 'throw.ts')}:100`,
318+
`${join(TEST_DIR, 'throw error.ts')}:100`,
303319
" bar() { throw new Error('this is a demo'); }",
304320
' ^',
305321
].join('\n')
@@ -428,11 +444,26 @@ test.suite('ts-node', (test) => {
428444
});
429445

430446
test('should use source maps with react tsx', async () => {
431-
const { err, stdout } = await exec(`${cmd} throw-react-tsx.tsx`);
447+
const { err, stdout } = await exec(`${cmd} "throw error react tsx.tsx"`);
448+
expect(err).not.to.equal(null);
449+
expect(err!.message).to.contain(
450+
[
451+
`${join(TEST_DIR, './throw error react tsx.tsx')}:100`,
452+
" bar() { throw new Error('this is a demo'); }",
453+
' ^',
454+
'Error: this is a demo',
455+
].join('\n')
456+
);
457+
});
458+
459+
test('should use source maps with react tsx in --transpile-only mode', async () => {
460+
const { err, stdout } = await exec(
461+
`${cmd} --transpile-only "throw error react tsx.tsx"`
462+
);
432463
expect(err).not.to.equal(null);
433464
expect(err!.message).to.contain(
434465
[
435-
`${join(TEST_DIR, './throw-react-tsx.tsx')}:100`,
466+
`${join(TEST_DIR, './throw error react tsx.tsx')}:100`,
436467
" bar() { throw new Error('this is a demo'); }",
437468
' ^',
438469
'Error: this is a demo',
@@ -1016,12 +1047,12 @@ test.suite('ts-node', (test) => {
10161047

10171048
test('should use source maps', async () => {
10181049
try {
1019-
require('../../tests/throw');
1050+
require('../../tests/throw error');
10201051
} catch (error) {
10211052
expect(error.stack).to.contain(
10221053
[
10231054
'Error: this is a demo',
1024-
` at Foo.bar (${join(TEST_DIR, './throw.ts')}:100:17)`,
1055+
` at Foo.bar (${join(TEST_DIR, './throw error.ts')}:100:17)`,
10251056
].join('\n')
10261057
);
10271058
}
@@ -1175,13 +1206,15 @@ test.suite('ts-node', (test) => {
11751206
expect(stdout).to.equal('foo bar baz biff libfoo\n');
11761207
});
11771208
test('should use source maps', async () => {
1178-
const { err, stdout } = await exec(`${cmd} throw.ts`, {
1209+
const { err, stdout } = await exec(`${cmd} "throw error.ts"`, {
11791210
cwd: join(TEST_DIR, './esm'),
11801211
});
11811212
expect(err).not.to.equal(null);
11821213
expect(err!.message).to.contain(
11831214
[
1184-
`${pathToFileURL(join(TEST_DIR, './esm/throw.ts'))}:100`,
1215+
`${pathToFileURL(join(TEST_DIR, './esm/throw error.ts'))
1216+
.toString()
1217+
.replace(/%20/g, ' ')}:100`,
11851218
" bar() { throw new Error('this is a demo'); }",
11861219
' ^',
11871220
'Error: this is a demo',

tests/esm/throw.ts renamed to tests/esm/throw error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
22
// 100 lines is meant to be far more space than the helper functions would take.
33

4-
4+
// Space in filename is intentional to ensure we handle this correctly when providing sourcemaps
55

66

77

tests/throw-react-tsx.tsx renamed to tests/throw error react tsx.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
22
// 100 lines is meant to be far more space than the helper functions would take.
33

4-
4+
// Space in filename is intentional to ensure we handle this correctly when providing sourcemaps
55

66

77

tests/throw.ts renamed to tests/throw error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
22
// 100 lines is meant to be far more space than the helper functions would take.
33

4-
4+
// Space in filename is intentional to ensure we handle this correctly when providing sourcemaps
55

66

77

0 commit comments

Comments
 (0)