ts-jest 26.1.1 → 26.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ts-jest-digest +1 -1
- package/CHANGELOG.md +34 -0
- package/dist/compiler/instance.js +9 -46
- package/dist/compiler/language-service.js +158 -25
- package/dist/compiler/transpiler.js +1 -9
- package/dist/config/config-set.d.ts +2 -1
- package/dist/config/config-set.js +11 -6
- package/dist/index.d.ts +1 -1
- package/dist/ts-jest-transformer.js +4 -4
- package/dist/types.d.ts +1 -10
- package/package.json +6 -6
- package/dist/compiler/compiler-utils.d.ts +0 -1
- package/dist/compiler/compiler-utils.js +0 -34
package/.ts-jest-digest
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
0737e8c053dff53d27ba181062809f8e72a79f50
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
## [26.1.4](https://github.com/kulshekhar/ts-jest/compare/v26.1.3...v26.1.4) (2020-07-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **compiler:** check if test file exists before doing type check ([#1827](https://github.com/kulshekhar/ts-jest/issues/1827)) ([cc89d5b](https://github.com/kulshekhar/ts-jest/commit/cc89d5b1f912975cd29114c5b3b0bf18426816da)), closes [#1506](https://github.com/kulshekhar/ts-jest/issues/1506)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [26.1.3](https://github.com/kulshekhar/ts-jest/compare/v26.1.2...v26.1.3) (2020-07-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* revert [#1793](https://github.com/kulshekhar/ts-jest/issues/1793) ([#1804](https://github.com/kulshekhar/ts-jest/issues/1804)) ([5095525](https://github.com/kulshekhar/ts-jest/commit/5095525333c8579c9c5e7f3149294b31f28d6774))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [26.1.2](https://github.com/kulshekhar/ts-jest/compare/v26.1.1...v26.1.2) (2020-07-13)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* **compiler:** use `resolveModuleNames` TypeScript API to get resolved modules for test files ([#1784](https://github.com/kulshekhar/ts-jest/issues/1784)) ([5f26054](https://github.com/kulshekhar/ts-jest/commit/5f2605457e94b548bd7b9b28fc968554f7eefa91)), closes [#1747](https://github.com/kulshekhar/ts-jest/issues/1747)
|
|
25
|
+
* **config:** invalidate cache when other options in `tsconfig` change ([#1788](https://github.com/kulshekhar/ts-jest/issues/1788)) ([6948855](https://github.com/kulshekhar/ts-jest/commit/69488552eca2846f3fc6ba86ab49d7893caaf521))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Performance Improvements
|
|
29
|
+
|
|
30
|
+
* **compiler:** cache module resolution for `isolatedModules: false` ([#1786](https://github.com/kulshekhar/ts-jest/issues/1786)) ([7f731ed](https://github.com/kulshekhar/ts-jest/commit/7f731ed8a02755aeb41ecb27df4eaf16db2ddd95))
|
|
31
|
+
* **compiler:** use `globsToMatcher` from `jest-util` ([#1754](https://github.com/kulshekhar/ts-jest/issues/1754)) ([44f3913](https://github.com/kulshekhar/ts-jest/commit/44f3913c2a017734ed87346b1c5fbec639d02062))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
1
35
|
<a name="26.1.1"></a>
|
|
2
36
|
## [26.1.1](https://github.com/kulshekhar/ts-jest/compare/v26.1.0...v26.1.1) (2020-06-21)
|
|
3
37
|
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __read = (this && this.__read) || function (o, n) {
|
|
14
3
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
4
|
if (!m) return o;
|
|
@@ -28,11 +17,9 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
28
17
|
};
|
|
29
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
19
|
exports.createCompilerInstance = void 0;
|
|
31
|
-
var fs_1 = require("fs");
|
|
32
|
-
var mkdirp = require("mkdirp");
|
|
33
|
-
var compiler_utils_1 = require("./compiler-utils");
|
|
34
20
|
var language_service_1 = require("./language-service");
|
|
35
21
|
var transpiler_1 = require("./transpiler");
|
|
22
|
+
var json_1 = require("../util/json");
|
|
36
23
|
var SOURCE_MAPPING_PREFIX = 'sourceMappingURL=';
|
|
37
24
|
function updateOutput(outputText, normalizedFileName, sourceMap) {
|
|
38
25
|
var base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64');
|
|
@@ -44,48 +31,24 @@ var updateSourceMap = function (sourceMapText, normalizedFileName) {
|
|
|
44
31
|
sourceMap.file = normalizedFileName;
|
|
45
32
|
sourceMap.sources = [normalizedFileName];
|
|
46
33
|
delete sourceMap.sourceRoot;
|
|
47
|
-
return
|
|
34
|
+
return json_1.stringify(sourceMap);
|
|
48
35
|
};
|
|
49
|
-
var
|
|
50
|
-
logger.debug({ fileName: fileName }, '
|
|
36
|
+
var compileAndUpdateOutput = function (compileFn, logger) { return function (code, fileName, lineOffset) {
|
|
37
|
+
logger.debug({ fileName: fileName }, 'compileAndUpdateOutput(): get compile output');
|
|
51
38
|
var _a = __read(compileFn(code, fileName, lineOffset), 2), value = _a[0], sourceMap = _a[1];
|
|
52
|
-
|
|
53
|
-
memoryCache.files.set(fileName, __assign(__assign({}, memoryCache.files.get(fileName)), { output: output }));
|
|
54
|
-
return output;
|
|
39
|
+
return updateOutput(value, fileName, sourceMap);
|
|
55
40
|
}; };
|
|
56
41
|
exports.createCompilerInstance = function (configs) {
|
|
57
42
|
var logger = configs.logger.child({ namespace: 'ts-compiler' });
|
|
58
43
|
var compilerOptions = configs.parsedTsConfig.options, tsJest = configs.tsJest;
|
|
59
|
-
var cacheDir = configs.tsCacheDir;
|
|
60
44
|
var extensions = ['.ts', '.tsx'];
|
|
61
|
-
var memoryCache = {
|
|
62
|
-
files: new Map(),
|
|
63
|
-
resolvedModules: Object.create(null),
|
|
64
|
-
};
|
|
65
45
|
if (compilerOptions.allowJs) {
|
|
66
46
|
extensions.push('.js');
|
|
67
47
|
extensions.push('.jsx');
|
|
68
48
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
memoryCache.resolvedModules = JSON.parse(fsMemoryCache);
|
|
74
|
-
}
|
|
75
|
-
catch (e) { }
|
|
76
|
-
}
|
|
77
|
-
configs.parsedTsConfig.fileNames.forEach(function (fileName) {
|
|
78
|
-
memoryCache.files.set(fileName, {
|
|
79
|
-
version: 0,
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
var compilerInstance;
|
|
83
|
-
if (!tsJest.isolatedModules) {
|
|
84
|
-
compilerInstance = language_service_1.initializeLanguageServiceInstance(configs, memoryCache, logger);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
compilerInstance = transpiler_1.initializeTranspilerInstance(configs, memoryCache, logger);
|
|
88
|
-
}
|
|
89
|
-
var compile = compileAndCacheResult(memoryCache, compilerInstance.compileFn, logger);
|
|
49
|
+
var compilerInstance = !tsJest.isolatedModules
|
|
50
|
+
? language_service_1.initializeLanguageServiceInstance(configs, logger)
|
|
51
|
+
: transpiler_1.initializeTranspilerInstance(configs, logger);
|
|
52
|
+
var compile = compileAndUpdateOutput(compilerInstance.compileFn, logger);
|
|
90
53
|
return { cwd: configs.cwd, compile: compile, program: compilerInstance.program };
|
|
91
54
|
};
|
|
@@ -1,4 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
2
49
|
var __read = (this && this.__read) || function (o, n) {
|
|
3
50
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
51
|
if (!m) return o;
|
|
@@ -19,36 +66,98 @@ var __spread = (this && this.__spread) || function () {
|
|
|
19
66
|
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
20
67
|
return ar;
|
|
21
68
|
};
|
|
69
|
+
var __values = (this && this.__values) || function(o) {
|
|
70
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
71
|
+
if (m) return m.call(o);
|
|
72
|
+
if (o && typeof o.length === "number") return {
|
|
73
|
+
next: function () {
|
|
74
|
+
if (o && i >= o.length) o = void 0;
|
|
75
|
+
return { value: o && o[i++], done: !o };
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
79
|
+
};
|
|
22
80
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
81
|
exports.initializeLanguageServiceInstance = void 0;
|
|
24
82
|
var bs_logger_1 = require("bs-logger");
|
|
83
|
+
var fs_1 = require("fs");
|
|
25
84
|
var path_1 = require("path");
|
|
85
|
+
var memoize = require("lodash.memoize");
|
|
86
|
+
var mkdirp = require("mkdirp");
|
|
26
87
|
var constants_1 = require("../constants");
|
|
27
88
|
var messages_1 = require("../util/messages");
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
function doTypeChecking(configs, fileName, service, logger) {
|
|
89
|
+
var json_1 = require("../util/json");
|
|
90
|
+
var sha1_1 = require("../util/sha1");
|
|
91
|
+
function doTypeChecking(configs, diagnosedFiles, fileName, service, logger) {
|
|
31
92
|
if (configs.shouldReportDiagnostic(fileName)) {
|
|
32
93
|
var diagnostics = service.getSemanticDiagnostics(fileName).concat(service.getSyntacticDiagnostics(fileName));
|
|
94
|
+
diagnosedFiles.push(fileName);
|
|
33
95
|
configs.raiseDiagnostics(diagnostics, fileName, logger);
|
|
34
96
|
}
|
|
35
97
|
}
|
|
36
|
-
exports.initializeLanguageServiceInstance = function (configs,
|
|
98
|
+
exports.initializeLanguageServiceInstance = function (configs, logger) {
|
|
37
99
|
var _a;
|
|
38
100
|
logger.debug('initializeLanguageServiceInstance(): create typescript compiler');
|
|
39
101
|
var ts = configs.compilerModule;
|
|
40
102
|
var cwd = configs.cwd;
|
|
41
103
|
var cacheDir = configs.tsCacheDir;
|
|
42
104
|
var _b = configs.parsedTsConfig, options = _b.options, fileNames = _b.fileNames;
|
|
105
|
+
var diagnosedFiles = [];
|
|
43
106
|
var serviceHostTraceCtx = (_a = {
|
|
44
107
|
namespace: 'ts:serviceHost',
|
|
45
108
|
call: null
|
|
46
109
|
},
|
|
47
110
|
_a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace,
|
|
48
111
|
_a);
|
|
112
|
+
var memoryCache = {
|
|
113
|
+
files: new Map(),
|
|
114
|
+
resolvedModules: new Map(),
|
|
115
|
+
};
|
|
116
|
+
var tsResolvedModulesCachePath;
|
|
117
|
+
if (cacheDir) {
|
|
118
|
+
mkdirp.sync(cacheDir);
|
|
119
|
+
tsResolvedModulesCachePath = path_1.join(cacheDir, sha1_1.sha1('ts-jest-resolved-modules', '\x00'));
|
|
120
|
+
try {
|
|
121
|
+
var cachedTSResolvedModules = fs_1.readFileSync(tsResolvedModulesCachePath, 'utf-8');
|
|
122
|
+
memoryCache.resolvedModules = new Map(json_1.parse(cachedTSResolvedModules));
|
|
123
|
+
}
|
|
124
|
+
catch (e) { }
|
|
125
|
+
}
|
|
126
|
+
configs.parsedTsConfig.fileNames.forEach(function (fileName) {
|
|
127
|
+
memoryCache.files.set(fileName, {
|
|
128
|
+
version: 0,
|
|
129
|
+
});
|
|
130
|
+
});
|
|
49
131
|
function isFileInCache(fileName) {
|
|
50
132
|
return memoryCache.files.has(fileName) && memoryCache.files.get(fileName).version !== 0;
|
|
51
133
|
}
|
|
134
|
+
var cacheReadFile = logger.wrap(serviceHostTraceCtx, 'readFile', memoize(ts.sys.readFile));
|
|
135
|
+
var moduleResolutionHost = {
|
|
136
|
+
fileExists: memoize(ts.sys.fileExists),
|
|
137
|
+
readFile: cacheReadFile,
|
|
138
|
+
directoryExists: memoize(ts.sys.directoryExists),
|
|
139
|
+
getCurrentDirectory: function () { return cwd; },
|
|
140
|
+
realpath: ts.sys.realpath && memoize(ts.sys.realpath),
|
|
141
|
+
getDirectories: memoize(ts.sys.getDirectories),
|
|
142
|
+
};
|
|
143
|
+
var moduleResolutionCache = ts.createModuleResolutionCache(cwd, function (x) { return x; }, options);
|
|
144
|
+
function resolveModuleNames(moduleNames, containingFile) {
|
|
145
|
+
var _a;
|
|
146
|
+
var normalizedContainingFile = path_1.normalize(containingFile);
|
|
147
|
+
var currentResolvedModules = (_a = memoryCache.resolvedModules.get(normalizedContainingFile)) !== null && _a !== void 0 ? _a : [];
|
|
148
|
+
return moduleNames.map(function (moduleName) {
|
|
149
|
+
var resolveModuleName = ts.resolveModuleName(moduleName, containingFile, options, moduleResolutionHost, moduleResolutionCache);
|
|
150
|
+
var resolvedModule = resolveModuleName.resolvedModule;
|
|
151
|
+
if (configs.isTestFile(normalizedContainingFile) && resolvedModule) {
|
|
152
|
+
var normalizedResolvedFileName = path_1.normalize(resolvedModule.resolvedFileName);
|
|
153
|
+
if (!currentResolvedModules.includes(normalizedResolvedFileName)) {
|
|
154
|
+
currentResolvedModules.push(normalizedResolvedFileName);
|
|
155
|
+
memoryCache.resolvedModules.set(normalizedContainingFile, currentResolvedModules);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return resolvedModule;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
52
161
|
var projectVersion = 1;
|
|
53
162
|
var updateMemoryCache = function (contents, fileName) {
|
|
54
163
|
logger.debug({ fileName: fileName }, 'updateMemoryCache(): update memory cache for language service');
|
|
@@ -90,11 +199,11 @@ exports.initializeLanguageServiceInstance = function (configs, memoryCache, logg
|
|
|
90
199
|
getScriptSnapshot: function (fileName) {
|
|
91
200
|
var _a;
|
|
92
201
|
var normalizedFileName = path_1.normalize(fileName);
|
|
93
|
-
var hit =
|
|
202
|
+
var hit = isFileInCache(normalizedFileName);
|
|
94
203
|
logger.trace({ normalizedFileName: normalizedFileName, cacheHit: hit }, 'getScriptSnapshot():', 'cache', hit ? 'hit' : 'miss');
|
|
95
204
|
if (!hit) {
|
|
96
205
|
memoryCache.files.set(normalizedFileName, {
|
|
97
|
-
text:
|
|
206
|
+
text: cacheReadFile(normalizedFileName),
|
|
98
207
|
version: 1,
|
|
99
208
|
});
|
|
100
209
|
}
|
|
@@ -104,42 +213,65 @@ exports.initializeLanguageServiceInstance = function (configs, memoryCache, logg
|
|
|
104
213
|
return ts.ScriptSnapshot.fromString(contents);
|
|
105
214
|
},
|
|
106
215
|
fileExists: memoize(ts.sys.fileExists),
|
|
107
|
-
readFile:
|
|
216
|
+
readFile: cacheReadFile,
|
|
108
217
|
readDirectory: memoize(ts.sys.readDirectory),
|
|
109
218
|
getDirectories: memoize(ts.sys.getDirectories),
|
|
110
219
|
directoryExists: memoize(ts.sys.directoryExists),
|
|
111
|
-
realpath: memoize(ts.sys.realpath),
|
|
220
|
+
realpath: ts.sys.realpath && memoize(ts.sys.realpath),
|
|
112
221
|
getNewLine: function () { return constants_1.LINE_FEED; },
|
|
113
222
|
getCurrentDirectory: function () { return cwd; },
|
|
114
223
|
getCompilationSettings: function () { return options; },
|
|
115
224
|
getDefaultLibFileName: function () { return ts.getDefaultLibFilePath(options); },
|
|
116
225
|
getCustomTransformers: function () { return configs.tsCustomTransformers; },
|
|
226
|
+
resolveModuleNames: resolveModuleNames,
|
|
117
227
|
};
|
|
118
228
|
logger.debug('initializeLanguageServiceInstance(): creating language service');
|
|
119
229
|
var service = ts.createLanguageService(serviceHost, ts.createDocumentRegistry());
|
|
120
230
|
return {
|
|
121
231
|
compileFn: function (code, fileName) {
|
|
232
|
+
var e_1, _a;
|
|
233
|
+
var _b;
|
|
122
234
|
logger.debug({ fileName: fileName }, 'compileFn(): compiling using language service');
|
|
123
235
|
updateMemoryCache(code, fileName);
|
|
124
236
|
var output = service.getEmitOutput(fileName);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return entry[1].modulePaths.find(function (modulePath) { return modulePath === fileName; }) && !memoryCache.files.has(entry[0]);
|
|
135
|
-
})
|
|
136
|
-
.forEach(function (entry) {
|
|
137
|
-
var testFileName = entry[0];
|
|
138
|
-
var testFileContent = entry[1].testFileContent;
|
|
139
|
-
logger.debug({ fileName: fileName }, 'compileFn(): computing diagnostics for test file that imports this module using language service');
|
|
140
|
-
updateMemoryCache(testFileContent, testFileName);
|
|
141
|
-
doTypeChecking(configs, testFileName, service, logger);
|
|
237
|
+
if (tsResolvedModulesCachePath) {
|
|
238
|
+
void (function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
239
|
+
return __generator(this, function (_a) {
|
|
240
|
+
switch (_a.label) {
|
|
241
|
+
case 0: return [4, fs_1.writeFile(tsResolvedModulesCachePath, json_1.stringify(__spread(memoryCache.resolvedModules)), function () { })];
|
|
242
|
+
case 1:
|
|
243
|
+
_a.sent();
|
|
244
|
+
return [2];
|
|
245
|
+
}
|
|
142
246
|
});
|
|
247
|
+
}); })();
|
|
248
|
+
}
|
|
249
|
+
if (!diagnosedFiles.includes(fileName)) {
|
|
250
|
+
logger.debug({ fileName: fileName }, 'compileFn(): computing diagnostics using language service');
|
|
251
|
+
doTypeChecking(configs, diagnosedFiles, fileName, service, logger);
|
|
252
|
+
}
|
|
253
|
+
if (!configs.isTestFile(fileName)) {
|
|
254
|
+
try {
|
|
255
|
+
for (var _c = __values(memoryCache.resolvedModules.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
256
|
+
var _e = __read(_d.value, 2), testFileName = _e[0], resolvedModules = _e[1];
|
|
257
|
+
if (resolvedModules.includes(fileName) &&
|
|
258
|
+
!diagnosedFiles.includes(testFileName) &&
|
|
259
|
+
fs_1.existsSync(testFileName)) {
|
|
260
|
+
var testFileContent = (_b = memoryCache.files.get(testFileName)) === null || _b === void 0 ? void 0 : _b.text;
|
|
261
|
+
if (!testFileContent) {
|
|
262
|
+
updateMemoryCache(cacheReadFile(testFileName), testFileName);
|
|
263
|
+
}
|
|
264
|
+
logger.debug({ testFileName: testFileName }, 'compileFn(): computing diagnostics using language service for test file which uses the module');
|
|
265
|
+
doTypeChecking(configs, diagnosedFiles, testFileName, service, logger);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
270
|
+
finally {
|
|
271
|
+
try {
|
|
272
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
273
|
+
}
|
|
274
|
+
finally { if (e_1) throw e_1.error; }
|
|
143
275
|
}
|
|
144
276
|
}
|
|
145
277
|
if (output.emitSkipped) {
|
|
@@ -150,6 +282,7 @@ exports.initializeLanguageServiceInstance = function (configs, memoryCache, logg
|
|
|
150
282
|
file: path_1.basename(fileName),
|
|
151
283
|
}));
|
|
152
284
|
}
|
|
285
|
+
memoryCache.files.set(fileName, __assign(__assign({}, memoryCache.files.get(fileName)), { output: output.outputFiles[1].text }));
|
|
153
286
|
return [output.outputFiles[1].text, output.outputFiles[0].text];
|
|
154
287
|
},
|
|
155
288
|
program: service.getProgram(),
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initializeTranspilerInstance = void 0;
|
|
4
|
-
exports.initializeTranspilerInstance = function (configs,
|
|
4
|
+
exports.initializeTranspilerInstance = function (configs, logger) {
|
|
5
5
|
logger.debug('initializeTranspilerInstance(): create typescript compiler');
|
|
6
6
|
var _a = configs.parsedTsConfig, options = _a.options, fileNames = _a.fileNames;
|
|
7
7
|
var ts = configs.compilerModule;
|
|
8
8
|
var program = ts.createProgram(fileNames, options);
|
|
9
|
-
var updateFileInCache = function (contents, filePath) {
|
|
10
|
-
var file = memoryCache.files.get(filePath);
|
|
11
|
-
if (file && file.text !== contents) {
|
|
12
|
-
file.version++;
|
|
13
|
-
file.text = contents;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
9
|
return {
|
|
17
10
|
compileFn: function (code, fileName) {
|
|
18
|
-
updateFileInCache(code, fileName);
|
|
19
11
|
logger.debug({ fileName: fileName }, 'compileFn(): compiling as isolated module');
|
|
20
12
|
var result = ts.transpileModule(code, {
|
|
21
13
|
fileName: fileName,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Config } from '@jest/types';
|
|
2
2
|
import { Logger } from 'bs-logger';
|
|
3
|
-
import { TsCompiler, TsJestGlobalOptions } from '../types';
|
|
3
|
+
import { TsCompiler, TsJestGlobalOptions, TTypeScript } from '../types';
|
|
4
4
|
export declare class ConfigSet {
|
|
5
5
|
readonly parentOptions?: TsJestGlobalOptions | undefined;
|
|
6
6
|
get versions(): Record<string, string>;
|
|
7
|
+
get compilerModule(): TTypeScript;
|
|
7
8
|
get tsCompiler(): TsCompiler;
|
|
8
9
|
get tsJestDigest(): string;
|
|
9
10
|
readonly logger: Logger;
|
|
@@ -52,6 +52,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
52
52
|
exports.ConfigSet = exports.TS_JEST_OUT_DIR = exports.IGNORE_DIAGNOSTIC_CODES = exports.MATCH_NOTHING = void 0;
|
|
53
53
|
var bs_logger_1 = require("bs-logger");
|
|
54
54
|
var fs_1 = require("fs");
|
|
55
|
+
var jest_util_1 = require("jest-util");
|
|
55
56
|
var json5 = require("json5");
|
|
56
57
|
var path_1 = require("path");
|
|
57
58
|
var typescript_1 = require("typescript");
|
|
@@ -194,7 +195,7 @@ var ConfigSet = (function () {
|
|
|
194
195
|
enumerable: false,
|
|
195
196
|
configurable: true
|
|
196
197
|
});
|
|
197
|
-
Object.defineProperty(ConfigSet.prototype, "
|
|
198
|
+
Object.defineProperty(ConfigSet.prototype, "isTestFile", {
|
|
198
199
|
get: function () {
|
|
199
200
|
var matchablePatterns = __spread(this.jest.testMatch, this.jest.testRegex).filter(function (pattern) {
|
|
200
201
|
return pattern instanceof RegExp || typeof pattern === 'string';
|
|
@@ -202,7 +203,11 @@ var ConfigSet = (function () {
|
|
|
202
203
|
if (!matchablePatterns.length) {
|
|
203
204
|
matchablePatterns.push.apply(matchablePatterns, __spread(constants_1.DEFAULT_JEST_TEST_MATCH));
|
|
204
205
|
}
|
|
205
|
-
return
|
|
206
|
+
var stringPatterns = matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; });
|
|
207
|
+
var isMatch = jest_util_1.globsToMatcher(stringPatterns);
|
|
208
|
+
return function (fileName) {
|
|
209
|
+
return matchablePatterns.some(function (pattern) { return (typeof pattern === 'string' ? isMatch(fileName) : pattern.test(fileName)); });
|
|
210
|
+
};
|
|
206
211
|
},
|
|
207
212
|
enumerable: false,
|
|
208
213
|
configurable: true
|
|
@@ -584,7 +589,10 @@ var ConfigSet = (function () {
|
|
|
584
589
|
jest: jest,
|
|
585
590
|
tsJest: this.tsJest,
|
|
586
591
|
babel: this.babel,
|
|
587
|
-
tsconfig:
|
|
592
|
+
tsconfig: {
|
|
593
|
+
options: this.parsedTsConfig.options,
|
|
594
|
+
raw: this.parsedTsConfig.raw,
|
|
595
|
+
},
|
|
588
596
|
});
|
|
589
597
|
},
|
|
590
598
|
enumerable: false,
|
|
@@ -731,9 +739,6 @@ var ConfigSet = (function () {
|
|
|
731
739
|
__decorate([
|
|
732
740
|
memoize_1.Memoize()
|
|
733
741
|
], ConfigSet.prototype, "jest", null);
|
|
734
|
-
__decorate([
|
|
735
|
-
memoize_1.Memoize()
|
|
736
|
-
], ConfigSet.prototype, "testMatchPatterns", null);
|
|
737
742
|
__decorate([
|
|
738
743
|
memoize_1.Memoize()
|
|
739
744
|
], ConfigSet.prototype, "tsJest", null);
|
package/dist/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ declare const jestPreset: Pick<Partial<{
|
|
|
44
44
|
dependencyExtractor: string;
|
|
45
45
|
detectLeaks: boolean;
|
|
46
46
|
detectOpenHandles: boolean;
|
|
47
|
-
displayName: import("@jest/types/build/Config").DisplayName;
|
|
47
|
+
displayName: string | import("@jest/types/build/Config").DisplayName;
|
|
48
48
|
expand: boolean;
|
|
49
49
|
extraGlobals: string[];
|
|
50
50
|
filter: string;
|
|
@@ -67,13 +67,13 @@ var TsJestTransformer = (function () {
|
|
|
67
67
|
var source = input;
|
|
68
68
|
var configs = this.configsFor(jestConfig);
|
|
69
69
|
var hooks = configs.hooks;
|
|
70
|
-
var
|
|
71
|
-
var babelJest =
|
|
70
|
+
var shouldStringifyContent = configs.shouldStringifyContent(filePath);
|
|
71
|
+
var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
|
|
72
72
|
var isDefinitionFile = filePath.endsWith('.d.ts');
|
|
73
73
|
var isJsFile = constants_1.JS_JSX_REGEX.test(filePath);
|
|
74
74
|
var isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(filePath);
|
|
75
|
-
if (
|
|
76
|
-
result = "module.exports=" +
|
|
75
|
+
if (shouldStringifyContent) {
|
|
76
|
+
result = "module.exports=" + json_1.stringify(source);
|
|
77
77
|
}
|
|
78
78
|
else if (isDefinitionFile) {
|
|
79
79
|
result = '';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _babel from 'babel__core';
|
|
2
2
|
import * as _ts from 'typescript';
|
|
3
|
+
export declare type TTypeScript = typeof _ts;
|
|
3
4
|
export declare type BabelConfig = _babel.TransformOptions;
|
|
4
5
|
export interface TsJestGlobalOptions {
|
|
5
6
|
tsConfig?: boolean | string | _ts.CompilerOptions;
|
|
@@ -65,14 +66,4 @@ export interface TsJestConfig {
|
|
|
65
66
|
export interface TsCompiler {
|
|
66
67
|
program: _ts.Program | undefined;
|
|
67
68
|
}
|
|
68
|
-
export declare type TSFiles = Map<string, TSFile>;
|
|
69
|
-
export interface TSFile {
|
|
70
|
-
text?: string;
|
|
71
|
-
output?: string;
|
|
72
|
-
version: number;
|
|
73
|
-
projectReference?: {
|
|
74
|
-
project?: _ts.ResolvedProjectReference;
|
|
75
|
-
outputFileName?: string;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
69
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-jest",
|
|
3
|
-
"version": "26.1.
|
|
3
|
+
"version": "26.1.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"bin": "cli.js",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"bs-logger": "0.x",
|
|
61
61
|
"buffer-from": "1.x",
|
|
62
62
|
"fast-json-stable-stringify": "2.x",
|
|
63
|
+
"jest-util": "26.x",
|
|
63
64
|
"json5": "2.x",
|
|
64
65
|
"lodash.memoize": "4.x",
|
|
65
66
|
"make-error": "1.x",
|
|
66
|
-
"micromatch": "4.x",
|
|
67
67
|
"mkdirp": "1.x",
|
|
68
68
|
"semver": "7.x",
|
|
69
69
|
"yargs-parser": "18.x"
|
|
@@ -80,15 +80,15 @@
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@commitlint/cli": "
|
|
84
|
-
"@commitlint/config-conventional": "
|
|
83
|
+
"@commitlint/cli": "9.x",
|
|
84
|
+
"@commitlint/config-conventional": "9.x",
|
|
85
85
|
"@jest/transform": "26.x",
|
|
86
86
|
"@jest/types": "26.x",
|
|
87
87
|
"@types/babel__core": "7.x",
|
|
88
88
|
"@types/buffer-from": "latest",
|
|
89
89
|
"@types/cross-spawn": "latest",
|
|
90
90
|
"@types/fs-extra": "latest",
|
|
91
|
-
"@types/jest": "
|
|
91
|
+
"@types/jest": "26.x",
|
|
92
92
|
"@types/js-yaml": "latest",
|
|
93
93
|
"@types/json5": "latest",
|
|
94
94
|
"@types/lodash.memoize": "4.x",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"@types/lodash.set": "4.x",
|
|
97
97
|
"@types/micromatch": "4.x",
|
|
98
98
|
"@types/mkdirp": "latest",
|
|
99
|
-
"@types/node": "
|
|
99
|
+
"@types/node": "12.x",
|
|
100
100
|
"@types/react": "16.x",
|
|
101
101
|
"@types/semver": "latest",
|
|
102
102
|
"@types/yargs": "latest",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTestFile = exports.cacheResolvedModules = exports.getResolvedModulesCache = void 0;
|
|
4
|
-
var fs_1 = require("fs");
|
|
5
|
-
var micromatch = require("micromatch");
|
|
6
|
-
var path_1 = require("path");
|
|
7
|
-
var sha1_1 = require("../util/sha1");
|
|
8
|
-
function getResolvedModulesCache(cacheDir) {
|
|
9
|
-
return path_1.join(cacheDir, sha1_1.sha1('ts-jest-resolved-modules', '\x00'));
|
|
10
|
-
}
|
|
11
|
-
exports.getResolvedModulesCache = getResolvedModulesCache;
|
|
12
|
-
function cacheResolvedModules(fileName, fileContent, memoryCache, program, cacheDir, logger) {
|
|
13
|
-
var importReferences = program.getSourceFile(fileName).imports;
|
|
14
|
-
if (importReferences.length) {
|
|
15
|
-
logger.debug({ fileName: fileName }, 'cacheResolvedModules(): get resolved modules');
|
|
16
|
-
memoryCache.resolvedModules[fileName] = Object.create(null);
|
|
17
|
-
memoryCache.resolvedModules[fileName].modulePaths = importReferences
|
|
18
|
-
.filter(function (importReference) { var _a; return (_a = importReference.parent.parent.resolvedModules) === null || _a === void 0 ? void 0 : _a.get(importReference.text); })
|
|
19
|
-
.map(function (importReference) {
|
|
20
|
-
return path_1.normalize(importReference.parent.parent.resolvedModules.get(importReference.text)
|
|
21
|
-
.resolvedFileName);
|
|
22
|
-
})
|
|
23
|
-
.reduce(function (a, b) { return a.concat(b); }, []);
|
|
24
|
-
memoryCache.resolvedModules[fileName].testFileContent = fileContent;
|
|
25
|
-
fs_1.writeFileSync(getResolvedModulesCache(cacheDir), JSON.stringify(memoryCache.resolvedModules));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.cacheResolvedModules = cacheResolvedModules;
|
|
29
|
-
function isTestFile(testMatchPatterns, fileName) {
|
|
30
|
-
return testMatchPatterns.some(function (pattern) {
|
|
31
|
-
return typeof pattern === 'string' ? micromatch.isMatch(fileName, pattern) : pattern.test(fileName);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
exports.isTestFile = isTestFile;
|