UNPKG

3.17 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.makeInvalidTransformerError =
7 exports.makeInvalidSyncTransformerError =
8 exports.makeInvalidSourceMapWarning =
9 exports.makeInvalidReturnValueError =
10 void 0;
11function _chalk() {
12 const data = _interopRequireDefault(require('chalk'));
13 _chalk = function () {
14 return data;
15 };
16 return data;
17}
18function _slash() {
19 const data = _interopRequireDefault(require('slash'));
20 _slash = function () {
21 return data;
22 };
23 return data;
24}
25function _interopRequireDefault(obj) {
26 return obj && obj.__esModule ? obj : {default: obj};
27}
28/**
29 * Copyright (c) Meta Platforms, Inc. and affiliates.
30 *
31 * This source code is licensed under the MIT license found in the
32 * LICENSE file in the root directory of this source tree.
33 */
34
35const BULLET = '\u25cf ';
36const DOCUMENTATION_NOTE = ` ${_chalk().default.bold(
37 'Code Transformation Documentation:'
38)}
39 https://jestjs.io/docs/code-transformation
40`;
41const UPGRADE_NOTE = ` ${_chalk().default.bold(
42 'This error may be caused by a breaking change in Jest 28:'
43)}
44 https://jestjs.io/docs/28.x/upgrading-to-jest28#transformer
45`;
46const makeInvalidReturnValueError = transformPath =>
47 _chalk().default.red(
48 [
49 _chalk().default.bold(`${BULLET}Invalid return value:`),
50 ' `process()` or/and `processAsync()` method of code transformer found at ',
51 ` "${(0, _slash().default)(transformPath)}" `,
52 ' should return an object or a Promise resolving to an object. The object ',
53 ' must have `code` property with a string of processed code.',
54 ''
55 ].join('\n') +
56 UPGRADE_NOTE +
57 DOCUMENTATION_NOTE
58 );
59exports.makeInvalidReturnValueError = makeInvalidReturnValueError;
60const makeInvalidSourceMapWarning = (filename, transformPath) =>
61 _chalk().default.yellow(
62 [
63 _chalk().default.bold(`${BULLET}Invalid source map:`),
64 ` The source map for "${(0, _slash().default)(
65 filename
66 )}" returned by "${(0, _slash().default)(transformPath)}" is invalid.`,
67 ' Proceeding without source mapping for that file.'
68 ].join('\n')
69 );
70exports.makeInvalidSourceMapWarning = makeInvalidSourceMapWarning;
71const makeInvalidSyncTransformerError = transformPath =>
72 _chalk().default.red(
73 [
74 _chalk().default.bold(`${BULLET}Invalid synchronous transformer module:`),
75 ` "${(0, _slash().default)(
76 transformPath
77 )}" specified in the "transform" object of Jest configuration`,
78 ' must export a `process` function.',
79 ''
80 ].join('\n') + DOCUMENTATION_NOTE
81 );
82exports.makeInvalidSyncTransformerError = makeInvalidSyncTransformerError;
83const makeInvalidTransformerError = transformPath =>
84 _chalk().default.red(
85 [
86 _chalk().default.bold(`${BULLET}Invalid transformer module:`),
87 ` "${(0, _slash().default)(
88 transformPath
89 )}" specified in the "transform" object of Jest configuration`,
90 ' must export a `process` or `processAsync` or `createTransformer` function.',
91 ''
92 ].join('\n') + DOCUMENTATION_NOTE
93 );
94exports.makeInvalidTransformerError = makeInvalidTransformerError;