Skip to content

Commit

Permalink
Prevent Jest from configuring Error source-maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jun 26, 2021
1 parent 3599ead commit 9f4627f
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 30 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ describe('parseHookNames', () => {
.inspectHooks;
parseHookNames = require('../parseHookNames').default;

// Jest (jest-runner?) configures Errors to automatically account for source maps.
// This changes behavior between our tests and the browser.
// To "fix" this, clear the prepareStackTrace() method on the Error object.
delete Error.prepareStackTrace;

fetchMock.mockIf(/.+$/, request => {
const {resolve} = require('path');
const url = request.url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ function compile(fileName) {
// Generate compiled output with external source maps
writeFileSync(
resolve(externalDir, fileName),
// This comment format (//##) isn't valid;
// but it prevents Node from auto-applying source maps to stack traces
// which lets unit tests more accurately simulate browser behavior.
transformed.code +
`\n//## sourceMappingURL=${fileName}.map` +
`\n//## sourceURL=${fileName}`,
`\n//# sourceMappingURL=${fileName}.map` +
`\n//# sourceURL=${fileName}`,
'utf8',
);
writeFileSync(
Expand All @@ -61,13 +58,10 @@ function compile(fileName) {
// Generate compiled output with external inline base64 source maps
writeFileSync(
resolve(inlineDir, fileName),
// This comment format (//##) isn't valid;
// but it prevents Node from auto-applying source maps to stack traces
// which lets unit tests more accurately simulate browser behavior.
transformed.code +
'\n//## sourceMappingURL=data:application/json;charset=utf-8;base64,' +
'\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,' +
btoa(JSON.stringify(sourceMap)) +
`\n//## sourceURL=${fileName}`,
`\n//# sourceURL=${fileName}`,
'utf8',
);
}
Expand Down

0 comments on commit 9f4627f

Please sign in to comment.