1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.findSiblingsWithFileExtension = exports.decodePossibleOutsideJestVmPath = exports.createOutsideJestVmPath = void 0;
|
7 |
|
8 | function path() {
|
9 | const data = _interopRequireWildcard(require('path'));
|
10 |
|
11 | path = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _slash() {
|
19 | const data = _interopRequireDefault(require('slash'));
|
20 |
|
21 | _slash = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _glob() {
|
29 | const data = _interopRequireDefault(require('glob'));
|
30 |
|
31 | _glob = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _interopRequireDefault(obj) {
|
39 | return obj && obj.__esModule ? obj : {default: obj};
|
40 | }
|
41 |
|
42 | function _getRequireWildcardCache() {
|
43 | if (typeof WeakMap !== 'function') return null;
|
44 | var cache = new WeakMap();
|
45 | _getRequireWildcardCache = function () {
|
46 | return cache;
|
47 | };
|
48 | return cache;
|
49 | }
|
50 |
|
51 | function _interopRequireWildcard(obj) {
|
52 | if (obj && obj.__esModule) {
|
53 | return obj;
|
54 | }
|
55 | if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
56 | return {default: obj};
|
57 | }
|
58 | var cache = _getRequireWildcardCache();
|
59 | if (cache && cache.has(obj)) {
|
60 | return cache.get(obj);
|
61 | }
|
62 | var newObj = {};
|
63 | var hasPropertyDescriptor =
|
64 | Object.defineProperty && Object.getOwnPropertyDescriptor;
|
65 | for (var key in obj) {
|
66 | if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
67 | var desc = hasPropertyDescriptor
|
68 | ? Object.getOwnPropertyDescriptor(obj, key)
|
69 | : null;
|
70 | if (desc && (desc.get || desc.set)) {
|
71 | Object.defineProperty(newObj, key, desc);
|
72 | } else {
|
73 | newObj[key] = obj[key];
|
74 | }
|
75 | }
|
76 | }
|
77 | newObj.default = obj;
|
78 | if (cache) {
|
79 | cache.set(obj, newObj);
|
80 | }
|
81 | return newObj;
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | const OUTSIDE_JEST_VM_PROTOCOL = 'jest-main:';
|
91 |
|
92 |
|
93 | const createOutsideJestVmPath = path =>
|
94 | OUTSIDE_JEST_VM_PROTOCOL + '//' + encodeURIComponent(path);
|
95 |
|
96 | exports.createOutsideJestVmPath = createOutsideJestVmPath;
|
97 |
|
98 | const decodePossibleOutsideJestVmPath = outsideJestVmPath => {
|
99 | if (outsideJestVmPath.startsWith(OUTSIDE_JEST_VM_PROTOCOL)) {
|
100 | return decodeURIComponent(
|
101 | outsideJestVmPath.replace(
|
102 | new RegExp('^' + OUTSIDE_JEST_VM_PROTOCOL + '//'),
|
103 | ''
|
104 | )
|
105 | );
|
106 | }
|
107 |
|
108 | return undefined;
|
109 | };
|
110 |
|
111 | exports.decodePossibleOutsideJestVmPath = decodePossibleOutsideJestVmPath;
|
112 |
|
113 | const findSiblingsWithFileExtension = (
|
114 | moduleFileExtensions,
|
115 | from,
|
116 | moduleName
|
117 | ) => {
|
118 | if (!path().isAbsolute(moduleName) && path().extname(moduleName) === '') {
|
119 | const dirname = path().dirname(from);
|
120 | const pathToModule = path().resolve(dirname, moduleName);
|
121 |
|
122 | try {
|
123 | const slashedDirname = (0, _slash().default)(dirname);
|
124 |
|
125 | const matches = _glob()
|
126 | .default.sync(`${pathToModule}.*`)
|
127 | .map(match => (0, _slash().default)(match))
|
128 | .map(match => {
|
129 | const relativePath = path().posix.relative(slashedDirname, match);
|
130 | return path().posix.dirname(match) === slashedDirname
|
131 | ? `./${relativePath}`
|
132 | : relativePath;
|
133 | })
|
134 | .map(match => `\t'${match}'`)
|
135 | .join('\n');
|
136 |
|
137 | if (matches) {
|
138 | const foundMessage = `\n\nHowever, Jest was able to find:\n${matches}`;
|
139 | const mappedModuleFileExtensions = moduleFileExtensions
|
140 | .map(ext => `'${ext}'`)
|
141 | .join(', ');
|
142 | return (
|
143 | foundMessage +
|
144 | "\n\nYou might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently " +
|
145 | `[${mappedModuleFileExtensions}].\n\nSee https://jestjs.io/docs/en/configuration#modulefileextensions-arraystring`
|
146 | );
|
147 | }
|
148 | } catch {}
|
149 | }
|
150 |
|
151 | return '';
|
152 | };
|
153 |
|
154 | exports.findSiblingsWithFileExtension = findSiblingsWithFileExtension;
|