Skip to content

Commit 13c3a4a

Browse files
authored
Merge branch 'master' into fix/test-match
2 parents 4b29b7b + ff44548 commit 13c3a4a

5 files changed

Lines changed: 62 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Fixes
44

55
- `[jest-runner]` Force parallel runs for watch mode, to avoid TTY freeze ([#6647](https://github.com/facebook/jest/pull/6647))
6+
- `[jest-cli]` properly reprint resolver errors in watch mode ([#6407](https://github.com/facebook/jest/pull/6407))
67
- `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648))
78

89
## 23.3.0

e2e/__tests__/__snapshots__/module_name_mapper.test.js.snap

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,27 @@ exports[`moduleNameMapper wrong configuration 1`] = `
1313
1414
Configuration error:
1515
16-
Could not locate module ./style.css (mapped as no-such-module)
17-
18-
Please check:
19-
20-
\\"moduleNameMapper\\": {
21-
\\"/\\\\.(css|less)$/\\": \\"no-such-module\\"
22-
},
23-
\\"resolver\\": null
16+
Could not locate module ./style.css mapped as:
17+
no-such-module.
18+
19+
Please check your configuration for these entries:
20+
{
21+
\\"moduleNameMapper\\": {
22+
\\"/\\\\.(css|less)$/\\": \\"no-such-module\\"
23+
},
24+
\\"resolver\\": null
25+
}
26+
27+
8 | 'use strict';
28+
9 |
29+
> 10 | require('./style.css');
30+
| ^
31+
11 |
32+
12 | module.exports = () => 'test';
33+
13 |
34+
35+
at packages/jest-resolve/build/index.js:400:17
36+
at index.js:10:1
2437
2538
"
2639
`;

packages/jest-cli/src/watch.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,13 @@ export default function watch(
236236
outputStream,
237237
startRun,
238238
testWatcher,
239-
}).catch(error => console.error(chalk.red(error.stack)));
239+
}).catch(error =>
240+
// Errors thrown inside `runJest`, e.g. by resolvers, are caught here for
241+
// continuous watch mode execution. We need to reprint them to the
242+
// terminal and give just a little bit of extra space so they fit below
243+
// `preRunMessagePrint` message nicely.
244+
console.error('\n\n' + chalk.red(error)),
245+
);
240246
};
241247

242248
const onKeypress = (key: string) => {

packages/jest-resolve-dependencies/src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class DependencyResolver {
100100
}
101101
}
102102
}
103-
104103
const modules = this._hasteFS.getAllFiles().map(file => ({
105104
dependencies: this.resolve(file, options),
106105
file,

packages/jest-resolve/src/index.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,13 @@ class Resolver {
352352
rootDir: this._options.rootDir,
353353
});
354354
if (!module) {
355-
const error = new Error(
356-
chalk.red(`${chalk.bold('Configuration error')}:
357-
358-
Could not locate module ${chalk.bold(moduleName)} (mapped as ${chalk.bold(
359-
updatedName,
360-
)})
361-
362-
Please check:
363-
364-
"moduleNameMapper": {
365-
"${regex.toString()}": "${chalk.bold(mappedModuleName)}"
366-
},
367-
"resolver": ${chalk.bold(String(resolver))}`),
355+
throw createNoMappedModuleFoundError(
356+
moduleName,
357+
updatedName,
358+
mappedModuleName,
359+
regex,
360+
resolver,
368361
);
369-
error.stack = '';
370-
throw error;
371362
}
372363
return module;
373364
}
@@ -381,4 +372,31 @@ Please check:
381372
}
382373
}
383374

375+
const createNoMappedModuleFoundError = (
376+
moduleName,
377+
updatedName,
378+
mappedModuleName,
379+
regex,
380+
resolver,
381+
) => {
382+
const error = new Error(
383+
chalk.red(`${chalk.bold('Configuration error')}:
384+
385+
Could not locate module ${chalk.bold(moduleName)} mapped as:
386+
${chalk.bold(updatedName)}.
387+
388+
Please check your configuration for these entries:
389+
{
390+
"moduleNameMapper": {
391+
"${regex.toString()}": "${chalk.bold(mappedModuleName)}"
392+
},
393+
"resolver": ${chalk.bold(String(resolver))}
394+
}`),
395+
);
396+
397+
error.name = '';
398+
399+
return error;
400+
};
401+
384402
module.exports = Resolver;

0 commit comments

Comments
 (0)