ts-jest 23.10.2 → 24.0.0
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/.gitattributes +2 -0
- package/.ts-jest-digest +1 -1
- package/CHANGELOG.md +50 -0
- package/README.md +4 -4
- package/dist/cli/config/init.js +31 -16
- package/dist/cli/config/migrate.js +26 -26
- package/dist/{util/hacks.d.ts → cli/helpers/presets.d.ts} +0 -0
- package/dist/cli/helpers/presets.js +39 -0
- package/dist/cli/index.js +14 -1
- package/dist/config/config-set.d.ts +2 -0
- package/dist/config/config-set.js +51 -5
- package/dist/config/create-jest-preset.d.ts +8 -1
- package/dist/config/create-jest-preset.js +2 -42
- package/dist/index.d.ts +11 -4
- package/dist/index.js +12 -2
- package/dist/types.d.ts +3 -8
- package/dist/util/exported.d.ts +3 -0
- package/dist/util/exported.js +8 -0
- package/dist/util/importer.js +1 -20
- package/dist/util/messages.js +3 -1
- package/dist/util/testing.d.ts +35 -0
- package/dist/util/testing.js +7 -0
- package/dist/util/version-checkers.js +2 -4
- package/package.json +34 -28
- package/presets/index.d.ts +4 -4
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/dist/util/hacks.js +0 -38
package/.gitattributes
ADDED
package/.ts-jest-digest
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
a088f4bb81d7f5f72d2907fcf9d998cc1aa136a8
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
+
<a name="24.0.0"></a>
|
|
2
|
+
# [24.0.0](https://github.com/kulshekhar/ts-jest/compare/v23.10.5...v24.0.0) (2019-02-18)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* cli test ([1d67101](https://github.com/kulshekhar/ts-jest/commit/1d67101))
|
|
8
|
+
* module tests and some snapshots ([999f889](https://github.com/kulshekhar/ts-jest/commit/999f889))
|
|
9
|
+
* remove unused snapshots ([108b08b](https://github.com/kulshekhar/ts-jest/commit/108b08b))
|
|
10
|
+
* some tests ([d0f2231](https://github.com/kulshekhar/ts-jest/commit/d0f2231))
|
|
11
|
+
* test command ([8372b5e](https://github.com/kulshekhar/ts-jest/commit/8372b5e))
|
|
12
|
+
* test path for windows (attempt 1) ([6824ac4](https://github.com/kulshekhar/ts-jest/commit/6824ac4))
|
|
13
|
+
* test path for windows (attempt 2) ([eb2fc8a](https://github.com/kulshekhar/ts-jest/commit/eb2fc8a))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* **jest:** bump to 24 ([defcb77](https://github.com/kulshekhar/ts-jest/commit/defcb77))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<a name="23.10.4"></a>
|
|
23
|
+
## [23.10.4](https://github.com/kulshekhar/ts-jest/compare/v23.10.3...v23.10.4) (2018-10-06)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* **cache:** adds project's dep versions to cache key ([6cacbea](https://github.com/kulshekhar/ts-jest/commit/6cacbea)), closes [#785](https://github.com/kulshekhar/ts-jest/issues/785)
|
|
29
|
+
* **cli:** change options to better reflect the new presets ([68abcfb](https://github.com/kulshekhar/ts-jest/commit/68abcfb))
|
|
30
|
+
* **helpers:** deprecate import from ts-jest, now ts-jest/utils ([33ff29f](https://github.com/kulshekhar/ts-jest/commit/33ff29f)), closes [#782](https://github.com/kulshekhar/ts-jest/issues/782)
|
|
31
|
+
* **typings:** typo in presets definition file ([53767ab](https://github.com/kulshekhar/ts-jest/commit/53767ab))
|
|
32
|
+
* **typings:** wrong import in preset typings + test ([94dc4e7](https://github.com/kulshekhar/ts-jest/commit/94dc4e7))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<a name="23.10.3"></a>
|
|
37
|
+
## [23.10.3](https://github.com/kulshekhar/ts-jest/compare/v23.10.2...v23.10.3) (2018-09-30)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Bug Fixes
|
|
41
|
+
|
|
42
|
+
* **compiler:** do not force module kind if piping babel ([acebc8c](https://github.com/kulshekhar/ts-jest/commit/acebc8c)), closes [#767](https://github.com/kulshekhar/ts-jest/issues/767)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Features
|
|
46
|
+
|
|
47
|
+
* **helpers:** adds a mocked test helper for mock typings ([f976135](https://github.com/kulshekhar/ts-jest/commit/f976135)), closes [#576](https://github.com/kulshekhar/ts-jest/issues/576)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
1
51
|
<a name="23.10.2"></a>
|
|
2
52
|
## [23.10.2](https://github.com/kulshekhar/ts-jest/compare/v23.10.1...v23.10.2) (2018-09-26)
|
|
3
53
|
|
package/README.md
CHANGED
|
@@ -30,9 +30,9 @@ These instructions will get you setup to use `ts-jest` in your project. For more
|
|
|
30
30
|
| | using npm | using yarn |
|
|
31
31
|
|---:|---|---|
|
|
32
32
|
| **Prerequisites** | `npm i -D jest typescript` | `yarn add --dev jest typescript` |
|
|
33
|
-
| **Installing** | `npm i -D ts-jest` | `yarn add --dev ts-jest` |
|
|
34
|
-
| **Creating config** | `
|
|
35
|
-
| **Running tests** | `npm t` or `
|
|
33
|
+
| **Installing** | `npm i -D ts-jest @types/jest` | `yarn add --dev ts-jest @types/jest` |
|
|
34
|
+
| **Creating config** | `npx ts-jest config:init` | `yarn ts-jest config:init` |
|
|
35
|
+
| **Running tests** | `npm t` or `npx jest` | `yarn test` or `yarn jest` |
|
|
36
36
|
|
|
37
37
|
## Built With
|
|
38
38
|
|
|
@@ -46,7 +46,7 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
|
|
|
46
46
|
|
|
47
47
|
## Versioning
|
|
48
48
|
|
|
49
|
-
We **
|
|
49
|
+
We **DO NOT** use [SemVer](http://semver.org/) for versioning. Tho you can think about SemVer when reading our version, except our major number follow the one of Jest. For the versions available, see the [tags on this repository](https://github.com/kulshekhar/ts-jest/tags).
|
|
50
50
|
|
|
51
51
|
## Authors/maintainers
|
|
52
52
|
|
package/dist/cli/config/init.js
CHANGED
|
@@ -50,10 +50,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
50
50
|
var fs_1 = require("fs");
|
|
51
51
|
var json5_1 = require("json5");
|
|
52
52
|
var path_1 = require("path");
|
|
53
|
-
var
|
|
53
|
+
var presets_1 = require("../helpers/presets");
|
|
54
54
|
exports.run = function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
55
|
-
var file, filePath, name, isPackage, exists, pkgFile, hasPackage, _a,
|
|
56
|
-
return __generator(this, function (
|
|
55
|
+
var file, filePath, name, isPackage, exists, pkgFile, hasPackage, _a, jestPreset, askedTsconfig, force, jsdom, tsconfig, pkgJson, jsFilesProcessor, shouldPostProcessWithBabel, preset, body, base, tsJestConf, content;
|
|
56
|
+
return __generator(this, function (_b) {
|
|
57
57
|
file = args._[0] || 'jest.config.js';
|
|
58
58
|
filePath = path_1.join(process.cwd(), file);
|
|
59
59
|
name = path_1.basename(file);
|
|
@@ -61,10 +61,25 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
|
|
|
61
61
|
exists = fs_1.existsSync(filePath);
|
|
62
62
|
pkgFile = isPackage ? filePath : path_1.join(process.cwd(), 'package.json');
|
|
63
63
|
hasPackage = isPackage || fs_1.existsSync(pkgFile);
|
|
64
|
-
_a = args.
|
|
64
|
+
_a = args.jestPreset, jestPreset = _a === void 0 ? true : _a, askedTsconfig = args.tsconfig, force = args.force, jsdom = args.jsdom;
|
|
65
65
|
tsconfig = askedTsconfig === 'tsconfig.json' ? undefined : askedTsconfig;
|
|
66
|
-
hasPresetVar = allowJs || !jestPreset;
|
|
67
66
|
pkgJson = hasPackage ? JSON.parse(fs_1.readFileSync(pkgFile, 'utf8')) : {};
|
|
67
|
+
jsFilesProcessor = args.js, shouldPostProcessWithBabel = args.babel;
|
|
68
|
+
if (jsFilesProcessor == null) {
|
|
69
|
+
jsFilesProcessor = shouldPostProcessWithBabel ? 'babel' : undefined;
|
|
70
|
+
}
|
|
71
|
+
else if (shouldPostProcessWithBabel == null) {
|
|
72
|
+
shouldPostProcessWithBabel = jsFilesProcessor === 'babel';
|
|
73
|
+
}
|
|
74
|
+
if (jsFilesProcessor === 'babel') {
|
|
75
|
+
preset = presets_1.jsWIthBabel;
|
|
76
|
+
}
|
|
77
|
+
else if (jsFilesProcessor === 'ts') {
|
|
78
|
+
preset = presets_1.jsWithTs;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
preset = presets_1.defaults;
|
|
82
|
+
}
|
|
68
83
|
if (isPackage && !exists) {
|
|
69
84
|
throw new Error("File " + file + " does not exists.");
|
|
70
85
|
}
|
|
@@ -84,39 +99,39 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
|
|
|
84
99
|
}
|
|
85
100
|
}
|
|
86
101
|
if (isPackage) {
|
|
87
|
-
base =
|
|
102
|
+
base = jestPreset ? { preset: preset.name } : __assign({}, preset.value);
|
|
88
103
|
if (!jsdom)
|
|
89
104
|
base.testEnvironment = 'node';
|
|
90
|
-
if (tsconfig ||
|
|
105
|
+
if (tsconfig || shouldPostProcessWithBabel) {
|
|
91
106
|
tsJestConf = {};
|
|
92
107
|
base.globals = { 'ts-jest': tsJestConf };
|
|
93
108
|
if (tsconfig)
|
|
94
109
|
tsJestConf.tsconfig = tsconfig;
|
|
95
|
-
if (
|
|
110
|
+
if (shouldPostProcessWithBabel)
|
|
96
111
|
tsJestConf.babelConfig = true;
|
|
97
112
|
}
|
|
98
113
|
body = JSON.stringify(__assign({}, pkgJson, { jest: base }), undefined, ' ');
|
|
99
114
|
}
|
|
100
115
|
else {
|
|
101
116
|
content = [];
|
|
102
|
-
if (
|
|
103
|
-
content.push(
|
|
117
|
+
if (!jestPreset) {
|
|
118
|
+
content.push(preset.jsImport('tsjPreset') + ";", '');
|
|
104
119
|
}
|
|
105
120
|
content.push('module.exports = {');
|
|
106
|
-
if (
|
|
107
|
-
content.push("
|
|
121
|
+
if (jestPreset) {
|
|
122
|
+
content.push(" preset: '" + preset.name + "',");
|
|
108
123
|
}
|
|
109
124
|
else {
|
|
110
|
-
content.push("
|
|
125
|
+
content.push(" ...tsjPreset,");
|
|
111
126
|
}
|
|
112
127
|
if (!jsdom)
|
|
113
128
|
content.push(" testEnvironment: 'node',");
|
|
114
|
-
if (tsconfig ||
|
|
129
|
+
if (tsconfig || shouldPostProcessWithBabel) {
|
|
115
130
|
content.push(" globals: {");
|
|
116
131
|
content.push(" 'ts-jest': {");
|
|
117
132
|
if (tsconfig)
|
|
118
133
|
content.push(" tsconfig: " + json5_1.stringify(tsconfig) + ",");
|
|
119
|
-
if (
|
|
134
|
+
if (shouldPostProcessWithBabel)
|
|
120
135
|
content.push(" babelConfig: true,");
|
|
121
136
|
content.push(" },");
|
|
122
137
|
content.push(" },");
|
|
@@ -131,7 +146,7 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
|
|
|
131
146
|
}); };
|
|
132
147
|
exports.help = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
133
148
|
return __generator(this, function (_a) {
|
|
134
|
-
process.stdout.write("\nUsage:\n ts-jest config:init [options] [<config-file>]\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n Default: jest.config.js\n\nOptions:\n --force Discard any existing Jest config\n --
|
|
149
|
+
process.stdout.write("\nUsage:\n ts-jest config:init [options] [<config-file>]\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n Default: jest.config.js\n\nOptions:\n --force Discard any existing Jest config\n --js ts|babel Process .js files with ts-jest if 'ts' or with\n babel-jest if 'babel'\n --no-jest-preset Disable the use of Jest presets\n --tsconfig <file> Path to the tsconfig.json file\n --babel Pipe babel-jest after ts-jest\n --jsdom Use jsdom as test environment instead of node\n");
|
|
135
150
|
return [2];
|
|
136
151
|
});
|
|
137
152
|
}); };
|
|
@@ -65,9 +65,9 @@ var fs_1 = require("fs");
|
|
|
65
65
|
var json5_1 = require("json5");
|
|
66
66
|
var path_1 = require("path");
|
|
67
67
|
var backports_1 = require("../../util/backports");
|
|
68
|
-
var
|
|
68
|
+
var presets_1 = require("../helpers/presets");
|
|
69
69
|
exports.run = function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
70
|
-
var nullLogger, file, filePath, footNotes, name, isPackage, actualConfig, migratedConfig, presetName, jsTransformers, jsWithTs, jsWithBabel,
|
|
70
|
+
var nullLogger, file, filePath, footNotes, name, isPackage, actualConfig, migratedConfig, presetName, preset, jsTransformers, jsWithTs, jsWithBabel, presetValue, migratedValue, presetValue, migratedValue, before, after, stringify, prefix;
|
|
71
71
|
return __generator(this, function (_a) {
|
|
72
72
|
nullLogger = bs_logger_1.createLogger({ targets: [] });
|
|
73
73
|
file = args._[0];
|
|
@@ -89,8 +89,9 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
|
|
|
89
89
|
actualConfig = {};
|
|
90
90
|
migratedConfig = backports_1.backportJestConfig(nullLogger, actualConfig);
|
|
91
91
|
if (!migratedConfig.preset && args.jestPreset) {
|
|
92
|
-
if (args.
|
|
93
|
-
presetName =
|
|
92
|
+
if (args.js) {
|
|
93
|
+
presetName = args.js === 'babel' ? presets_1.JestPresetNames.jsWIthBabel : presets_1.JestPresetNames.jsWithTs;
|
|
94
|
+
}
|
|
94
95
|
else {
|
|
95
96
|
jsTransformers = Object.keys(migratedConfig.transform || {}).reduce(function (list, pattern) {
|
|
96
97
|
if (RegExp(pattern.replace(/^<rootDir>\/?/, '/dummy-project/')).test('/dummy-project/src/foo.js')) {
|
|
@@ -106,42 +107,41 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
|
|
|
106
107
|
jsWithTs = jsTransformers.includes('ts-jest');
|
|
107
108
|
jsWithBabel = jsTransformers.includes('babel-jest');
|
|
108
109
|
if (jsWithBabel && !jsWithTs) {
|
|
109
|
-
presetName =
|
|
110
|
+
presetName = presets_1.JestPresetNames.jsWIthBabel;
|
|
110
111
|
}
|
|
111
112
|
else if (jsWithTs && !jsWithBabel) {
|
|
112
|
-
presetName =
|
|
113
|
+
presetName = presets_1.JestPresetNames.jsWithTs;
|
|
113
114
|
}
|
|
114
115
|
else {
|
|
115
|
-
presetName =
|
|
116
|
+
presetName = presets_1.JestPresetNames.default;
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
|
-
presetName = presetName ||
|
|
119
|
-
|
|
120
|
-
footNotes.push("Detected preset '" +
|
|
119
|
+
presetName = presetName || presets_1.JestPresetNames.default;
|
|
120
|
+
preset = presets_1.allPresets[presetName];
|
|
121
|
+
footNotes.push("Detected preset '" + preset.label + "' as the best matching preset for your configuration.\nVisit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more information about presets.\n");
|
|
121
122
|
}
|
|
122
123
|
else if (migratedConfig.preset && migratedConfig.preset.startsWith('ts-jest')) {
|
|
123
124
|
if (args.jestPreset === false) {
|
|
124
125
|
delete migratedConfig.preset;
|
|
125
126
|
}
|
|
126
127
|
else {
|
|
127
|
-
|
|
128
|
+
preset = presets_1.allPresets[migratedConfig.preset] || presets_1.defaults;
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
presetValue = dedupSort(presets.moduleFileExtensions).join('::');
|
|
131
|
+
if (preset)
|
|
132
|
+
migratedConfig.preset = preset.name;
|
|
133
|
+
if (migratedConfig.moduleFileExtensions && migratedConfig.moduleFileExtensions.length && preset) {
|
|
134
|
+
presetValue = dedupSort(preset.value.moduleFileExtensions || []).join('::');
|
|
135
135
|
migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::');
|
|
136
136
|
if (presetValue === migratedValue) {
|
|
137
137
|
delete migratedConfig.moduleFileExtensions;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
if (migratedConfig.testRegex &&
|
|
140
|
+
if (migratedConfig.testRegex && preset) {
|
|
141
141
|
migratedConfig.testMatch = null;
|
|
142
142
|
}
|
|
143
|
-
else if (migratedConfig.testMatch && migratedConfig.testMatch.length &&
|
|
144
|
-
presetValue = dedupSort(
|
|
143
|
+
else if (migratedConfig.testMatch && migratedConfig.testMatch.length && preset) {
|
|
144
|
+
presetValue = dedupSort(preset.value.testMatch || []).join('::');
|
|
145
145
|
migratedValue = dedupSort(migratedConfig.testMatch).join('::');
|
|
146
146
|
if (presetValue === migratedValue) {
|
|
147
147
|
delete migratedConfig.testMatch;
|
|
@@ -156,9 +156,9 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
|
|
|
156
156
|
}
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
|
-
if (
|
|
159
|
+
if (preset &&
|
|
160
160
|
migratedConfig.transform &&
|
|
161
|
-
fast_json_stable_stringify_1.default(migratedConfig.transform) === fast_json_stable_stringify_1.default(
|
|
161
|
+
fast_json_stable_stringify_1.default(migratedConfig.transform) === fast_json_stable_stringify_1.default(preset.value.transform)) {
|
|
162
162
|
delete migratedConfig.transform;
|
|
163
163
|
}
|
|
164
164
|
cleanupConfig(actualConfig);
|
|
@@ -171,8 +171,8 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
|
|
|
171
171
|
}
|
|
172
172
|
stringify = /\.json$/.test(file) ? JSON.stringify : json5_1.stringify;
|
|
173
173
|
prefix = /\.json$/.test(file) ? '"jest": ' : 'module.exports = ';
|
|
174
|
-
if (
|
|
175
|
-
footNotes.push("\nI couldn't check if your \"transform\" value is the same as mine which is: " + stringify(
|
|
174
|
+
if (preset && migratedConfig.transform) {
|
|
175
|
+
footNotes.push("\nI couldn't check if your \"transform\" value is the same as mine which is: " + stringify(preset.value.transform, undefined, ' ') + "\nIf it is the case, you can safely remove the \"transform\" from what I've migrated.\n");
|
|
176
176
|
}
|
|
177
177
|
process.stderr.write("\nMigrated Jest configuration:\n");
|
|
178
178
|
process.stdout.write("" + prefix + stringify(migratedConfig, undefined, ' ') + "\n");
|
|
@@ -204,8 +204,8 @@ function cleanupConfig(config) {
|
|
|
204
204
|
if (config.testMatch.length === 0)
|
|
205
205
|
delete config.testMatch;
|
|
206
206
|
}
|
|
207
|
-
if (config.preset ===
|
|
208
|
-
config.preset =
|
|
207
|
+
if (config.preset === presets_1.JestPresetNames.default)
|
|
208
|
+
config.preset = presets_1.defaults.name;
|
|
209
209
|
}
|
|
210
210
|
function dedupSort(arr) {
|
|
211
211
|
return arr
|
|
@@ -214,7 +214,7 @@ function dedupSort(arr) {
|
|
|
214
214
|
}
|
|
215
215
|
exports.help = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
216
216
|
return __generator(this, function (_a) {
|
|
217
|
-
process.stdout.write("\nUsage:\n ts-jest config:migrate [options] <config-file>\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n\nOptions:\n --
|
|
217
|
+
process.stdout.write("\nUsage:\n ts-jest config:migrate [options] <config-file>\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n\nOptions:\n --js ts|babel Process .js files with ts-jest if 'ts' or with\n babel-jest if 'babel'\n --no-jest-preset Disable the use of Jest presets\n");
|
|
218
218
|
return [2];
|
|
219
219
|
});
|
|
220
220
|
}); };
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var JestPresetNames;
|
|
4
|
+
(function (JestPresetNames) {
|
|
5
|
+
JestPresetNames["default"] = "ts-jest/presets/default";
|
|
6
|
+
JestPresetNames["jsWithTs"] = "ts-jest/presets/js-with-ts";
|
|
7
|
+
JestPresetNames["jsWIthBabel"] = "ts-jest/presets/js-with-babel";
|
|
8
|
+
})(JestPresetNames = exports.JestPresetNames || (exports.JestPresetNames = {}));
|
|
9
|
+
var definePreset = function (fullName) { return ({
|
|
10
|
+
fullName: fullName,
|
|
11
|
+
get name() {
|
|
12
|
+
return this.isDefault ? 'ts-jest' : fullName;
|
|
13
|
+
},
|
|
14
|
+
get label() {
|
|
15
|
+
return fullName.split('/').pop();
|
|
16
|
+
},
|
|
17
|
+
get jsVarName() {
|
|
18
|
+
return this.isDefault
|
|
19
|
+
? 'defaults'
|
|
20
|
+
: fullName
|
|
21
|
+
.split('/')
|
|
22
|
+
.pop()
|
|
23
|
+
.replace(/\-([a-z])/g, function (_, l) { return l.toUpperCase(); });
|
|
24
|
+
},
|
|
25
|
+
get value() {
|
|
26
|
+
return require("../../../" + fullName.replace(/^ts-jest\//, '') + "/jest-preset");
|
|
27
|
+
},
|
|
28
|
+
jsImport: function (varName) {
|
|
29
|
+
if (varName === void 0) { varName = 'tsjPreset'; }
|
|
30
|
+
return "const { " + this.jsVarName + ": " + varName + " } = require('ts-jest/presets')";
|
|
31
|
+
},
|
|
32
|
+
get isDefault() {
|
|
33
|
+
return fullName === JestPresetNames.default;
|
|
34
|
+
},
|
|
35
|
+
}); };
|
|
36
|
+
exports.allPresets = {};
|
|
37
|
+
exports.defaults = (exports.allPresets[JestPresetNames.default] = definePreset(JestPresetNames.default));
|
|
38
|
+
exports.jsWithTs = (exports.allPresets[JestPresetNames.jsWithTs] = definePreset(JestPresetNames.jsWithTs));
|
|
39
|
+
exports.jsWIthBabel = (exports.allPresets[JestPresetNames.jsWIthBabel] = definePreset(JestPresetNames.jsWIthBabel));
|
package/dist/cli/index.js
CHANGED
|
@@ -50,11 +50,24 @@ function cli(args) {
|
|
|
50
50
|
return __generator(this, function (_b) {
|
|
51
51
|
parsedArgv = yargs_parser_1.default(args, {
|
|
52
52
|
boolean: ['dry-run', 'jest-preset', 'allow-js', 'diff', 'babel', 'force', 'jsdom'],
|
|
53
|
-
string: ['tsconfig'],
|
|
53
|
+
string: ['tsconfig', 'js'],
|
|
54
54
|
count: ['verbose'],
|
|
55
55
|
alias: { verbose: ['v'] },
|
|
56
56
|
default: { jestPreset: true, verbose: 0 },
|
|
57
|
+
coerce: {
|
|
58
|
+
js: function (val) {
|
|
59
|
+
var res = val.trim().toLowerCase();
|
|
60
|
+
if (!['babel', 'ts'].includes(res))
|
|
61
|
+
throw new Error("The 'js' option must be 'babel' or 'ts', given: '" + val + "'.");
|
|
62
|
+
return res;
|
|
63
|
+
},
|
|
64
|
+
},
|
|
57
65
|
});
|
|
66
|
+
if (parsedArgv.allowJs != null) {
|
|
67
|
+
if (parsedArgv.js)
|
|
68
|
+
throw new Error("The 'allowJs' and 'js' options cannot be set together.");
|
|
69
|
+
parsedArgv.js = parsedArgv.allowJs ? 'ts' : undefined;
|
|
70
|
+
}
|
|
58
71
|
command = parsedArgv._.shift();
|
|
59
72
|
isHelp = command === 'help';
|
|
60
73
|
if (isHelp)
|
|
@@ -4,6 +4,8 @@ import { CompilerOptions, CustomTransformers, ParsedCommandLine } from 'typescri
|
|
|
4
4
|
import { AstTransformerDesc, BabelConfig, BabelJestTransformer, TTypeScript, TsCompiler, TsJestConfig, TsJestGlobalOptions, TsJestHooksMap } from '../types';
|
|
5
5
|
export declare class ConfigSet {
|
|
6
6
|
readonly parentOptions?: TsJestGlobalOptions | undefined;
|
|
7
|
+
readonly projectPackageJson: Record<string, any>;
|
|
8
|
+
readonly projectDependencies: Record<string, string>;
|
|
7
9
|
readonly jest: jest.ProjectConfig;
|
|
8
10
|
readonly tsJest: TsJestConfig;
|
|
9
11
|
readonly typescript: ParsedCommandLine;
|
|
@@ -132,6 +132,39 @@ var ConfigSet = (function () {
|
|
|
132
132
|
this._jestConfig = jestConfig;
|
|
133
133
|
this.logger = parentLogger ? parentLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a)) : logger;
|
|
134
134
|
}
|
|
135
|
+
Object.defineProperty(ConfigSet.prototype, "projectPackageJson", {
|
|
136
|
+
get: function () {
|
|
137
|
+
var tsJestRoot = path_1.resolve(__dirname, '..', '..');
|
|
138
|
+
var pkgPath = path_1.resolve(tsJestRoot, '..', '..', 'package.json');
|
|
139
|
+
var exists = fs_1.existsSync(pkgPath);
|
|
140
|
+
if (!exists) {
|
|
141
|
+
if (fs_1.realpathSync(this.rootDir) === fs_1.realpathSync(tsJestRoot)) {
|
|
142
|
+
pkgPath = path_1.resolve(tsJestRoot, 'package.json');
|
|
143
|
+
exists = true;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.logger.warn(messages_1.Errors.UnableToFindProjectRoot);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return exists ? require(pkgPath) : {};
|
|
150
|
+
},
|
|
151
|
+
enumerable: true,
|
|
152
|
+
configurable: true
|
|
153
|
+
});
|
|
154
|
+
Object.defineProperty(ConfigSet.prototype, "projectDependencies", {
|
|
155
|
+
get: function () {
|
|
156
|
+
var pkg = this.projectPackageJson;
|
|
157
|
+
var names = Object.keys(__assign({}, pkg.optionalDependencies, pkg.peerDependencies, pkg.devDependencies, pkg.dependencies));
|
|
158
|
+
return names.reduce(function (map, name) {
|
|
159
|
+
var version = get_package_version_1.getPackageVersion(name);
|
|
160
|
+
if (version)
|
|
161
|
+
map[name] = version;
|
|
162
|
+
return map;
|
|
163
|
+
}, {});
|
|
164
|
+
},
|
|
165
|
+
enumerable: true,
|
|
166
|
+
configurable: true
|
|
167
|
+
});
|
|
135
168
|
Object.defineProperty(ConfigSet.prototype, "jest", {
|
|
136
169
|
get: function () {
|
|
137
170
|
var config = backports_1.backportJestConfig(this.logger, this._jestConfig);
|
|
@@ -238,7 +271,7 @@ var ConfigSet = (function () {
|
|
|
238
271
|
get: function () {
|
|
239
272
|
var modules = ['jest', this.tsJest.compiler];
|
|
240
273
|
if (this.tsJest.babelConfig) {
|
|
241
|
-
modules.push('@babel/core', 'babel-
|
|
274
|
+
modules.push('@babel/core', 'babel-jest');
|
|
242
275
|
}
|
|
243
276
|
return modules.reduce(function (map, name) {
|
|
244
277
|
map[name] = get_package_version_1.getPackageVersion(name) || '-';
|
|
@@ -441,13 +474,15 @@ var ConfigSet = (function () {
|
|
|
441
474
|
}
|
|
442
475
|
var cacheSuffix = sha1_1.sha1(json_1.stringify({
|
|
443
476
|
version: this.compilerModule.version,
|
|
477
|
+
digest: this.tsJestDigest,
|
|
478
|
+
dependencies: this.projectDependencies,
|
|
444
479
|
compiler: this.tsJest.compiler,
|
|
445
480
|
compilerOptions: this.typescript.options,
|
|
446
481
|
isolatedModules: this.tsJest.isolatedModules,
|
|
447
482
|
diagnostics: this.tsJest.diagnostics,
|
|
448
483
|
}));
|
|
449
484
|
var res = path_1.join(this.jest.cacheDirectory, 'ts-jest', cacheSuffix.substr(0, 2), cacheSuffix.substr(2));
|
|
450
|
-
logger.debug({ cacheDirectory: res },
|
|
485
|
+
logger.debug({ cacheDirectory: res }, 'will use file caching');
|
|
451
486
|
return res;
|
|
452
487
|
},
|
|
453
488
|
enumerable: true,
|
|
@@ -455,14 +490,13 @@ var ConfigSet = (function () {
|
|
|
455
490
|
});
|
|
456
491
|
Object.defineProperty(ConfigSet.prototype, "overriddenCompilerOptions", {
|
|
457
492
|
get: function () {
|
|
458
|
-
|
|
493
|
+
var options = {
|
|
459
494
|
sourceMap: true,
|
|
460
495
|
inlineSourceMap: false,
|
|
461
496
|
inlineSources: true,
|
|
462
497
|
declaration: false,
|
|
463
498
|
noEmit: false,
|
|
464
499
|
outDir: '$$ts-jest$$',
|
|
465
|
-
module: this.compilerModule.ModuleKind.CommonJS,
|
|
466
500
|
removeComments: false,
|
|
467
501
|
out: undefined,
|
|
468
502
|
outFile: undefined,
|
|
@@ -472,6 +506,10 @@ var ConfigSet = (function () {
|
|
|
472
506
|
emitDeclarationOnly: undefined,
|
|
473
507
|
sourceRoot: undefined,
|
|
474
508
|
};
|
|
509
|
+
if (!this.tsJest.babelConfig) {
|
|
510
|
+
options.module = this.compilerModule.ModuleKind.CommonJS;
|
|
511
|
+
}
|
|
512
|
+
return options;
|
|
475
513
|
},
|
|
476
514
|
enumerable: true,
|
|
477
515
|
configurable: true
|
|
@@ -513,6 +551,7 @@ var ConfigSet = (function () {
|
|
|
513
551
|
delete globals['ts-jest'];
|
|
514
552
|
return new jsonable_value_1.JsonableValue({
|
|
515
553
|
versions: this.versions,
|
|
554
|
+
projectDepVersions: this.projectDependencies,
|
|
516
555
|
digest: this.tsJestDigest,
|
|
517
556
|
transformers: this.astTransformers.map(function (t) { return t.name + "@" + t.version; }),
|
|
518
557
|
jest: jest,
|
|
@@ -582,7 +621,8 @@ var ConfigSet = (function () {
|
|
|
582
621
|
? ts.ModuleKind.CommonJS
|
|
583
622
|
: ts.ModuleKind.ESNext;
|
|
584
623
|
var moduleValue = finalOptions.module == null ? defaultModule : finalOptions.module;
|
|
585
|
-
if (
|
|
624
|
+
if ('module' in forcedOptions &&
|
|
625
|
+
moduleValue !== forcedOptions.module &&
|
|
586
626
|
!(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)) {
|
|
587
627
|
result.errors.push(this.makeDiagnostic(DiagnosticCodes.ConfigModuleOption, messages_1.Errors.ConfigNoModuleInterop, {
|
|
588
628
|
category: ts.DiagnosticCategory.Message,
|
|
@@ -647,6 +687,12 @@ var ConfigSet = (function () {
|
|
|
647
687
|
ConfigSet.prototype.toJSON = function () {
|
|
648
688
|
return this.jsonValue.value;
|
|
649
689
|
};
|
|
690
|
+
__decorate([
|
|
691
|
+
memoize_1.Memoize()
|
|
692
|
+
], ConfigSet.prototype, "projectPackageJson", null);
|
|
693
|
+
__decorate([
|
|
694
|
+
memoize_1.Memoize()
|
|
695
|
+
], ConfigSet.prototype, "projectDependencies", null);
|
|
650
696
|
__decorate([
|
|
651
697
|
memoize_1.Memoize()
|
|
652
698
|
], ConfigSet.prototype, "jest", null);
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
|
-
|
|
2
|
+
export interface TsJestPresets {
|
|
3
|
+
transform: Record<string, string>;
|
|
4
|
+
testMatch?: string[];
|
|
5
|
+
moduleFileExtensions?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface CreateJestPresetOptions {
|
|
8
|
+
allowJs?: boolean;
|
|
9
|
+
}
|
|
3
10
|
export declare function createJestPreset({ allowJs }?: CreateJestPresetOptions, from?: jest.InitialOptions): TsJestPresets;
|
|
@@ -10,54 +10,14 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spread = (this && this.__spread) || function () {
|
|
30
|
-
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
37
|
-
result["default"] = mod;
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
var jestConfig = __importStar(require("jest-config"));
|
|
42
14
|
var logger_1 = require("../util/logger");
|
|
43
15
|
var logger = logger_1.rootLogger.child({ namespace: 'jest-preset' });
|
|
44
|
-
var defaults = jestConfig.defaults || {
|
|
45
|
-
transform: null,
|
|
46
|
-
testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)+(spec|test).js?(x)'],
|
|
47
|
-
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
|
|
48
|
-
};
|
|
49
16
|
function createJestPreset(_a, from) {
|
|
50
17
|
var _b = (_a === void 0 ? {} : _a).allowJs, allowJs = _b === void 0 ? false : _b;
|
|
18
|
+
if (from === void 0) { from = {}; }
|
|
51
19
|
var _c;
|
|
52
20
|
logger.debug({ allowJs: allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files');
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
transform: __assign({}, from.transform, (_c = {}, _c[allowJs ? '^.+\\.[tj]sx?$' : '^.+\\.tsx?$'] = 'ts-jest', _c)),
|
|
56
|
-
testMatch: dedup(__spread((from.testMatch || []), ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'])),
|
|
57
|
-
moduleFileExtensions: dedup(__spread((from.moduleFileExtensions || []), ['ts', 'tsx'])),
|
|
58
|
-
};
|
|
21
|
+
return __assign({ transform: __assign({}, from.transform, (_c = {}, _c[allowJs ? '^.+\\.[tj]sx?$' : '^.+\\.tsx?$'] = 'ts-jest', _c)) }, (from.testMatch ? { testMatch: from.testMatch } : undefined), (from.moduleFileExtensions ? { moduleFileExtensions: from.moduleFileExtensions } : undefined));
|
|
59
22
|
}
|
|
60
23
|
exports.createJestPreset = createJestPreset;
|
|
61
|
-
function dedup(array) {
|
|
62
|
-
return array.filter(function (e, i, a) { return a.indexOf(e) === i; });
|
|
63
|
-
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { createJestPreset } from './config/create-jest-preset';
|
|
2
|
-
import { pathsToModuleNameMapper } from './config/paths-to-module-name-mapper';
|
|
1
|
+
import { createJestPreset as createJestPresetCore } from './config/create-jest-preset';
|
|
3
2
|
import { TsJestTransformer } from './ts-jest-transformer';
|
|
4
3
|
import { TsJestGlobalOptions } from './types';
|
|
4
|
+
import { mocked as mockedCore } from './util/testing';
|
|
5
|
+
export declare const mocked: typeof mockedCore;
|
|
6
|
+
export declare const createJestPreset: typeof createJestPresetCore;
|
|
7
|
+
export declare const pathsToModuleNameMapper: (mapping: import("typescript").MapLike<string[]>, { prefix }?: {
|
|
8
|
+
prefix?: string | undefined;
|
|
9
|
+
}) => {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
} | undefined;
|
|
5
12
|
export declare const version: string;
|
|
6
13
|
export declare const digest: string;
|
|
7
14
|
export declare function createTransformer(baseConfig?: TsJestGlobalOptions): TsJestTransformer;
|
|
8
|
-
declare const jestPreset: import("./
|
|
9
|
-
export {
|
|
15
|
+
declare const jestPreset: import("./config/create-jest-preset").TsJestPresets;
|
|
16
|
+
export { jestPreset, };
|
package/dist/index.js
CHANGED
|
@@ -20,14 +20,24 @@ var __spread = (this && this.__spread) || function () {
|
|
|
20
20
|
return ar;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
var _a;
|
|
24
|
+
var bs_logger_1 = require("bs-logger");
|
|
23
25
|
var fs_1 = require("fs");
|
|
24
26
|
var path_1 = require("path");
|
|
25
27
|
var create_jest_preset_1 = require("./config/create-jest-preset");
|
|
26
|
-
exports.createJestPreset = create_jest_preset_1.createJestPreset;
|
|
27
28
|
var paths_to_module_name_mapper_1 = require("./config/paths-to-module-name-mapper");
|
|
28
|
-
exports.pathsToModuleNameMapper = paths_to_module_name_mapper_1.pathsToModuleNameMapper;
|
|
29
29
|
var ts_jest_transformer_1 = require("./ts-jest-transformer");
|
|
30
|
+
var logger_1 = require("./util/logger");
|
|
31
|
+
var messages_1 = require("./util/messages");
|
|
32
|
+
var testing_1 = require("./util/testing");
|
|
30
33
|
var version_checkers_1 = require("./util/version-checkers");
|
|
34
|
+
var warn = logger_1.rootLogger.child((_a = {}, _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.warn, _a));
|
|
35
|
+
var helperMoved = function (name, helper) {
|
|
36
|
+
return warn.wrap(messages_1.interpolate(messages_1.Deprecateds.HelperMovedToUtils, { helper: name }), helper);
|
|
37
|
+
};
|
|
38
|
+
exports.mocked = helperMoved('mocked', testing_1.mocked);
|
|
39
|
+
exports.createJestPreset = helperMoved('createJestPreset', create_jest_preset_1.createJestPreset);
|
|
40
|
+
exports.pathsToModuleNameMapper = helperMoved('pathsToModuleNameMapper', paths_to_module_name_mapper_1.pathsToModuleNameMapper);
|
|
31
41
|
exports.version = require('../package.json').version;
|
|
32
42
|
exports.digest = fs_1.readFileSync(path_1.resolve(__dirname, '..', '.ts-jest-digest'), 'utf8');
|
|
33
43
|
var transformer;
|
package/dist/types.d.ts
CHANGED
|
@@ -23,11 +23,6 @@ export interface TsJestGlobalOptions {
|
|
|
23
23
|
babelConfig?: boolean | string | BabelConfig;
|
|
24
24
|
stringifyContentPathRegex?: string | RegExp;
|
|
25
25
|
}
|
|
26
|
-
export interface TsJestPresets {
|
|
27
|
-
transform: Record<string, string>;
|
|
28
|
-
testMatch: string[];
|
|
29
|
-
moduleFileExtensions: string[];
|
|
30
|
-
}
|
|
31
26
|
interface TsJestConfig$tsConfig$file {
|
|
32
27
|
kind: 'file';
|
|
33
28
|
value: string | undefined;
|
|
@@ -65,9 +60,6 @@ export interface TsJestConfig {
|
|
|
65
60
|
export interface TsJestHooksMap {
|
|
66
61
|
afterProcess?(args: any[], result: string | jest.TransformedSource): string | jest.TransformedSource | void;
|
|
67
62
|
}
|
|
68
|
-
export interface CreateJestPresetOptions {
|
|
69
|
-
allowJs?: boolean;
|
|
70
|
-
}
|
|
71
63
|
export interface TSCommon {
|
|
72
64
|
version: typeof _ts.version;
|
|
73
65
|
sys: typeof _ts.sys;
|
|
@@ -103,4 +95,7 @@ export interface AstTransformerDesc {
|
|
|
103
95
|
version: number;
|
|
104
96
|
factory(cs: ConfigSet): TransformerFactory<SourceFile>;
|
|
105
97
|
}
|
|
98
|
+
export interface IPackageJson {
|
|
99
|
+
main: string;
|
|
100
|
+
}
|
|
106
101
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var testing_1 = require("./testing");
|
|
4
|
+
exports.mocked = testing_1.mocked;
|
|
5
|
+
var create_jest_preset_1 = require("../config/create-jest-preset");
|
|
6
|
+
exports.createJestPreset = create_jest_preset_1.createJestPreset;
|
|
7
|
+
var paths_to_module_name_mapper_1 = require("../config/paths-to-module-name-mapper");
|
|
8
|
+
exports.pathsToModuleNameMapper = paths_to_module_name_mapper_1.pathsToModuleNameMapper;
|
package/dist/util/importer.js
CHANGED
|
@@ -36,15 +36,7 @@ var __spread = (this && this.__spread) || function () {
|
|
|
36
36
|
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
37
37
|
return ar;
|
|
38
38
|
};
|
|
39
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
40
|
-
if (mod && mod.__esModule) return mod;
|
|
41
|
-
var result = {};
|
|
42
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
43
|
-
result["default"] = mod;
|
|
44
|
-
return result;
|
|
45
|
-
};
|
|
46
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
var hacks = __importStar(require("./hacks"));
|
|
48
40
|
var logger_1 = require("./logger");
|
|
49
41
|
var memoize_1 = require("./memoize");
|
|
50
42
|
var messages_1 = require("./messages");
|
|
@@ -63,7 +55,6 @@ var Importer = (function () {
|
|
|
63
55
|
get: function () {
|
|
64
56
|
logger.debug('creating Importer singleton');
|
|
65
57
|
return new Importer({
|
|
66
|
-
'babel-core': [passThru(version_checkers_1.VersionCheckers.babelCoreLegacy.warn), hacks.patchBabelCore_githubIssue6577],
|
|
67
58
|
'@babel/core': [passThru(version_checkers_1.VersionCheckers.babelCore.warn)],
|
|
68
59
|
'babel-jest': [passThru(version_checkers_1.VersionCheckers.babelJest.warn)],
|
|
69
60
|
typescript: [passThru(version_checkers_1.VersionCheckers.typescript.warn)],
|
|
@@ -74,20 +65,10 @@ var Importer = (function () {
|
|
|
74
65
|
configurable: true
|
|
75
66
|
});
|
|
76
67
|
Importer.prototype.babelJest = function (why) {
|
|
77
|
-
this.tryThese('babel-core');
|
|
78
68
|
return this._import(why, 'babel-jest');
|
|
79
69
|
};
|
|
80
70
|
Importer.prototype.babelCore = function (why) {
|
|
81
|
-
return this._import(why, 'babel
|
|
82
|
-
alternatives: ['@babel/core'],
|
|
83
|
-
installTip: [
|
|
84
|
-
{
|
|
85
|
-
label: 'for Babel 7',
|
|
86
|
-
module: "babel-jest 'babel-core@^7.0.0-0' @babel/core",
|
|
87
|
-
},
|
|
88
|
-
{ label: 'for Babel 6', module: 'babel-jest babel-core' },
|
|
89
|
-
],
|
|
90
|
-
});
|
|
71
|
+
return this._import(why, '@babel/core');
|
|
91
72
|
};
|
|
92
73
|
Importer.prototype.typescript = function (why, which) {
|
|
93
74
|
return this._import(why, which);
|
package/dist/util/messages.js
CHANGED
|
@@ -14,11 +14,12 @@ var Errors;
|
|
|
14
14
|
Errors["NotMappingMultiStarPath"] = "Not mapping \"{{path}}\" because it has more than one star (`*`).";
|
|
15
15
|
Errors["NotMappingPathWithEmptyMap"] = "Not mapping \"{{path}}\" because it has no target.";
|
|
16
16
|
Errors["MappingOnlyFirstTargetOfPath"] = "Mapping only to first target of \"{{path}}\" because it has more than one ({{count}}).";
|
|
17
|
-
Errors["CannotPatchBabelCore6"] = "Error while trying to patch babel-core/lib/transformation/file: {{error}}";
|
|
18
17
|
Errors["GotJsFileButAllowJsFalse"] = "Got a `.js` file to compile while `allowJs` option is not set to `true` (file: {{path}}). To fix this:\n - if you want TypeScript to process JS files, set `allowJs` to `true` in your TypeScript config (usually tsconfig.json)\n - if you do not want TypeScript to process your `.js` files, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match `.js` files anymore";
|
|
19
18
|
Errors["GotUnknownFileTypeWithoutBabel"] = "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore.";
|
|
20
19
|
Errors["GotUnknownFileTypeWithBabel"] = "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files.";
|
|
21
20
|
Errors["ConfigNoModuleInterop"] = "If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.";
|
|
21
|
+
Errors["UnableToFindProjectRoot"] = "Unable to find the root of the project where ts-jest has been installed.";
|
|
22
|
+
Errors["UnableToResolveJestConfig"] = "Unable to resolve jest-config. Ensure Jest is properly installed.";
|
|
22
23
|
})(Errors = exports.Errors || (exports.Errors = {}));
|
|
23
24
|
var Helps;
|
|
24
25
|
(function (Helps) {
|
|
@@ -32,6 +33,7 @@ var Deprecateds;
|
|
|
32
33
|
Deprecateds["ConfigOption"] = "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.";
|
|
33
34
|
Deprecateds["ConfigOptionWithNote"] = "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.\n \u21B3 {{note}}";
|
|
34
35
|
Deprecateds["ConfigOptionUseBabelRcNote"] = "See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845";
|
|
36
|
+
Deprecateds["HelperMovedToUtils"] = "The `{{helper}}` helper has been moved to `ts-jest/utils`. Use `import { {{helper}} } from 'ts-jest/utils'` instead.";
|
|
35
37
|
})(Deprecateds = exports.Deprecateds || (exports.Deprecateds = {}));
|
|
36
38
|
var ImportReasons;
|
|
37
39
|
(function (ImportReasons) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
interface MockWithArgs<T> extends Function, jest.MockInstance<T> {
|
|
3
|
+
new (...args: ArgumentsOf<T>): T;
|
|
4
|
+
(...args: ArgumentsOf<T>): any;
|
|
5
|
+
}
|
|
6
|
+
declare type MethodKeysOf<T> = {
|
|
7
|
+
[K in keyof T]: T[K] extends Function ? K : never;
|
|
8
|
+
}[keyof T];
|
|
9
|
+
declare type PropertyKeysOf<T> = {
|
|
10
|
+
[K in keyof T]: T[K] extends Function ? never : K;
|
|
11
|
+
}[keyof T];
|
|
12
|
+
declare type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never;
|
|
13
|
+
interface MockWithArgs<T> extends Function, jest.MockInstance<T> {
|
|
14
|
+
new (...args: ArgumentsOf<T>): T;
|
|
15
|
+
(...args: ArgumentsOf<T>): any;
|
|
16
|
+
}
|
|
17
|
+
declare type MockedFunction<T> = MockWithArgs<T> & {
|
|
18
|
+
[K in keyof T]: T[K];
|
|
19
|
+
};
|
|
20
|
+
declare type MockedFunctionDeep<T> = MockWithArgs<T> & MockedObjectDeep<T>;
|
|
21
|
+
declare type MockedObject<T> = {
|
|
22
|
+
[K in MethodKeysOf<T>]: MockedFunction<T[K]>;
|
|
23
|
+
} & {
|
|
24
|
+
[K in PropertyKeysOf<T>]: T[K];
|
|
25
|
+
};
|
|
26
|
+
declare type MockedObjectDeep<T> = {
|
|
27
|
+
[K in MethodKeysOf<T>]: MockedFunctionDeep<T[K]>;
|
|
28
|
+
} & {
|
|
29
|
+
[K in PropertyKeysOf<T>]: MaybeMockedDeep<T[K]>;
|
|
30
|
+
};
|
|
31
|
+
export declare type MaybeMockedDeep<T> = T extends Function ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
|
|
32
|
+
export declare type MaybeMocked<T> = T extends Function ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
|
|
33
|
+
export declare function mocked<T>(item: T, deep?: false): MaybeMocked<T>;
|
|
34
|
+
export declare function mocked<T>(item: T, deep: true): MaybeMockedDeep<T>;
|
|
35
|
+
export {};
|
|
@@ -7,17 +7,15 @@ var messages_1 = require("./messages");
|
|
|
7
7
|
var logger = logger_1.rootLogger.child({ namespace: 'versions' });
|
|
8
8
|
var ExpectedVersions;
|
|
9
9
|
(function (ExpectedVersions) {
|
|
10
|
-
ExpectedVersions["Jest"] = ">=
|
|
10
|
+
ExpectedVersions["Jest"] = ">=24 <25";
|
|
11
11
|
ExpectedVersions["TypeScript"] = ">=2.7 <4";
|
|
12
|
-
ExpectedVersions["BabelJest"] = ">=
|
|
13
|
-
ExpectedVersions["BabelCoreLegacy"] = ">=6 <7 || 7.0.0-bridge.0";
|
|
12
|
+
ExpectedVersions["BabelJest"] = ">=24 <25";
|
|
14
13
|
ExpectedVersions["BabelCore"] = ">=7.0.0-beta.0 <8";
|
|
15
14
|
})(ExpectedVersions = exports.ExpectedVersions || (exports.ExpectedVersions = {}));
|
|
16
15
|
exports.VersionCheckers = {
|
|
17
16
|
jest: createVersionChecker('jest', ExpectedVersions.Jest),
|
|
18
17
|
typescript: createVersionChecker('typescript', ExpectedVersions.TypeScript),
|
|
19
18
|
babelJest: createVersionChecker('babel-jest', ExpectedVersions.BabelJest),
|
|
20
|
-
babelCoreLegacy: createVersionChecker('babel-core', ExpectedVersions.BabelCoreLegacy),
|
|
21
19
|
babelCore: createVersionChecker('@babel/core', ExpectedVersions.BabelCore),
|
|
22
20
|
};
|
|
23
21
|
function checkVersion(name, expectedRange, action) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"bin": "cli.js",
|
|
@@ -32,9 +32,6 @@
|
|
|
32
32
|
"changelog": "node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
33
33
|
"prepare": "npm run build",
|
|
34
34
|
"prepublishOnly": "npm run test",
|
|
35
|
-
"commitmsg": "node_modules/.bin/commitlint -E GIT_PARAMS",
|
|
36
|
-
"precommit": "node_modules/.bin/lint-staged",
|
|
37
|
-
"postcommit": "git reset",
|
|
38
35
|
"preversion": "npm run test",
|
|
39
36
|
"version": "npm run changelog && git add CHANGELOG.md"
|
|
40
37
|
},
|
|
@@ -65,47 +62,56 @@
|
|
|
65
62
|
"json5": "2.x",
|
|
66
63
|
"make-error": "1.x",
|
|
67
64
|
"mkdirp": "0.x",
|
|
68
|
-
"
|
|
65
|
+
"resolve": "1.x",
|
|
66
|
+
"semver": "^5.5",
|
|
69
67
|
"yargs-parser": "10.x"
|
|
70
68
|
},
|
|
71
69
|
"peerDependencies": {
|
|
72
|
-
"jest": ">=
|
|
70
|
+
"jest": ">=24 <25"
|
|
71
|
+
},
|
|
72
|
+
"husky": {
|
|
73
|
+
"hooks": {
|
|
74
|
+
"pre-commit": "lint-staged",
|
|
75
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
76
|
+
"post-commit": "git reset"
|
|
77
|
+
}
|
|
73
78
|
},
|
|
74
79
|
"devDependencies": {
|
|
75
80
|
"@commitlint/cli": "7.x",
|
|
76
81
|
"@commitlint/config-conventional": "7.x",
|
|
77
82
|
"@types/babel__core": "7.x",
|
|
78
|
-
"@types/buffer-from": "
|
|
79
|
-
"@types/cross-spawn": "
|
|
80
|
-
"@types/fs-extra": "
|
|
83
|
+
"@types/buffer-from": "latest",
|
|
84
|
+
"@types/cross-spawn": "latest",
|
|
85
|
+
"@types/fs-extra": "latest",
|
|
81
86
|
"@types/jest": "23.x",
|
|
82
|
-
"@types/js-yaml": "
|
|
83
|
-
"@types/json5": "
|
|
87
|
+
"@types/js-yaml": "latest",
|
|
88
|
+
"@types/json5": "latest",
|
|
84
89
|
"@types/lodash.memoize": "4.x",
|
|
85
90
|
"@types/lodash.merge": "4.x",
|
|
86
91
|
"@types/lodash.set": "4.x",
|
|
87
|
-
"@types/mkdirp": "
|
|
92
|
+
"@types/mkdirp": "latest",
|
|
88
93
|
"@types/node": "10.x",
|
|
89
|
-
"@types/
|
|
90
|
-
"@types/
|
|
94
|
+
"@types/resolve": "latest",
|
|
95
|
+
"@types/semver": "latest",
|
|
96
|
+
"@types/yargs": "latest",
|
|
91
97
|
"conventional-changelog-cli": "2.x",
|
|
92
|
-
"cross-spawn": "
|
|
93
|
-
"eslint": "
|
|
94
|
-
"fs-extra": "
|
|
95
|
-
"glob-gitignore": "
|
|
96
|
-
"husky": "
|
|
97
|
-
"jest": "
|
|
98
|
-
"js-yaml": "
|
|
99
|
-
"lint-staged": "
|
|
98
|
+
"cross-spawn": "latest",
|
|
99
|
+
"eslint": "latest",
|
|
100
|
+
"fs-extra": "latest",
|
|
101
|
+
"glob-gitignore": "latest",
|
|
102
|
+
"husky": "1.x",
|
|
103
|
+
"jest": "24.x",
|
|
104
|
+
"js-yaml": "latest",
|
|
105
|
+
"lint-staged": "latest",
|
|
100
106
|
"lodash.memoize": "4.x",
|
|
101
107
|
"lodash.merge": "4.x",
|
|
102
108
|
"lodash.set": "4.x",
|
|
103
|
-
"npm-run-all": "
|
|
104
|
-
"prettier": "
|
|
105
|
-
"source-map": "
|
|
106
|
-
"tslint": "
|
|
107
|
-
"tslint-config-prettier": "
|
|
108
|
-
"tslint-plugin-prettier": "
|
|
109
|
+
"npm-run-all": "latest",
|
|
110
|
+
"prettier": "latest",
|
|
111
|
+
"source-map": "latest",
|
|
112
|
+
"tslint": "latest",
|
|
113
|
+
"tslint-config-prettier": "latest",
|
|
114
|
+
"tslint-plugin-prettier": "latest",
|
|
109
115
|
"typescript": "3.x"
|
|
110
116
|
},
|
|
111
117
|
"lint-staged": {
|
package/presets/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TsJestPresets } from '../dist/
|
|
1
|
+
import { TsJestPresets } from '../dist/config/create-jest-preset'
|
|
2
2
|
|
|
3
|
-
export const defaults:
|
|
4
|
-
export const jsWithTs:
|
|
5
|
-
export const jsWithBabel:
|
|
3
|
+
export const defaults: TsJestPresets
|
|
4
|
+
export const jsWithTs: TsJestPresets
|
|
5
|
+
export const jsWithBabel: TsJestPresets
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/util/exported'
|
package/utils/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/util/exported')
|
package/dist/util/hacks.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var semver_1 = __importDefault(require("semver"));
|
|
7
|
-
var logger_1 = require("./logger");
|
|
8
|
-
var messages_1 = require("./messages");
|
|
9
|
-
var logger = logger_1.rootLogger.child({ namespace: 'hacks' });
|
|
10
|
-
exports.patchBabelCore_githubIssue6577 = function (babel) {
|
|
11
|
-
if (typeof babel.version !== 'string')
|
|
12
|
-
return babel;
|
|
13
|
-
var version = semver_1.default.coerce(babel.version);
|
|
14
|
-
if (version && version.major === 6) {
|
|
15
|
-
var flag = Symbol.for('ts-jest:patchBabelCore_githubIssue6577');
|
|
16
|
-
try {
|
|
17
|
-
var File = require('babel-core/lib/transformation/file').File;
|
|
18
|
-
if (File.prototype.initOptions[flag])
|
|
19
|
-
return babel;
|
|
20
|
-
File.prototype.initOptions = (function (original) {
|
|
21
|
-
return function initOptions(opt) {
|
|
22
|
-
var before = opt.sourceMaps;
|
|
23
|
-
var result = original.apply(this, arguments);
|
|
24
|
-
if (before && before !== result.sourceMaps) {
|
|
25
|
-
result.sourceMaps = before;
|
|
26
|
-
}
|
|
27
|
-
return result;
|
|
28
|
-
};
|
|
29
|
-
})(File.prototype.initOptions);
|
|
30
|
-
Object.defineProperty(File.prototype.initOptions, flag, { value: true });
|
|
31
|
-
logger.info('patched babel-core/lib/transformation/file');
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
logger.warn({ error: error }, messages_1.interpolate(messages_1.Errors.CannotPatchBabelCore6, { error: error.message }));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return babel;
|
|
38
|
-
};
|