@samitouri / QOS-React-2 / commits / 769875806c

Add option for source maps when running tests (#24577)

I added a `--sourceMaps` option to our test command that enables inline source maps. I've kept it disabled by default, since it makes the tests run slower. But it's super useful when attaching to a debugger.

Andrew Clark committed May 18, 2022 at 13:48 UTC 769875806ca7b90b6ce9178531628e97ef43cd84
2 files changed +15
scripts/jest/jest-cli.js
+12
@@ -110,6 +110,12 @@ const argv = yargs
110 requiresArg: true,
111 type: 'string',
112 },
113 + sourceMaps: {
114 + describe:
115 + 'Enable inline source maps when tranforming source files with Jest. Useful for debugging, but makes it slower.',
116 + type: 'boolean',
117 + default: false,
118 + },
119 }).argv;
120
121 function logError(message) {
@@ -333,6 +339,12 @@ function getEnvars() {
339 envars.REACT_VERSION = semver.coerce(argv.reactVersion);
340 }
341
342 + if (argv.sourceMaps) {
343 + // This is off by default because it slows down the test runner, but it's
344 + // super useful when running the debugger.
345 + envars.JEST_ENABLE_SOURCE_MAPS = 'inline';
346 + }
347 +
348 return envars;
349 }
350
scripts/jest/preprocessor.js
+3
@@ -93,6 +93,9 @@ module.exports = {
93 babelOptions,
94 {
95 plugins,
96 + sourceMaps: process.env.JEST_ENABLE_SOURCE_MAPS
97 + ? process.env.JEST_ENABLE_SOURCE_MAPS
98 + : false,
99 }
100 )
101 );