Skip to content

Commit

Permalink
add to sourcemap tests: --transpile-only and spaces in filenames (#1329)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cspotcode committed May 22, 2021
1 parent e993623 commit 6b8323e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
!/src
!/tests
tests/main-realpath/symlink/tsconfig.json
tests/throw.ts
tests/throw-react-tsx.tsx
tests/esm/throw.ts
tests/throw error.ts
tests/throw error react tsx.tsx
tests/esm/throw error.ts
53 changes: 43 additions & 10 deletions src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,30 @@ test.suite('ts-node', (test) => {
});

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

expect(err.message).to.contain(
[
`${join(TEST_DIR, 'throw.ts')}:100`,
`${join(TEST_DIR, 'throw error.ts')}:100`,
" bar() { throw new Error('this is a demo'); }",
' ^',
'Error: this is a demo',
].join('\n')
);
});

test('should work with source maps in --transpile-only mode', async () => {
const { err } = await exec(`${cmd} --transpile-only "throw error"`);
if (err === null) {
throw new Error('Command was expected to fail, but it succeeded.');
}

expect(err.message).to.contain(
[
`${join(TEST_DIR, 'throw error.ts')}:100`,
" bar() { throw new Error('this is a demo'); }",
' ^',
'Error: this is a demo',
Expand All @@ -292,14 +308,14 @@ test.suite('ts-node', (test) => {
});

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

expect(err.message).to.contain(
[
`${join(TEST_DIR, 'throw.ts')}:100`,
`${join(TEST_DIR, 'throw error.ts')}:100`,
" bar() { throw new Error('this is a demo'); }",
' ^',
].join('\n')
Expand Down Expand Up @@ -428,11 +444,26 @@ test.suite('ts-node', (test) => {
});

test('should use source maps with react tsx', async () => {
const { err, stdout } = await exec(`${cmd} throw-react-tsx.tsx`);
const { err, stdout } = await exec(`${cmd} "throw error react tsx.tsx"`);
expect(err).not.to.equal(null);
expect(err!.message).to.contain(
[
`${join(TEST_DIR, './throw error react tsx.tsx')}:100`,
" bar() { throw new Error('this is a demo'); }",
' ^',
'Error: this is a demo',
].join('\n')
);
});

test('should use source maps with react tsx in --transpile-only mode', async () => {
const { err, stdout } = await exec(
`${cmd} --transpile-only "throw error react tsx.tsx"`
);
expect(err).not.to.equal(null);
expect(err!.message).to.contain(
[
`${join(TEST_DIR, './throw-react-tsx.tsx')}:100`,
`${join(TEST_DIR, './throw error react tsx.tsx')}:100`,
" bar() { throw new Error('this is a demo'); }",
' ^',
'Error: this is a demo',
Expand Down Expand Up @@ -1016,12 +1047,12 @@ test.suite('ts-node', (test) => {

test('should use source maps', async () => {
try {
require('../../tests/throw');
require('../../tests/throw error');
} catch (error) {
expect(error.stack).to.contain(
[
'Error: this is a demo',
` at Foo.bar (${join(TEST_DIR, './throw.ts')}:100:17)`,
` at Foo.bar (${join(TEST_DIR, './throw error.ts')}:100:17)`,
].join('\n')
);
}
Expand Down Expand Up @@ -1175,13 +1206,15 @@ test.suite('ts-node', (test) => {
expect(stdout).to.equal('foo bar baz biff libfoo\n');
});
test('should use source maps', async () => {
const { err, stdout } = await exec(`${cmd} throw.ts`, {
const { err, stdout } = await exec(`${cmd} "throw error.ts"`, {
cwd: join(TEST_DIR, './esm'),
});
expect(err).not.to.equal(null);
expect(err!.message).to.contain(
[
`${pathToFileURL(join(TEST_DIR, './esm/throw.ts'))}:100`,
`${pathToFileURL(join(TEST_DIR, './esm/throw error.ts'))
.toString()
.replace(/%20/g, ' ')}:100`,
" bar() { throw new Error('this is a demo'); }",
' ^',
'Error: this is a demo',
Expand Down
2 changes: 1 addition & 1 deletion tests/esm/throw.ts → tests/esm/throw error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
// 100 lines is meant to be far more space than the helper functions would take.


// Space in filename is intentional to ensure we handle this correctly when providing sourcemaps



Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
// 100 lines is meant to be far more space than the helper functions would take.


// Space in filename is intentional to ensure we handle this correctly when providing sourcemaps



Expand Down
2 changes: 1 addition & 1 deletion tests/throw.ts → tests/throw error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
// 100 lines is meant to be far more space than the helper functions would take.


// Space in filename is intentional to ensure we handle this correctly when providing sourcemaps



Expand Down

0 comments on commit 6b8323e

Please sign in to comment.