Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): generate source map correctly when tsconfig mapRoot is set #1741

Merged
merged 1 commit into from Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions e2e/__helpers__/test-case/types.ts
Expand Up @@ -10,7 +10,7 @@ export interface RunTestOptions {
inject?: (() => any) | string
writeIo?: boolean
jestConfig?: Config.ProjectConfig | any
tsJestConfig?: TsJestConfig | any
tsJestConfig?: Partial<TsJestConfig> | any
noCache?: boolean
jestConfigPath?: string
}
Expand All @@ -24,7 +24,6 @@ export interface RunWithTemplateIteratorContext {
testLabel: string
}


export type TestRunResultsMap<T extends string = string> = { [key in T]: RunResult }

export interface PreparedTest {
Expand Down
300 changes: 294 additions & 6 deletions e2e/__tests__/__snapshots__/source-map.test.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Source map using template "default" should have the source maps comment 1`] = `
exports[`Source map with tsconfig mapRoot using template "default" should have the source maps comment 1`] = `
===[ FILE: main.ts ]============================================================
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Expand Down Expand Up @@ -34,7 +34,7 @@ exports[`Source map using template "default" should have the source maps comment
================================================================================
`;

exports[`Source map using template "default" should report correct line numbers 1`] = `
exports[`Source map with tsconfig mapRoot using template "default" should report correct line numbers 1`] = `
× jest --no-cache
↳ exit code: 1
===[ STDOUT ]===================================================================
Expand Down Expand Up @@ -92,7 +92,7 @@ exports[`Source map using template "default" should report correct line numbers
================================================================================
`;

exports[`Source map using template "with-babel-7" should have the source maps comment 1`] = `
exports[`Source map with tsconfig mapRoot using template "with-babel-7" should have the source maps comment 1`] = `
===[ FILE: main.ts ]============================================================
"use strict";

Expand Down Expand Up @@ -132,7 +132,7 @@ exports[`Source map using template "with-babel-7" should have the source maps co
================================================================================
`;

exports[`Source map using template "with-babel-7" should report correct line numbers 1`] = `
exports[`Source map with tsconfig mapRoot using template "with-babel-7" should report correct line numbers 1`] = `
× jest --no-cache
↳ exit code: 1
===[ STDOUT ]===================================================================
Expand Down Expand Up @@ -190,7 +190,7 @@ exports[`Source map using template "with-babel-7" should report correct line num
================================================================================
`;

exports[`Source map using template "with-babel-7-string-config" should have the source maps comment 1`] = `
exports[`Source map with tsconfig mapRoot using template "with-babel-7-string-config" should have the source maps comment 1`] = `
===[ FILE: main.ts ]============================================================
"use strict";

Expand Down Expand Up @@ -230,7 +230,295 @@ exports[`Source map using template "with-babel-7-string-config" should have the
================================================================================
`;

exports[`Source map using template "with-babel-7-string-config" should report correct line numbers 1`] = `
exports[`Source map with tsconfig mapRoot using template "with-babel-7-string-config" should report correct line numbers 1`] = `
× jest --no-cache
↳ exit code: 1
===[ STDOUT ]===================================================================
console.log
WITHIN SOURCE

at Object.consoleLog (main.ts:2:11)

console.log
WITHIN TEST

at Object.<anonymous> (main.spec.ts:9:13)
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
console.log()
√ from sources
√ from tests
throw new Error()
× throws from sources
× throws from tests

● throw new Error() › throws from sources

WITHIN SOURCE

4 |
5 | export function throwError() {
> 6 | throw new Error('WITHIN SOURCE')
| ^
7 | }
8 |

at Object.throwError (main.ts:6:9)
at Object.<anonymous> (main.spec.ts:16:5)

● throw new Error() › throws from tests

WITHIN TEST

18 | });
19 | test('throws from tests', () => {
> 20 | throw new Error('WITHIN TEST');
| ^
21 | expect(true).toBe(true);
22 | });
23 | });

at Object.<anonymous> (main.spec.ts:20:11)

Test Suites: 1 failed, 1 total
Tests: 2 failed, 2 passed, 4 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`Source map without tsconfig mapRoot using template "default" should have the source maps comment 1`] = `
===[ FILE: main.ts ]============================================================
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.throwError = exports.consoleLog = void 0;
function consoleLog() {
console.log('WITHIN SOURCE');
}
exports.consoleLog = consoleLog;
function throwError() {
throw new Error('WITHIN SOURCE');
}
exports.throwError = throwError;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoiPGN3ZD4vbWFpbi50cyIsIm1hcHBpbmdzIjoiOzs7QUFBQSxTQUFnQixVQUFVO0lBQ3hCLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLENBQUE7QUFDOUIsQ0FBQztBQUZELGdDQUVDO0FBRUQsU0FBZ0IsVUFBVTtJQUN4QixNQUFNLElBQUksS0FBSyxDQUFDLGVBQWUsQ0FBQyxDQUFBO0FBQ2xDLENBQUM7QUFGRCxnQ0FFQyIsIm5hbWVzIjpbXSwic291cmNlcyI6WyI8Y3dkPi9tYWluLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBmdW5jdGlvbiBjb25zb2xlTG9nKCkge1xuICBjb25zb2xlLmxvZygnV0lUSElOIFNPVVJDRScpXG59XG5cbmV4cG9ydCBmdW5jdGlvbiB0aHJvd0Vycm9yKCkge1xuICB0aHJvdyBuZXcgRXJyb3IoJ1dJVEhJTiBTT1VSQ0UnKVxufVxuIl0sInZlcnNpb24iOjN9
===[ INLINE SOURCE MAPS ]=======================================================
file: <cwd>/main.ts
mappings: >-
;;;AAAA,SAAgB,UAAU;IACxB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAC9B,CAAC;AAFD,gCAEC;AAED,SAAgB,UAAU;IACxB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;AAClC,CAAC;AAFD,gCAEC
names: []
sources:
- <cwd>/main.ts
sourcesContent:
- |
export function consoleLog() {
console.log('WITHIN SOURCE')
}

export function throwError() {
throw new Error('WITHIN SOURCE')
}
version: 3
================================================================================
`;

exports[`Source map without tsconfig mapRoot using template "default" should report correct line numbers 1`] = `
× jest --no-cache
↳ exit code: 1
===[ STDOUT ]===================================================================
console.log
WITHIN SOURCE

at Object.consoleLog (main.ts:2:11)

console.log
WITHIN TEST

at Object.<anonymous> (main.spec.ts:9:13)
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
console.log()
√ from sources
√ from tests
throw new Error()
× throws from sources
× throws from tests

● throw new Error() › throws from sources

WITHIN SOURCE

4 |
5 | export function throwError() {
> 6 | throw new Error('WITHIN SOURCE')
| ^
7 | }
8 |

at Object.throwError (main.ts:6:9)
at Object.<anonymous> (main.spec.ts:16:5)

● throw new Error() › throws from tests

WITHIN TEST

18 | });
19 | test('throws from tests', () => {
> 20 | throw new Error('WITHIN TEST');
| ^
21 | expect(true).toBe(true);
22 | });
23 | });

at Object.<anonymous> (main.spec.ts:20:11)

Test Suites: 1 failed, 1 total
Tests: 2 failed, 2 passed, 4 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`Source map without tsconfig mapRoot using template "with-babel-7" should have the source maps comment 1`] = `
===[ FILE: main.ts ]============================================================
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.throwError = exports.consoleLog = void 0;

function consoleLog() {
console.log('WITHIN SOURCE');
}

exports.consoleLog = consoleLog;

function throwError() {
throw new Error('WITHIN SOURCE');
}

exports.throwError = throwError;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJtYXBwaW5ncyI6Ijs7Ozs7OztBQUFBLFNBQWdCLFVBQWhCLEdBQTBCO0FBQ3hCLEVBQUEsT0FBTyxDQUFDLEdBQVIsQ0FBWSxlQUFaO0FBQ0Q7O0FBRkQsT0FBQSxDQUFBLFVBQUEsR0FBQSxVQUFBOztBQUlBLFNBQWdCLFVBQWhCLEdBQTBCO0FBQ3hCLFFBQU0sSUFBSSxLQUFKLENBQVUsZUFBVixDQUFOO0FBQ0Q7O0FBRkQsT0FBQSxDQUFBLFVBQUEsR0FBQSxVQUFBIiwibmFtZXMiOltdLCJzb3VyY2VzIjpbIjxjd2Q+L21haW4udHMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGZ1bmN0aW9uIGNvbnNvbGVMb2coKSB7XG4gIGNvbnNvbGUubG9nKCdXSVRISU4gU09VUkNFJylcbn1cblxuZXhwb3J0IGZ1bmN0aW9uIHRocm93RXJyb3IoKSB7XG4gIHRocm93IG5ldyBFcnJvcignV0lUSElOIFNPVVJDRScpXG59XG4iXSwidmVyc2lvbiI6M30=
===[ INLINE SOURCE MAPS ]=======================================================
mappings: >-
;;;;;;;AAAA,SAAgB,UAAhB,GAA0B;AACxB,EAAA,OAAO,CAAC,GAAR,CAAY,eAAZ;AACD;;AAFD,OAAA,CAAA,UAAA,GAAA,UAAA;;AAIA,SAAgB,UAAhB,GAA0B;AACxB,QAAM,IAAI,KAAJ,CAAU,eAAV,CAAN;AACD;;AAFD,OAAA,CAAA,UAAA,GAAA,UAAA
names: []
sources:
- <cwd>/main.ts
sourcesContent:
- |
export function consoleLog() {
console.log('WITHIN SOURCE')
}

export function throwError() {
throw new Error('WITHIN SOURCE')
}
version: 3
================================================================================
`;

exports[`Source map without tsconfig mapRoot using template "with-babel-7" should report correct line numbers 1`] = `
× jest --no-cache
↳ exit code: 1
===[ STDOUT ]===================================================================
console.log
WITHIN SOURCE

at Object.consoleLog (main.ts:2:11)

console.log
WITHIN TEST

at Object.<anonymous> (main.spec.ts:9:13)
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
console.log()
√ from sources
√ from tests
throw new Error()
× throws from sources
× throws from tests

● throw new Error() › throws from sources

WITHIN SOURCE

4 |
5 | export function throwError() {
> 6 | throw new Error('WITHIN SOURCE')
| ^
7 | }
8 |

at Object.throwError (main.ts:6:9)
at Object.<anonymous> (main.spec.ts:16:5)

● throw new Error() › throws from tests

WITHIN TEST

18 | });
19 | test('throws from tests', () => {
> 20 | throw new Error('WITHIN TEST');
| ^
21 | expect(true).toBe(true);
22 | });
23 | });

at Object.<anonymous> (main.spec.ts:20:11)

Test Suites: 1 failed, 1 total
Tests: 2 failed, 2 passed, 4 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`Source map without tsconfig mapRoot using template "with-babel-7-string-config" should have the source maps comment 1`] = `
===[ FILE: main.ts ]============================================================
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.throwError = exports.consoleLog = void 0;

function consoleLog() {
console.log('WITHIN SOURCE');
}

exports.consoleLog = consoleLog;

function throwError() {
throw new Error('WITHIN SOURCE');
}

exports.throwError = throwError;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJtYXBwaW5ncyI6Ijs7Ozs7OztBQUFBLFNBQWdCLFVBQWhCLEdBQTBCO0FBQ3hCLEVBQUEsT0FBTyxDQUFDLEdBQVIsQ0FBWSxlQUFaO0FBQ0Q7O0FBRkQsT0FBQSxDQUFBLFVBQUEsR0FBQSxVQUFBOztBQUlBLFNBQWdCLFVBQWhCLEdBQTBCO0FBQ3hCLFFBQU0sSUFBSSxLQUFKLENBQVUsZUFBVixDQUFOO0FBQ0Q7O0FBRkQsT0FBQSxDQUFBLFVBQUEsR0FBQSxVQUFBIiwibmFtZXMiOltdLCJzb3VyY2VzIjpbIjxjd2Q+L21haW4udHMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGZ1bmN0aW9uIGNvbnNvbGVMb2coKSB7XG4gIGNvbnNvbGUubG9nKCdXSVRISU4gU09VUkNFJylcbn1cblxuZXhwb3J0IGZ1bmN0aW9uIHRocm93RXJyb3IoKSB7XG4gIHRocm93IG5ldyBFcnJvcignV0lUSElOIFNPVVJDRScpXG59XG4iXSwidmVyc2lvbiI6M30=
===[ INLINE SOURCE MAPS ]=======================================================
mappings: >-
;;;;;;;AAAA,SAAgB,UAAhB,GAA0B;AACxB,EAAA,OAAO,CAAC,GAAR,CAAY,eAAZ;AACD;;AAFD,OAAA,CAAA,UAAA,GAAA,UAAA;;AAIA,SAAgB,UAAhB,GAA0B;AACxB,QAAM,IAAI,KAAJ,CAAU,eAAV,CAAN;AACD;;AAFD,OAAA,CAAA,UAAA,GAAA,UAAA
names: []
sources:
- <cwd>/main.ts
sourcesContent:
- |
export function consoleLog() {
console.log('WITHIN SOURCE')
}

export function throwError() {
throw new Error('WITHIN SOURCE')
}
version: 3
================================================================================
`;

exports[`Source map without tsconfig mapRoot using template "with-babel-7-string-config" should report correct line numbers 1`] = `
× jest --no-cache
↳ exit code: 1
===[ STDOUT ]===================================================================
Expand Down
22 changes: 20 additions & 2 deletions e2e/__tests__/source-map.test.ts
Expand Up @@ -2,13 +2,14 @@ import { join } from 'path'

import { allValidPackageSets } from '../__helpers__/templates'
import { configureTestCase } from '../__helpers__/test-case'
import { TsJestConfig } from '../../src/types'

describe('Source map', () => {
function runSourceMapTests(tsJestConfig: Partial<TsJestConfig> | any) {
const testCase = configureTestCase('source-maps', {
writeIo: true,
// TS5023 - unrecognized compiler option
// TS7027 - unreachable code
tsJestConfig: { diagnostics: { ignoreCodes: [5023, 7027] } },
tsJestConfig,
})

testCase.runWithTemplates(allValidPackageSets, 1, (runTest, { templateName }) => {
Expand All @@ -35,4 +36,21 @@ describe('Source map', () => {
})
})
})
}

const BASE_CONFIG = { diagnostics: { ignoreCodes: [5023, 7027], pretty: true, throws: false } }

describe('Source map', () => {
describe('without tsconfig mapRoot', () => {
runSourceMapTests(BASE_CONFIG)
})

describe('with tsconfig mapRoot', () => {
runSourceMapTests({
...BASE_CONFIG,
tsConfig: {
mapRoot: './'
}
})
})
})