ts-jest 27.0.7 → 27.1.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/.ts-jest-digest +1 -1
- package/CHANGELOG.md +25 -0
- package/CONTRIBUTING.md +95 -42
- package/dist/cli/config/init.js +16 -16
- package/dist/cli/config/migrate.js +23 -19
- package/dist/cli/helpers/presets.js +2 -2
- package/dist/cli/index.js +14 -7
- package/dist/compiler/compiler-utils.js +3 -3
- package/dist/compiler/index.d.ts +3 -0
- package/dist/compiler/index.js +15 -0
- package/dist/compiler/ts-compiler.d.ts +1 -1
- package/dist/compiler/ts-compiler.js +37 -34
- package/dist/compiler/ts-jest-compiler.d.ts +1 -1
- package/dist/config/config-set.js +64 -37
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +14 -0
- package/dist/config/paths-to-module-name-mapper.js +10 -10
- package/dist/index.d.ts +8 -0
- package/dist/index.js +18 -0
- package/dist/presets/create-jest-preset.js +2 -2
- package/dist/transformers/hoist-jest.d.ts +4 -1
- package/dist/transformers/hoist-jest.js +72 -94
- package/dist/transformers/path-mapping.d.ts +2 -2
- package/dist/transformers/path-mapping.js +33 -26
- package/dist/ts-jest-transformer.d.ts +3 -1
- package/dist/ts-jest-transformer.js +87 -46
- package/dist/types.d.ts +2 -2
- package/dist/utils/backports.js +2 -2
- package/dist/utils/get-package-version.js +1 -1
- package/dist/utils/importer.js +21 -18
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/json.js +1 -1
- package/dist/utils/jsonable-value.js +1 -1
- package/dist/utils/logger.js +3 -3
- package/dist/utils/sha1.js +1 -1
- package/dist/utils/ts-error.js +1 -1
- package/dist/utils/version-checkers.js +3 -3
- package/package.json +26 -29
- package/presets/index.d.ts +1 -1
- package/utils/index.js +13 -0
package/.ts-jest-digest
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
605af00ea20195c659a2337af7e3921155cf4587
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
# [27.1.0](https://github.com/kulshekhar/ts-jest/compare/v27.0.7...v27.1.0) (2021-11-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* allow subclasses to extend `processAsync` and `getCacheKeyAsync` ([#3047](https://github.com/kulshekhar/ts-jest/issues/3047)) ([571a880](https://github.com/kulshekhar/ts-jest/commit/571a880007642c9dcbcd7bf109c5392e7eb78cc4))
|
|
7
|
+
* **config:** support custom AST transformers written in TypeScript ([#3063](https://github.com/kulshekhar/ts-jest/issues/3063)) ([340a305](https://github.com/kulshekhar/ts-jest/commit/340a30573e5ff92df77c94af51c371ce4bf956e7)), closes [#2831](https://github.com/kulshekhar/ts-jest/issues/2831)
|
|
8
|
+
* export `ts-jest` public apis from `index.js` ([#3080](https://github.com/kulshekhar/ts-jest/issues/3080)) ([53175dd](https://github.com/kulshekhar/ts-jest/commit/53175dd04218bf22ead464e30aa01b258c87e7af)), closes [#3045](https://github.com/kulshekhar/ts-jest/issues/3045)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Code Refactoring
|
|
12
|
+
|
|
13
|
+
* **utils:** deprecate `mocked` util function ([#3102](https://github.com/kulshekhar/ts-jest/issues/3102)) ([55e69f1](https://github.com/kulshekhar/ts-jest/commit/55e69f12f65d678962c3087fca7673992f5f1b26))
|
|
14
|
+
* define clear type for `compiler` option ([#3087](https://github.com/kulshekhar/ts-jest/issues/3087)) ([cc42daf](https://github.com/kulshekhar/ts-jest/commit/cc42daf795585887664be59956d2c52244237bda))
|
|
15
|
+
* **transformers**: deprecate `path-mapping` AST transformer ([#3088](https://github.com/kulshekhar/ts-jest/issues/3088)) ([d8f6b96](https://github.com/kulshekhar/ts-jest/commit/d8f6b9624ee76a164aa7003720cd3f83fc6c4865))
|
|
16
|
+
* **transformers**: use ts `factory` API for `hoisting` AST transformer ([#3058](https://github.com/kulshekhar/ts-jest/issues/3058)) ([a72f51d](https://github.com/kulshekhar/ts-jest/commit/a72f51d9b7c4ea2866e486c0aac4f4706c3ed542))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## DEPRECATIONS
|
|
20
|
+
|
|
21
|
+
* **transformers**: `path-mapping` AST transformer is deprecated and will be removed in **v28.0.0**. One should use an alternative one like https://github.com/LeDDGroup/typescript-transform-paths instead.
|
|
22
|
+
* **utils**: `mocked` function is deprecated and will be removed in **v28.0.0**. The function has been integrated into `jest-mock` package as a part of Jest **27.4.0**, see https://github.com/facebook/jest/pull/12089. One should use the one from Jest instead
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
1
26
|
## [27.0.7](https://github.com/kulshekhar/ts-jest/compare/v27.0.6...v27.0.7) (2021-10-16)
|
|
2
27
|
|
|
3
28
|
|
package/CONTRIBUTING.md
CHANGED
|
@@ -1,67 +1,120 @@
|
|
|
1
1
|
# Contributing
|
|
2
2
|
|
|
3
|
-
When contributing to this repository, please first discuss the change you wish to make via
|
|
3
|
+
When contributing to this repository, please first discuss the change you wish to make via
|
|
4
|
+
[discussion](https://github.com/kulshekhar/ts-jest/discussions) or [issue](https://github.com/kulshekhar/ts-jest/issues)
|
|
5
|
+
with the owners of this repository before making a change.
|
|
4
6
|
|
|
5
7
|
Please note we have a code of conduct, please follow it in all your interactions with the project.
|
|
6
8
|
|
|
7
|
-
## Pull
|
|
9
|
+
## Workflow and Pull Requests
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
2. Update the `docs/` with details of your changes if required.
|
|
11
|
-
3. If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications.
|
|
12
|
-
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you.
|
|
11
|
+
The team will monitor pull requests. We'll do our best to provide updates and feedback throughout the process.
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
_Before_ submitting a pull request, please make sure the following is done…
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
1. Fork the repo and create your branch from `main`. A guide on how to fork a repository: https://help.github.com/articles/fork-a-repo/
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type:
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
```sh-session
|
|
20
|
+
$ git clone https://github.com/<your_username>/ts-jest
|
|
21
|
+
$ cd ts-jest
|
|
22
|
+
$ git checkout -b my_branch
|
|
23
|
+
```
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
Note: Replace `<your_username>` with your GitHub username
|
|
23
26
|
|
|
24
|
-
-
|
|
25
|
-
- Being respectful of differing viewpoints and experiences
|
|
26
|
-
- Gracefully accepting constructive criticism
|
|
27
|
-
- Focusing on what is best for the community
|
|
28
|
-
- Showing empathy towards other community members
|
|
27
|
+
2. `ts-jest` uses `npm` for running development scripts. If you haven't already done so, please [install npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
3. Make sure you have a compatible version of `node` installed (As of April 14th 2021, `v14.x` is recommended).
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
- Publishing others' private information, such as a physical or electronic address, without explicit permission
|
|
36
|
-
- Other conduct which could reasonably be considered inappropriate in a professional setting
|
|
31
|
+
```sh
|
|
32
|
+
node -v
|
|
33
|
+
```
|
|
37
34
|
|
|
38
|
-
|
|
35
|
+
4. Run `npm ci`. `ts-jest` will automatically build source files into `dist/` after installing dependencies.
|
|
39
36
|
|
|
40
|
-
|
|
37
|
+
5. Ensure the test suite passes via `npm run test`.
|
|
41
38
|
|
|
42
|
-
|
|
39
|
+
### Testing
|
|
43
40
|
|
|
44
|
-
|
|
41
|
+
Code that is written needs to be tested to ensure that it achieves the desired behaviour. Tests either fall into a unit
|
|
42
|
+
test or an integration test.
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
##### Unit tests
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
The unit test files are associated with source files which are in `src/`. If the scope of your work only requires a unit test,
|
|
47
|
+
this is where you will write it in. Tests here usually don't require much if any setup.
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
reported by contacting the project team at kulshekhar@gmail.com. All
|
|
52
|
-
complaints will be reviewed and investigated and will result in a response that
|
|
53
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
|
54
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
55
|
-
Further details of specific enforcement policies may be posted separately.
|
|
49
|
+
##### Integration tests
|
|
56
50
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
There will be situations however where the work you have done cannot be tested alone using unit tests. In situations like this,
|
|
52
|
+
you should write an integration test for your code. The integration tests reside within the `e2e` directory.
|
|
53
|
+
Within this directory, there is a `__tests__` directory. This is where you will write the integration test itself.
|
|
54
|
+
The tests within this directory execute jest itself using `run-jest.ts` and assertions are usually made on one if not all
|
|
55
|
+
the output of the following `status`, `stdout` and `stderr`. The other subdirectories within the `e2e` directory are
|
|
56
|
+
where you will write the files that jest will run for your integration tests. Feel free to take a look at any of the tests
|
|
57
|
+
in the `__tests__` directory within `e2e` to have a better sense of how it is currently being done.
|
|
60
58
|
|
|
61
|
-
|
|
59
|
+
It is possible to run the integration test itself manually to inspect that the new behaviour is indeed correct.
|
|
60
|
+
Here is a small code snippet of how to do just that. This is useful when debugging a failing test.
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
```bash
|
|
63
|
+
$ cd e2e/test-utils
|
|
64
|
+
$ node ../../node_modules/jest/bin/jest.js # It is possible to use node --inspect or ndb
|
|
65
|
+
PASS __tests__/test-utils.spec.ts
|
|
66
|
+
✓ stub (3ms)
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
Test Suites: 1 passed, 1 total
|
|
69
|
+
Tests: 1 passed, 1 total
|
|
70
|
+
Snapshots: 0 total
|
|
71
|
+
Time: 0.232 s, estimated 1 s
|
|
72
|
+
Ran all test suites.
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Additional Workflow for any changes made to website or docs
|
|
76
|
+
|
|
77
|
+
If you are making changes to the website or documentation, test the `website` folder and run the server to check if your
|
|
78
|
+
changes are being displayed accurately.
|
|
79
|
+
|
|
80
|
+
1. Locate to the `website` directory and install any website specific dependencies by typing in `npm ci`.
|
|
81
|
+
2. Following steps are to be followed for this purpose from the root directory.
|
|
82
|
+
```sh-session
|
|
83
|
+
$ cd website # Only needed if you are not already in the website directory
|
|
84
|
+
$ npm ci
|
|
85
|
+
$ npm run start
|
|
86
|
+
```
|
|
87
|
+
3. You can run a development server to check if the changes you made are being displayed accurately by running `npm run start` in the website directory.
|
|
88
|
+
|
|
89
|
+
The `ts-jest` website also offers documentation for older versions of `ts-jest`, which you can edit in `website/versioned_docs`.
|
|
90
|
+
After making changes to the current documentation in `docs`, please check if any older versions of the documentation
|
|
91
|
+
have a copy of the file where the change is also relevant and apply the changes to the `versioned_docs` as well.
|
|
92
|
+
|
|
93
|
+
## Bugs
|
|
94
|
+
|
|
95
|
+
### Where to Find Known Issues
|
|
96
|
+
|
|
97
|
+
We will be using GitHub Issues for our public bugs. We will keep a close eye on this and try to make it clear when we
|
|
98
|
+
have an internal fix in progress. Before filing a new issue, try to make sure your problem doesn't already exist.
|
|
99
|
+
|
|
100
|
+
### Reporting New Issues
|
|
101
|
+
|
|
102
|
+
The best way to get your bug fixed is to provide a reduced test case. Please provide a public repository with a runnable example.
|
|
103
|
+
|
|
104
|
+
## How to Get in Touch
|
|
105
|
+
|
|
106
|
+
[`#testing` on Reactiflux](https://discord.gg/j6FKKQQrW9) or [our GitHub discussion](https://github.com/kulshekhar/ts-jest/discussions)
|
|
107
|
+
|
|
108
|
+
## Code Conventions
|
|
109
|
+
|
|
110
|
+
- 2 spaces for indentation (no tabs).
|
|
111
|
+
- 120 character line length strongly preferred.
|
|
112
|
+
- Prefer `'` over `"`.
|
|
113
|
+
- ES6 syntax when possible.
|
|
114
|
+
- Use [TypeScript](https://www.typescriptlang.org/).
|
|
115
|
+
- No semicolon (`;`) required
|
|
116
|
+
- Trailing commas,
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
By contributing to `ts-jest`, you agree that your contributions will be licensed under its MIT license.
|
package/dist/cli/config/init.js
CHANGED
|
@@ -57,15 +57,15 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
57
57
|
var _b, _c;
|
|
58
58
|
return __generator(this, function (_d) {
|
|
59
59
|
file = (_c = (_b = args._[0]) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : 'jest.config.js';
|
|
60
|
-
filePath = path_1.join(process.cwd(), file);
|
|
61
|
-
name = path_1.basename(file);
|
|
60
|
+
filePath = (0, path_1.join)(process.cwd(), file);
|
|
61
|
+
name = (0, path_1.basename)(file);
|
|
62
62
|
isPackage = name === 'package.json';
|
|
63
|
-
exists = fs_1.existsSync(filePath);
|
|
64
|
-
pkgFile = isPackage ? filePath : path_1.join(process.cwd(), 'package.json');
|
|
65
|
-
hasPackage = isPackage || fs_1.existsSync(pkgFile);
|
|
63
|
+
exists = (0, fs_1.existsSync)(filePath);
|
|
64
|
+
pkgFile = isPackage ? filePath : (0, path_1.join)(process.cwd(), 'package.json');
|
|
65
|
+
hasPackage = isPackage || (0, fs_1.existsSync)(pkgFile);
|
|
66
66
|
_a = args.jestPreset, jestPreset = _a === void 0 ? true : _a, askedTsconfig = args.tsconfig, force = args.force, jsdom = args.jsdom;
|
|
67
67
|
tsconfig = askedTsconfig === 'tsconfig.json' ? undefined : askedTsconfig;
|
|
68
|
-
pkgJson = hasPackage ? JSON.parse(fs_1.readFileSync(pkgFile, 'utf8')) : {};
|
|
68
|
+
pkgJson = hasPackage ? JSON.parse((0, fs_1.readFileSync)(pkgFile, 'utf8')) : {};
|
|
69
69
|
jsFilesProcessor = args.js, shouldPostProcessWithBabel = args.babel;
|
|
70
70
|
if (jsFilesProcessor == null) {
|
|
71
71
|
jsFilesProcessor = shouldPostProcessWithBabel ? 'babel' : undefined;
|
|
@@ -83,21 +83,21 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
83
83
|
preset = presets_1.defaults;
|
|
84
84
|
}
|
|
85
85
|
if (isPackage && !exists) {
|
|
86
|
-
throw new Error("File "
|
|
86
|
+
throw new Error("File ".concat(file, " does not exists."));
|
|
87
87
|
}
|
|
88
88
|
else if (!isPackage && exists && !force) {
|
|
89
|
-
throw new Error("Configuration file "
|
|
89
|
+
throw new Error("Configuration file ".concat(file, " already exists."));
|
|
90
90
|
}
|
|
91
91
|
if (!isPackage && !name.endsWith('.js')) {
|
|
92
|
-
throw new TypeError("Configuration file "
|
|
92
|
+
throw new TypeError("Configuration file ".concat(file, " must be a .js file or the package.json."));
|
|
93
93
|
}
|
|
94
94
|
if (hasPackage && pkgJson.jest) {
|
|
95
95
|
if (force && !isPackage) {
|
|
96
96
|
delete pkgJson.jest;
|
|
97
|
-
fs_1.writeFileSync(pkgFile, JSON.stringify(pkgJson, undefined, ' '));
|
|
97
|
+
(0, fs_1.writeFileSync)(pkgFile, JSON.stringify(pkgJson, undefined, ' '));
|
|
98
98
|
}
|
|
99
99
|
else if (!force) {
|
|
100
|
-
throw new Error("A Jest configuration is already set in "
|
|
100
|
+
throw new Error("A Jest configuration is already set in ".concat(pkgFile, "."));
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
if (isPackage) {
|
|
@@ -117,12 +117,12 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
117
117
|
else {
|
|
118
118
|
content = [];
|
|
119
119
|
if (!jestPreset) {
|
|
120
|
-
content.push(preset.jsImport('tsjPreset')
|
|
120
|
+
content.push("".concat(preset.jsImport('tsjPreset'), ";"), '');
|
|
121
121
|
}
|
|
122
122
|
content.push("/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */");
|
|
123
123
|
content.push('module.exports = {');
|
|
124
124
|
if (jestPreset) {
|
|
125
|
-
content.push(" preset: '"
|
|
125
|
+
content.push(" preset: '".concat(preset.name, "',"));
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
128
|
content.push(' ...tsjPreset,');
|
|
@@ -133,7 +133,7 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
133
133
|
content.push(' globals: {');
|
|
134
134
|
content.push(" 'ts-jest': {");
|
|
135
135
|
if (tsconfig)
|
|
136
|
-
content.push(" tsconfig: "
|
|
136
|
+
content.push(" tsconfig: ".concat((0, json5_1.stringify)(tsconfig), ","));
|
|
137
137
|
if (shouldPostProcessWithBabel)
|
|
138
138
|
content.push(' babelConfig: true,');
|
|
139
139
|
content.push(' },');
|
|
@@ -142,8 +142,8 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
142
142
|
content.push('};');
|
|
143
143
|
body = content.join('\n');
|
|
144
144
|
}
|
|
145
|
-
fs_1.writeFileSync(filePath, body);
|
|
146
|
-
process.stderr.write("\nJest configuration written to \""
|
|
145
|
+
(0, fs_1.writeFileSync)(filePath, body);
|
|
146
|
+
process.stderr.write("\nJest configuration written to \"".concat(filePath, "\".\n"));
|
|
147
147
|
return [2];
|
|
148
148
|
});
|
|
149
149
|
}); };
|
|
@@ -51,10 +51,14 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
51
51
|
}
|
|
52
52
|
return ar;
|
|
53
53
|
};
|
|
54
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
55
|
-
for (var i = 0,
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
+
if (ar || !(i in from)) {
|
|
57
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
+
ar[i] = from[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
58
62
|
};
|
|
59
63
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
60
64
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -72,17 +76,17 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
72
76
|
var nullLogger, file, filePath, footNotes, name, isPackage, actualConfig, migratedConfig, presetName, preset, jsTransformers, jsWithTs, jsWithBabel, presetValue, migratedValue, presetValue, migratedValue, before, after, stringify, prefix;
|
|
73
77
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
74
78
|
return __generator(this, function (_j) {
|
|
75
|
-
nullLogger = bs_logger_1.createLogger({ targets: [] });
|
|
79
|
+
nullLogger = (0, bs_logger_1.createLogger)({ targets: [] });
|
|
76
80
|
file = (_a = args._[0]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
77
|
-
filePath = path_1.resolve(process.cwd(), file);
|
|
81
|
+
filePath = (0, path_1.resolve)(process.cwd(), file);
|
|
78
82
|
footNotes = [];
|
|
79
|
-
if (!fs_1.existsSync(filePath)) {
|
|
80
|
-
throw new Error("Configuration file "
|
|
83
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
84
|
+
throw new Error("Configuration file ".concat(file, " does not exists."));
|
|
81
85
|
}
|
|
82
|
-
name = path_1.basename(file);
|
|
86
|
+
name = (0, path_1.basename)(file);
|
|
83
87
|
isPackage = name === 'package.json';
|
|
84
88
|
if (!/\.(js|json)$/.test(name)) {
|
|
85
|
-
throw new TypeError("Configuration file "
|
|
89
|
+
throw new TypeError("Configuration file ".concat(file, " must be a JavaScript or JSON file."));
|
|
86
90
|
}
|
|
87
91
|
actualConfig = require(filePath);
|
|
88
92
|
if (isPackage) {
|
|
@@ -90,7 +94,7 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
90
94
|
}
|
|
91
95
|
if (!actualConfig)
|
|
92
96
|
actualConfig = {};
|
|
93
|
-
migratedConfig = backports_1.backportJestConfig(nullLogger, actualConfig);
|
|
97
|
+
migratedConfig = (0, backports_1.backportJestConfig)(nullLogger, actualConfig);
|
|
94
98
|
if (!migratedConfig.preset && args.jestPreset) {
|
|
95
99
|
if (args.js) {
|
|
96
100
|
presetName = args.js === 'babel' ? "ts-jest/presets/js-with-babel" : "ts-jest/presets/js-with-ts";
|
|
@@ -103,7 +107,7 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
103
107
|
transformer = 'babel-jest';
|
|
104
108
|
else if (/\ts-jest\b/.test(transformer))
|
|
105
109
|
transformer = 'ts-jest';
|
|
106
|
-
return __spreadArray(__spreadArray([], __read(list)), [transformer]);
|
|
110
|
+
return __spreadArray(__spreadArray([], __read(list), false), [transformer], false);
|
|
107
111
|
}
|
|
108
112
|
return list;
|
|
109
113
|
}, []);
|
|
@@ -121,7 +125,7 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
121
125
|
}
|
|
122
126
|
presetName = presetName !== null && presetName !== void 0 ? presetName : "ts-jest/presets/default";
|
|
123
127
|
preset = presets_1.allPresets[presetName];
|
|
124
|
-
footNotes.push("Detected preset '"
|
|
128
|
+
footNotes.push("Detected preset '".concat(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"));
|
|
125
129
|
}
|
|
126
130
|
else if ((_b = migratedConfig.preset) === null || _b === void 0 ? void 0 : _b.startsWith('ts-jest')) {
|
|
127
131
|
if (args.jestPreset === false) {
|
|
@@ -161,13 +165,13 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
161
165
|
}
|
|
162
166
|
if (preset &&
|
|
163
167
|
migratedConfig.transform &&
|
|
164
|
-
fast_json_stable_stringify_1.default(migratedConfig.transform) === fast_json_stable_stringify_1.default(preset.value.transform)) {
|
|
168
|
+
(0, fast_json_stable_stringify_1.default)(migratedConfig.transform) === (0, fast_json_stable_stringify_1.default)(preset.value.transform)) {
|
|
165
169
|
delete migratedConfig.transform;
|
|
166
170
|
}
|
|
167
171
|
cleanupConfig(actualConfig);
|
|
168
172
|
cleanupConfig(migratedConfig);
|
|
169
|
-
before = fast_json_stable_stringify_1.default(actualConfig);
|
|
170
|
-
after = fast_json_stable_stringify_1.default(migratedConfig);
|
|
173
|
+
before = (0, fast_json_stable_stringify_1.default)(actualConfig);
|
|
174
|
+
after = (0, fast_json_stable_stringify_1.default)(migratedConfig);
|
|
171
175
|
if (after === before) {
|
|
172
176
|
process.stderr.write("\nNo migration needed for given Jest configuration\n ");
|
|
173
177
|
return [2];
|
|
@@ -175,12 +179,12 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
175
179
|
stringify = file.endsWith('.json') ? JSON.stringify : json5_1.stringify;
|
|
176
180
|
prefix = file.endsWith('.json') ? '"jest": ' : 'module.exports = ';
|
|
177
181
|
if (preset && migratedConfig.transform) {
|
|
178
|
-
footNotes.push("\nI couldn't check if your \"transform\" value is the same as mine which is: "
|
|
182
|
+
footNotes.push("\nI couldn't check if your \"transform\" value is the same as mine which is: ".concat(stringify(preset.value.transform, undefined, ' '), "\nIf it is the case, you can safely remove the \"transform\" from what I've migrated.\n"));
|
|
179
183
|
}
|
|
180
184
|
process.stderr.write("\nMigrated Jest configuration:\n");
|
|
181
|
-
process.stdout.write(""
|
|
185
|
+
process.stdout.write("".concat(prefix).concat(stringify(migratedConfig, undefined, ' '), "\n"));
|
|
182
186
|
if (footNotes.length) {
|
|
183
|
-
process.stderr.write("\n"
|
|
187
|
+
process.stderr.write("\n".concat(footNotes.join('\n'), "\n"));
|
|
184
188
|
}
|
|
185
189
|
return [2];
|
|
186
190
|
});
|
|
@@ -19,11 +19,11 @@ var definePreset = function (fullName) { return ({
|
|
|
19
19
|
.replace(/\-([a-z])/g, function (_, l) { return l.toUpperCase(); });
|
|
20
20
|
},
|
|
21
21
|
get value() {
|
|
22
|
-
return require("../../../"
|
|
22
|
+
return require("../../../".concat(fullName.replace(/^ts-jest\//, ''), "/jest-preset"));
|
|
23
23
|
},
|
|
24
24
|
jsImport: function (varName) {
|
|
25
25
|
if (varName === void 0) { varName = 'tsjPreset'; }
|
|
26
|
-
return "const { "
|
|
26
|
+
return "const { ".concat(this.jsVarName, ": ").concat(varName, " } = require('ts-jest/presets')");
|
|
27
27
|
},
|
|
28
28
|
get isDefault() {
|
|
29
29
|
return fullName === "ts-jest/presets/default";
|
package/dist/cli/index.js
CHANGED
|
@@ -43,14 +43,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
43
43
|
exports.processArgv = void 0;
|
|
44
44
|
var bs_logger_1 = require("bs-logger");
|
|
45
45
|
var yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
46
|
-
var
|
|
46
|
+
var utils_1 = require("../utils");
|
|
47
47
|
var VALID_COMMANDS = ['help', 'config:migrate', 'config:init'];
|
|
48
|
-
var logger =
|
|
48
|
+
var logger = utils_1.rootLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'cli', _a[bs_logger_1.LogContexts.application] = 'ts-jest', _a));
|
|
49
49
|
function cli(args) {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function () {
|
|
51
51
|
var parsedArgv, command, isHelp, _a, run, help, cmd;
|
|
52
52
|
return __generator(this, function (_b) {
|
|
53
|
-
parsedArgv = yargs_parser_1.default(args, {
|
|
53
|
+
parsedArgv = (0, yargs_parser_1.default)(args, {
|
|
54
54
|
boolean: ['dry-run', 'jest-preset', 'allow-js', 'diff', 'babel', 'force', 'jsdom'],
|
|
55
55
|
string: ['tsconfig', 'js'],
|
|
56
56
|
count: ['verbose'],
|
|
@@ -60,7 +60,7 @@ function cli(args) {
|
|
|
60
60
|
js: function (val) {
|
|
61
61
|
var res = val.trim().toLowerCase();
|
|
62
62
|
if (!['babel', 'ts'].includes(res))
|
|
63
|
-
throw new Error("The 'js' option must be 'babel' or 'ts', given: '"
|
|
63
|
+
throw new Error("The 'js' option must be 'babel' or 'ts', given: '".concat(val, "'."));
|
|
64
64
|
return res;
|
|
65
65
|
},
|
|
66
66
|
},
|
|
@@ -76,12 +76,17 @@ function cli(args) {
|
|
|
76
76
|
command = parsedArgv._.shift();
|
|
77
77
|
if (!VALID_COMMANDS.includes(command))
|
|
78
78
|
command = 'help';
|
|
79
|
-
_a = require("./"
|
|
79
|
+
_a = require("./".concat(command.replace(/:/g, '/'))), run = _a.run, help = _a.help;
|
|
80
80
|
cmd = isHelp && command !== 'help' ? help : run;
|
|
81
81
|
return [2, cmd(parsedArgv, logger)];
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
+
var errorHasMessage = function (err) {
|
|
86
|
+
if (typeof err !== 'object' || err === null)
|
|
87
|
+
return false;
|
|
88
|
+
return 'message' in err;
|
|
89
|
+
};
|
|
85
90
|
function processArgv() {
|
|
86
91
|
return __awaiter(this, void 0, void 0, function () {
|
|
87
92
|
var err_1;
|
|
@@ -96,8 +101,10 @@ function processArgv() {
|
|
|
96
101
|
return [3, 3];
|
|
97
102
|
case 2:
|
|
98
103
|
err_1 = _a.sent();
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
if (errorHasMessage(err_1)) {
|
|
105
|
+
logger.fatal(err_1.message);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
101
108
|
return [3, 3];
|
|
102
109
|
case 3: return [2];
|
|
103
110
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateOutput = exports.SOURCE_MAPPING_PREFIX = void 0;
|
|
4
|
-
var
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
5
|
exports.SOURCE_MAPPING_PREFIX = 'sourceMappingURL=';
|
|
6
6
|
function updateOutput(outputText, normalizedFileName, sourceMap) {
|
|
7
7
|
if (sourceMap) {
|
|
8
8
|
var base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64');
|
|
9
|
-
var sourceMapContent = "data:application/json;charset=utf-8;base64,"
|
|
9
|
+
var sourceMapContent = "data:application/json;charset=utf-8;base64,".concat(base64Map);
|
|
10
10
|
return (outputText.slice(0, outputText.lastIndexOf(exports.SOURCE_MAPPING_PREFIX) + exports.SOURCE_MAPPING_PREFIX.length) +
|
|
11
11
|
sourceMapContent);
|
|
12
12
|
}
|
|
@@ -20,5 +20,5 @@ var updateSourceMap = function (sourceMapText, normalizedFileName) {
|
|
|
20
20
|
sourceMap.file = normalizedFileName;
|
|
21
21
|
sourceMap.sources = [normalizedFileName];
|
|
22
22
|
delete sourceMap.sourceRoot;
|
|
23
|
-
return
|
|
23
|
+
return (0, utils_1.stringify)(sourceMap);
|
|
24
24
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./compiler-utils"), exports);
|
|
14
|
+
__exportStar(require("./ts-compiler"), exports);
|
|
15
|
+
__exportStar(require("./ts-jest-compiler"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Logger } from 'bs-logger';
|
|
2
2
|
import type { TranspileOutput, CompilerOptions, Program, CustomTransformers } from 'typescript';
|
|
3
|
-
import type { ConfigSet } from '../config
|
|
3
|
+
import type { ConfigSet } from '../config';
|
|
4
4
|
import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript } from '../types';
|
|
5
5
|
export declare class TsCompiler implements TsCompilerInstance {
|
|
6
6
|
readonly configSet: ConfigSet;
|