1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = handlePotentialSyntaxError;
|
7 | exports.enhanceUnexpectedTokenMessage = enhanceUnexpectedTokenMessage;
|
8 | function _chalk() {
|
9 | const data = _interopRequireDefault(require('chalk'));
|
10 | _chalk = function () {
|
11 | return data;
|
12 | };
|
13 | return data;
|
14 | }
|
15 | function _interopRequireDefault(obj) {
|
16 | return obj && obj.__esModule ? obj : {default: obj};
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const DOT = ' \u2022 ';
|
26 | function handlePotentialSyntaxError(e) {
|
27 | if (e.codeFrame != null) {
|
28 | e.stack = `${e.message}\n${e.codeFrame}`;
|
29 | }
|
30 | if (
|
31 |
|
32 | e.name === 'SyntaxError' &&
|
33 | !e.message.includes(' expected')
|
34 | ) {
|
35 | throw enhanceUnexpectedTokenMessage(e);
|
36 | }
|
37 | return e;
|
38 | }
|
39 | function enhanceUnexpectedTokenMessage(e) {
|
40 | e.stack = `${_chalk().default.bold.red(
|
41 | 'Jest encountered an unexpected token'
|
42 | )}
|
43 |
|
44 | Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
|
45 |
|
46 | Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
|
47 |
|
48 | By default "node_modules" folder is ignored by transformers.
|
49 |
|
50 | Here's what you can do:
|
51 | ${DOT}If you are trying to use ECMAScript Modules, see ${_chalk().default.underline(
|
52 | 'https://jestjs.io/docs/ecmascript-modules'
|
53 | )} for how to enable it.
|
54 | ${DOT}If you are trying to use TypeScript, see ${_chalk().default.underline(
|
55 | 'https://jestjs.io/docs/getting-started#using-typescript'
|
56 | )}
|
57 | ${DOT}To have some of your "node_modules" files transformed, you can specify a custom ${_chalk().default.bold(
|
58 | '"transformIgnorePatterns"'
|
59 | )} in your config.
|
60 | ${DOT}If you need a custom transformation specify a ${_chalk().default.bold(
|
61 | '"transform"'
|
62 | )} option in your config.
|
63 | ${DOT}If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the ${_chalk().default.bold(
|
64 | '"moduleNameMapper"'
|
65 | )} config option.
|
66 |
|
67 | You'll find more details and examples of these config options in the docs:
|
68 | ${_chalk().default.cyan('https://jestjs.io/docs/configuration')}
|
69 | For information about custom transformations, see:
|
70 | ${_chalk().default.cyan('https://jestjs.io/docs/code-transformation')}
|
71 |
|
72 | ${_chalk().default.bold.red('Details:')}
|
73 |
|
74 | ${e.stack ?? ''}`.trimRight();
|
75 | return e;
|
76 | }
|