@depup/ts-jest 29.4.6-depup.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/.lintstagedrc +4 -0
- package/.ts-jest-digest +1 -0
- package/CHANGELOG.md +2025 -0
- package/CONTRIBUTING.md +121 -0
- package/LICENSE.md +21 -0
- package/README.md +33 -0
- package/TROUBLESHOOTING.md +3 -0
- package/changes.json +18 -0
- package/cli.js +3 -0
- package/dist/cli/config/init.d.ts +6 -0
- package/dist/cli/config/init.js +139 -0
- package/dist/cli/config/migrate.d.ts +1 -0
- package/dist/cli/config/migrate.js +177 -0
- package/dist/cli/help.d.ts +1 -0
- package/dist/cli/help.js +25 -0
- package/dist/cli/helpers/presets.d.ts +1 -0
- package/dist/cli/helpers/presets.js +41 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +63 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +18 -0
- package/dist/config/paths-to-module-name-mapper.d.ts +9 -0
- package/dist/config/paths-to-module-name-mapper.js +52 -0
- package/dist/config/types.d.ts +2 -0
- package/dist/config/types.js +2 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +22 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +31 -0
- package/dist/legacy/compiler/compiler-utils.d.ts +8 -0
- package/dist/legacy/compiler/compiler-utils.js +32 -0
- package/dist/legacy/compiler/index.d.ts +2 -0
- package/dist/legacy/compiler/index.js +18 -0
- package/dist/legacy/compiler/ts-compiler.d.ts +27 -0
- package/dist/legacy/compiler/ts-compiler.js +434 -0
- package/dist/legacy/compiler/ts-jest-compiler.d.ts +8 -0
- package/dist/legacy/compiler/ts-jest-compiler.js +18 -0
- package/dist/legacy/config/config-set.d.ts +36 -0
- package/dist/legacy/config/config-set.js +622 -0
- package/dist/legacy/index.d.ts +6 -0
- package/dist/legacy/index.js +6 -0
- package/dist/legacy/ts-jest-transformer.d.ts +28 -0
- package/dist/legacy/ts-jest-transformer.js +293 -0
- package/dist/presets/all-presets.d.ts +15 -0
- package/dist/presets/all-presets.js +42 -0
- package/dist/presets/create-jest-preset.d.ts +18 -0
- package/dist/presets/create-jest-preset.js +180 -0
- package/dist/raw-compiler-options.d.ts +556 -0
- package/dist/raw-compiler-options.js +2 -0
- package/dist/transformers/hoist-jest.d.ts +9 -0
- package/dist/transformers/hoist-jest.js +111 -0
- package/dist/transpilers/typescript/transpile-module.d.ts +8 -0
- package/dist/transpilers/typescript/transpile-module.js +174 -0
- package/dist/types.d.ts +282 -0
- package/dist/types.js +3 -0
- package/dist/utils/backports.d.ts +1 -0
- package/dist/utils/backports.js +118 -0
- package/dist/utils/diagnostics.d.ts +5 -0
- package/dist/utils/diagnostics.js +8 -0
- package/dist/utils/get-package-version.d.ts +1 -0
- package/dist/utils/get-package-version.js +14 -0
- package/dist/utils/importer.d.ts +1 -0
- package/dist/utils/importer.js +146 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/json.js +16 -0
- package/dist/utils/jsonable-value.d.ts +10 -0
- package/dist/utils/jsonable-value.js +29 -0
- package/dist/utils/logger.d.ts +1 -0
- package/dist/utils/logger.js +20 -0
- package/dist/utils/memoize.d.ts +1 -0
- package/dist/utils/memoize.js +60 -0
- package/dist/utils/messages.d.ts +1 -0
- package/dist/utils/messages.js +21 -0
- package/dist/utils/normalize-slashes.d.ts +1 -0
- package/dist/utils/normalize-slashes.js +9 -0
- package/dist/utils/sha1.d.ts +1 -0
- package/dist/utils/sha1.js +38 -0
- package/dist/utils/ts-error.d.ts +1 -0
- package/dist/utils/ts-error.js +37 -0
- package/jest-preset.js +1 -0
- package/legacy.js +1 -0
- package/package.json +167 -0
- package/preprocessor.js +7 -0
- package/presets/default/jest-preset.js +1 -0
- package/presets/default-esm/jest-preset.js +1 -0
- package/presets/default-esm-legacy/jest-preset.js +1 -0
- package/presets/default-legacy/jest-preset.js +1 -0
- package/presets/index.d.ts +3 -0
- package/presets/index.js +3 -0
- package/presets/js-with-babel/jest-preset.js +1 -0
- package/presets/js-with-babel-esm/jest-preset.js +1 -0
- package/presets/js-with-babel-esm-legacy/jest-preset.js +1 -0
- package/presets/js-with-babel-legacy/jest-preset.js +1 -0
- package/presets/js-with-ts/jest-preset.js +1 -0
- package/presets/js-with-ts-esm/jest-preset.js +1 -0
- package/presets/js-with-ts-esm-legacy/jest-preset.js +1 -0
- package/presets/js-with-ts-legacy/jest-preset.js +1 -0
- package/tsconfig.base.json +20 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
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.
|
|
6
|
+
|
|
7
|
+
Please note we have a code of conduct, please follow it in all your interactions with the project.
|
|
8
|
+
|
|
9
|
+
## Workflow and Pull Requests
|
|
10
|
+
|
|
11
|
+
The team will monitor pull requests. We'll do our best to provide updates and feedback throughout the process.
|
|
12
|
+
|
|
13
|
+
_Before_ submitting a pull request, please make sure the following is done…
|
|
14
|
+
|
|
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/
|
|
16
|
+
|
|
17
|
+
Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type:
|
|
18
|
+
|
|
19
|
+
```sh-session
|
|
20
|
+
$ git clone https://github.com/<your_username>/ts-jest
|
|
21
|
+
$ cd ts-jest
|
|
22
|
+
$ git checkout -b my_branch
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Note: Replace `<your_username>` with your GitHub username
|
|
26
|
+
|
|
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).
|
|
28
|
+
|
|
29
|
+
3. Make sure you have a compatible version of `node` installed (As of April 14th 2021, `v14.x` is recommended).
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
node -v
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
4. Run `npm ci`. `ts-jest` will automatically build source files into `dist/` after installing dependencies.
|
|
36
|
+
|
|
37
|
+
5. Ensure the test suite passes via `npm run test`.
|
|
38
|
+
|
|
39
|
+
### Testing
|
|
40
|
+
|
|
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.
|
|
43
|
+
|
|
44
|
+
##### Unit tests
|
|
45
|
+
|
|
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.
|
|
48
|
+
|
|
49
|
+
##### Integration tests
|
|
50
|
+
|
|
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.
|
|
58
|
+
|
|
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.
|
|
61
|
+
|
|
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)
|
|
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 lint-prettier # Please format markdown files
|
|
86
|
+
$ npm run start
|
|
87
|
+
```
|
|
88
|
+
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.
|
|
89
|
+
|
|
90
|
+
The `ts-jest` website also offers documentation for older versions of `ts-jest`, which you can edit in `website/versioned_docs`.
|
|
91
|
+
After making changes to the current documentation in `docs`, please check if any older versions of the documentation
|
|
92
|
+
have a copy of the file where the change is also relevant and apply the changes to the `versioned_docs` as well.
|
|
93
|
+
|
|
94
|
+
## Bugs
|
|
95
|
+
|
|
96
|
+
### Where to Find Known Issues
|
|
97
|
+
|
|
98
|
+
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
|
|
99
|
+
have an internal fix in progress. Before filing a new issue, try to make sure your problem doesn't already exist.
|
|
100
|
+
|
|
101
|
+
### Reporting New Issues
|
|
102
|
+
|
|
103
|
+
The best way to get your bug fixed is to provide a reduced test case. Please provide a public repository with a runnable example.
|
|
104
|
+
|
|
105
|
+
## How to Get in Touch
|
|
106
|
+
|
|
107
|
+
[`#testing` on Reactiflux](https://discord.gg/j6FKKQQrW9) or [our GitHub discussion](https://github.com/kulshekhar/ts-jest/discussions)
|
|
108
|
+
|
|
109
|
+
## Code Conventions
|
|
110
|
+
|
|
111
|
+
- 2 spaces for indentation (no tabs).
|
|
112
|
+
- 120 character line length strongly preferred.
|
|
113
|
+
- Prefer `'` over `"`.
|
|
114
|
+
- ES6 syntax when possible.
|
|
115
|
+
- Use [TypeScript](https://www.typescriptlang.org/).
|
|
116
|
+
- No semicolon (`;`) required
|
|
117
|
+
- Trailing commas,
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
By contributing to `ts-jest`, you agree that your contributions will be licensed under its MIT license.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @depup/ts-jest
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [ts-jest](https://www.npmjs.com/package/ts-jest)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/ts-jest
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [ts-jest](https://www.npmjs.com/package/ts-jest) @ 29.4.6 |
|
|
17
|
+
| Processed | 2026-03-17 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 3 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| semver | ^7.7.3 | ^7.7.4 |
|
|
26
|
+
| type-fest | ^4.41.0 | ^5.4.4 |
|
|
27
|
+
| yargs-parser | ^21.1.1 | ^22.0.0 |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/ts-jest
|
|
32
|
+
|
|
33
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bumped": {
|
|
3
|
+
"semver": {
|
|
4
|
+
"from": "^7.7.3",
|
|
5
|
+
"to": "^7.7.4"
|
|
6
|
+
},
|
|
7
|
+
"type-fest": {
|
|
8
|
+
"from": "^4.41.0",
|
|
9
|
+
"to": "^5.4.4"
|
|
10
|
+
},
|
|
11
|
+
"yargs-parser": {
|
|
12
|
+
"from": "^21.1.1",
|
|
13
|
+
"to": "^22.0.0"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"timestamp": "2026-03-17T16:39:33.271Z",
|
|
17
|
+
"totalUpdated": 3
|
|
18
|
+
}
|
package/cli.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This has been written quickly. While trying to improve I realised it'd be better to have it in Jest...
|
|
4
|
+
* ...and I saw a merged PR with `jest --init` tool!
|
|
5
|
+
* TODO: see what's the best path for this
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.help = exports.run = void 0;
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
15
|
+
const json5_1 = require("json5");
|
|
16
|
+
const create_jest_preset_1 = require("../../presets/create-jest-preset");
|
|
17
|
+
const JEST_CONFIG_TEMPLATE = `const { {{ presetCreatorFn }} } = require("ts-jest");
|
|
18
|
+
|
|
19
|
+
const tsJestTransformCfg = {{ presetCreatorFn }}({{{ transformOpts }}}).transform;
|
|
20
|
+
|
|
21
|
+
/** @type {import("jest").Config} **/
|
|
22
|
+
{{{ exportKind }}} {
|
|
23
|
+
testEnvironment: "{{ testEnvironment }}",
|
|
24
|
+
transform: {
|
|
25
|
+
...tsJestTransformCfg,
|
|
26
|
+
},
|
|
27
|
+
};`;
|
|
28
|
+
const ensureOnlyUsingDoubleQuotes = (str) => {
|
|
29
|
+
return str
|
|
30
|
+
.replace(/"'(.*?)'"/g, '"$1"')
|
|
31
|
+
.replace(/'ts-jest'/g, '"ts-jest"')
|
|
32
|
+
.replace(/'babel-jest'/g, '"babel-jest"');
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
const run = async (args /* , logger: Logger */) => {
|
|
38
|
+
const { tsconfig: askedTsconfig, force, jsdom, js: jsFilesProcessor, babel: shouldPostProcessWithBabel } = args;
|
|
39
|
+
const file = args._[0]?.toString() ?? 'jest.config.js';
|
|
40
|
+
const filePath = (0, path_1.join)(process.cwd(), file);
|
|
41
|
+
const name = (0, path_1.basename)(file);
|
|
42
|
+
const isPackageJsonConfig = name === 'package.json';
|
|
43
|
+
const isJestConfigFileExisted = (0, fs_1.existsSync)(filePath);
|
|
44
|
+
const pkgFile = isPackageJsonConfig ? filePath : (0, path_1.join)(process.cwd(), 'package.json');
|
|
45
|
+
const isPackageJsonExisted = isPackageJsonConfig || (0, fs_1.existsSync)(pkgFile);
|
|
46
|
+
const tsconfig = askedTsconfig === 'tsconfig.json' ? undefined : askedTsconfig;
|
|
47
|
+
const pkgJsonContent = isPackageJsonExisted ? JSON.parse((0, fs_1.readFileSync)(pkgFile, 'utf8')) : {};
|
|
48
|
+
if (shouldPostProcessWithBabel) {
|
|
49
|
+
console.warn(`The option --babel is deprecated and will be removed in the next major version.` +
|
|
50
|
+
` Please specify 'js' option value (see more with npx ts-jest help) if you wish 'ts-jest' to process 'js' with TypeScript API or Babel.`);
|
|
51
|
+
}
|
|
52
|
+
if (isPackageJsonConfig && !isJestConfigFileExisted) {
|
|
53
|
+
throw new Error(`File ${file} does not exists.`);
|
|
54
|
+
}
|
|
55
|
+
else if (!isPackageJsonConfig && isJestConfigFileExisted && !force) {
|
|
56
|
+
throw new Error(`Configuration file ${file} already exists.`);
|
|
57
|
+
}
|
|
58
|
+
if (!isPackageJsonConfig && !name.endsWith('.js')) {
|
|
59
|
+
throw new TypeError(`Configuration file ${file} must be a .js file or the package.json.`);
|
|
60
|
+
}
|
|
61
|
+
if (isPackageJsonExisted && pkgJsonContent.jest) {
|
|
62
|
+
if (force && !isPackageJsonConfig) {
|
|
63
|
+
delete pkgJsonContent.jest;
|
|
64
|
+
(0, fs_1.writeFileSync)(pkgFile, JSON.stringify(pkgJsonContent, undefined, ' '));
|
|
65
|
+
}
|
|
66
|
+
else if (!force) {
|
|
67
|
+
throw new Error(`A Jest configuration is already set in ${pkgFile}.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
let body;
|
|
71
|
+
const transformOpts = tsconfig
|
|
72
|
+
? { tsconfig: `${(0, json5_1.stringify)(tsconfig)}` }
|
|
73
|
+
: undefined;
|
|
74
|
+
let transformConfig;
|
|
75
|
+
if (isPackageJsonConfig) {
|
|
76
|
+
if (jsFilesProcessor === 'babel' || shouldPostProcessWithBabel) {
|
|
77
|
+
transformConfig = (0, create_jest_preset_1.createJsWithBabelPreset)(transformOpts);
|
|
78
|
+
}
|
|
79
|
+
else if (jsFilesProcessor === 'ts') {
|
|
80
|
+
transformConfig = (0, create_jest_preset_1.createJsWithTsPreset)(transformOpts);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
transformConfig = (0, create_jest_preset_1.createDefaultPreset)(transformOpts);
|
|
84
|
+
}
|
|
85
|
+
body = ensureOnlyUsingDoubleQuotes(JSON.stringify({
|
|
86
|
+
...pkgJsonContent,
|
|
87
|
+
jest: transformConfig,
|
|
88
|
+
}, undefined, ' '));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
let presetCreatorFn;
|
|
92
|
+
if (jsFilesProcessor === 'babel' || shouldPostProcessWithBabel) {
|
|
93
|
+
presetCreatorFn = 'createJsWithBabelPreset';
|
|
94
|
+
}
|
|
95
|
+
else if (jsFilesProcessor === 'ts') {
|
|
96
|
+
presetCreatorFn = 'createJsWithTsPreset';
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
presetCreatorFn = 'createDefaultPreset';
|
|
100
|
+
}
|
|
101
|
+
const template = handlebars_1.default.compile(JEST_CONFIG_TEMPLATE);
|
|
102
|
+
body = template({
|
|
103
|
+
exportKind: pkgJsonContent.type === 'module' ? 'export default' : 'module.exports =',
|
|
104
|
+
testEnvironment: jsdom ? 'jsdom' : 'node',
|
|
105
|
+
presetCreatorFn,
|
|
106
|
+
transformOpts: transformOpts ? ensureOnlyUsingDoubleQuotes(JSON.stringify(transformOpts, null, 2)) : undefined,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
(0, fs_1.writeFileSync)(filePath, body);
|
|
110
|
+
process.stderr.write(`
|
|
111
|
+
Jest configuration written to "${filePath}".
|
|
112
|
+
`);
|
|
113
|
+
};
|
|
114
|
+
exports.run = run;
|
|
115
|
+
/**
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
const help = async () => {
|
|
119
|
+
process.stdout.write(`
|
|
120
|
+
Usage:
|
|
121
|
+
ts-jest config:init [options] [<config-file>]
|
|
122
|
+
|
|
123
|
+
Arguments:
|
|
124
|
+
<config-file> Can be a js or json Jest config file. If it is a
|
|
125
|
+
package.json file, the configuration will be read from
|
|
126
|
+
the "jest" property.
|
|
127
|
+
Default: jest.config.js
|
|
128
|
+
|
|
129
|
+
Options:
|
|
130
|
+
--force Discard any existing Jest config
|
|
131
|
+
--js ts|babel Process '.js' files with ts-jest if 'ts' or with
|
|
132
|
+
babel-jest if 'babel'
|
|
133
|
+
--no-jest-preset Disable the use of Jest presets
|
|
134
|
+
--tsconfig <file> Path to the tsconfig.json file
|
|
135
|
+
--babel Enable using Babel to process 'js' resulted content from 'ts-jest' processing
|
|
136
|
+
--jsdom Use 'jsdom' as test environment instead of 'node'
|
|
137
|
+
`);
|
|
138
|
+
};
|
|
139
|
+
exports.help = help;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
exports.help = exports.run = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const bs_logger_1 = require("bs-logger");
|
|
10
|
+
const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
|
|
11
|
+
const json5_1 = require("json5");
|
|
12
|
+
const create_jest_preset_1 = require("../../presets/create-jest-preset");
|
|
13
|
+
const backports_1 = require("../../utils/backports");
|
|
14
|
+
const presets_1 = require("../helpers/presets");
|
|
15
|
+
const migrateGlobalConfigToTransformConfig = (transformConfig, globalsTsJestConfig) => {
|
|
16
|
+
if (transformConfig) {
|
|
17
|
+
return Object.entries(transformConfig).reduce((previousValue, currentValue) => {
|
|
18
|
+
const [key, transformOptions] = currentValue;
|
|
19
|
+
if (typeof transformOptions === 'string' && transformOptions.includes('ts-jest')) {
|
|
20
|
+
return {
|
|
21
|
+
...previousValue,
|
|
22
|
+
[key]: globalsTsJestConfig ? ['ts-jest', globalsTsJestConfig] : 'ts-jest',
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
...previousValue,
|
|
27
|
+
[key]: transformOptions,
|
|
28
|
+
};
|
|
29
|
+
}, {});
|
|
30
|
+
}
|
|
31
|
+
return {};
|
|
32
|
+
};
|
|
33
|
+
const migratePresetToTransformConfig = (transformConfig, preset, globalsTsJestConfig) => {
|
|
34
|
+
if (preset) {
|
|
35
|
+
const transformConfigFromPreset = preset.name === "ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */
|
|
36
|
+
? (0, create_jest_preset_1.createJsWithTsPreset)(globalsTsJestConfig)
|
|
37
|
+
: preset.name === "ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */
|
|
38
|
+
? (0, create_jest_preset_1.createJsWithBabelPreset)(globalsTsJestConfig)
|
|
39
|
+
: (0, create_jest_preset_1.createDefaultPreset)(globalsTsJestConfig);
|
|
40
|
+
return {
|
|
41
|
+
...transformConfig,
|
|
42
|
+
...transformConfigFromPreset.transform,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return transformConfig;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
const run = async (args /* , logger: Logger*/) => {
|
|
51
|
+
const nullLogger = (0, bs_logger_1.createLogger)({ targets: [] });
|
|
52
|
+
const file = args._[0]?.toString();
|
|
53
|
+
const filePath = (0, path_1.resolve)(process.cwd(), file);
|
|
54
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
55
|
+
throw new Error(`Configuration file ${file} does not exists.`);
|
|
56
|
+
}
|
|
57
|
+
const name = (0, path_1.basename)(file);
|
|
58
|
+
const isPackage = name === 'package.json';
|
|
59
|
+
if (!/\.(js|json)$/.test(name)) {
|
|
60
|
+
throw new TypeError(`Configuration file ${file} must be a JavaScript or JSON file.`);
|
|
61
|
+
}
|
|
62
|
+
let actualConfig = require(filePath);
|
|
63
|
+
if (isPackage) {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
actualConfig = actualConfig.jest;
|
|
66
|
+
}
|
|
67
|
+
if (!actualConfig)
|
|
68
|
+
actualConfig = {};
|
|
69
|
+
// migrate
|
|
70
|
+
// first we backport our options
|
|
71
|
+
const migratedConfig = (0, backports_1.backportJestConfig)(nullLogger, actualConfig);
|
|
72
|
+
let preset;
|
|
73
|
+
if (migratedConfig.preset) {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
preset = presets_1.allPresets[migratedConfig.preset] ?? presets_1.allPresets["ts-jest/presets/default" /* JestPresetNames.default */];
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (args.js) {
|
|
79
|
+
preset = args.js === 'babel' ? presets_1.allPresets["ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */] : presets_1.allPresets["ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */];
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
preset = presets_1.allPresets["ts-jest/presets/default" /* JestPresetNames.default */];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// check the extensions
|
|
86
|
+
if (migratedConfig.moduleFileExtensions?.length && preset) {
|
|
87
|
+
const presetValue = dedupSort(preset.value.moduleFileExtensions ?? []).join('::');
|
|
88
|
+
const migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::');
|
|
89
|
+
if (presetValue === migratedValue) {
|
|
90
|
+
delete migratedConfig.moduleFileExtensions;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// there is a testRegex, remove our testMatch
|
|
94
|
+
if (typeof migratedConfig.testRegex === 'string' || migratedConfig.testRegex?.length) {
|
|
95
|
+
delete migratedConfig.testMatch;
|
|
96
|
+
}
|
|
97
|
+
// check the testMatch
|
|
98
|
+
else if (migratedConfig.testMatch?.length &&
|
|
99
|
+
preset &&
|
|
100
|
+
Array.isArray(preset.value.testMatch) &&
|
|
101
|
+
Array.isArray(migratedConfig.testMatch)) {
|
|
102
|
+
const presetValue = dedupSort(preset.value.testMatch).join('::');
|
|
103
|
+
const migratedValue = dedupSort(migratedConfig.testMatch).join('::');
|
|
104
|
+
if (presetValue === migratedValue) {
|
|
105
|
+
delete migratedConfig.testMatch;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const globalsTsJestConfig = migratedConfig.globals?.['ts-jest'];
|
|
109
|
+
migratedConfig.transform = migrateGlobalConfigToTransformConfig(migratedConfig.transform, globalsTsJestConfig);
|
|
110
|
+
migratedConfig.transform = migratePresetToTransformConfig(migratedConfig.transform, preset, globalsTsJestConfig);
|
|
111
|
+
cleanupConfig(actualConfig);
|
|
112
|
+
cleanupConfig(migratedConfig);
|
|
113
|
+
const before = (0, fast_json_stable_stringify_1.default)(actualConfig);
|
|
114
|
+
const after = (0, fast_json_stable_stringify_1.default)(migratedConfig);
|
|
115
|
+
if (after === before) {
|
|
116
|
+
process.stderr.write(`
|
|
117
|
+
No migration needed for given Jest configuration
|
|
118
|
+
`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const stringify = file.endsWith('.json') ? JSON.stringify : json5_1.stringify;
|
|
122
|
+
const prefix = file.endsWith('.json') ? '"jest": ' : 'module.exports = ';
|
|
123
|
+
// output new config
|
|
124
|
+
process.stderr.write(`
|
|
125
|
+
Migrated Jest configuration:
|
|
126
|
+
`);
|
|
127
|
+
process.stdout.write(`${prefix}${stringify(migratedConfig, undefined, ' ')}\n`);
|
|
128
|
+
};
|
|
129
|
+
exports.run = run;
|
|
130
|
+
function cleanupConfig(config) {
|
|
131
|
+
if (config.globals) {
|
|
132
|
+
delete config.globals['ts-jest'];
|
|
133
|
+
if (!Object.keys(config.globals).length) {
|
|
134
|
+
delete config.globals;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (config.transform && !Object.keys(config.transform).length) {
|
|
138
|
+
delete config.transform;
|
|
139
|
+
}
|
|
140
|
+
if (config.moduleFileExtensions) {
|
|
141
|
+
config.moduleFileExtensions = dedupSort(config.moduleFileExtensions);
|
|
142
|
+
if (!config.moduleFileExtensions.length)
|
|
143
|
+
delete config.moduleFileExtensions;
|
|
144
|
+
}
|
|
145
|
+
if (config.testMatch && Array.isArray(config.testMatch)) {
|
|
146
|
+
config.testMatch = dedupSort(config.testMatch);
|
|
147
|
+
if (!config.testMatch.length)
|
|
148
|
+
delete config.testMatch;
|
|
149
|
+
}
|
|
150
|
+
delete config.preset;
|
|
151
|
+
}
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
153
|
+
function dedupSort(arr) {
|
|
154
|
+
return arr
|
|
155
|
+
.filter((s, i, a) => a.findIndex((e) => s.toString() === e.toString()) === i)
|
|
156
|
+
.sort((a, b) => (a.toString() > b.toString() ? 1 : a.toString() < b.toString() ? -1 : 0));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
const help = async () => {
|
|
162
|
+
process.stdout.write(`
|
|
163
|
+
Usage:
|
|
164
|
+
ts-jest config:migrate [options] <config-file>
|
|
165
|
+
|
|
166
|
+
Arguments:
|
|
167
|
+
<config-file> Can be a js or json Jest config file. If it is a
|
|
168
|
+
package.json file, the configuration will be read from
|
|
169
|
+
the "jest" property.
|
|
170
|
+
|
|
171
|
+
Options:
|
|
172
|
+
--js ts|babel Process .js files with ts-jest if 'ts' or with
|
|
173
|
+
babel-jest if 'babel'
|
|
174
|
+
--no-jest-preset Disable the use of Jest presets
|
|
175
|
+
`);
|
|
176
|
+
};
|
|
177
|
+
exports.help = help;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli/help.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.help = exports.run = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
const run = async (_) => {
|
|
8
|
+
process.stdout.write(`
|
|
9
|
+
Usage:
|
|
10
|
+
ts-jest command [options] [...args]
|
|
11
|
+
|
|
12
|
+
Commands:
|
|
13
|
+
config:init Creates initial Jest configuration
|
|
14
|
+
config:migrate Migrates a given Jest configuration
|
|
15
|
+
help [command] Show this help, or help about a command
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
ts-jest help config:migrate
|
|
19
|
+
`);
|
|
20
|
+
};
|
|
21
|
+
exports.run = run;
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
exports.help = exports.run;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsWIthBabel = exports.jsWithTs = exports.defaults = exports.allPresets = void 0;
|
|
4
|
+
const definePreset = (fullName) => ({
|
|
5
|
+
fullName,
|
|
6
|
+
get name() {
|
|
7
|
+
return this.isDefault ? 'ts-jest' : fullName;
|
|
8
|
+
},
|
|
9
|
+
get label() {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
11
|
+
return fullName.split('/').pop();
|
|
12
|
+
},
|
|
13
|
+
get jsVarName() {
|
|
14
|
+
return this.isDefault
|
|
15
|
+
? 'defaults'
|
|
16
|
+
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17
|
+
fullName
|
|
18
|
+
.split('/')
|
|
19
|
+
.pop()
|
|
20
|
+
// eslint-disable-next-line no-useless-escape
|
|
21
|
+
.replace(/\-([a-z])/g, (_, l) => l.toUpperCase());
|
|
22
|
+
},
|
|
23
|
+
get value() {
|
|
24
|
+
return require(`../../../${fullName.replace(/^ts-jest\//, '')}/jest-preset`);
|
|
25
|
+
},
|
|
26
|
+
jsImport(varName = 'tsjPreset') {
|
|
27
|
+
return `const { ${this.jsVarName}: ${varName} } = require('ts-jest/presets')`;
|
|
28
|
+
},
|
|
29
|
+
get isDefault() {
|
|
30
|
+
return fullName === "ts-jest/presets/default" /* JestPresetNames.default */;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
/** @internal */
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
exports.allPresets = {};
|
|
36
|
+
/** @internal */
|
|
37
|
+
exports.defaults = (exports.allPresets["ts-jest/presets/default" /* JestPresetNames.default */] = definePreset("ts-jest/presets/default" /* JestPresetNames.default */));
|
|
38
|
+
/** @internal */
|
|
39
|
+
exports.jsWithTs = (exports.allPresets["ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */] = definePreset("ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */));
|
|
40
|
+
/** @internal */
|
|
41
|
+
exports.jsWIthBabel = (exports.allPresets["ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */] = definePreset("ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
exports.processArgv = processArgv;
|
|
7
|
+
const bs_logger_1 = require("bs-logger");
|
|
8
|
+
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const VALID_COMMANDS = ['help', 'config:migrate', 'config:init'];
|
|
11
|
+
const logger = utils_1.rootLogger.child({ [bs_logger_1.LogContexts.namespace]: 'cli', [bs_logger_1.LogContexts.application]: 'ts-jest' });
|
|
12
|
+
async function cli(args) {
|
|
13
|
+
const parsedArgv = (0, yargs_parser_1.default)(args, {
|
|
14
|
+
boolean: ['dry-run', 'jest-preset', 'allow-js', 'diff', 'babel', 'force', 'jsdom'],
|
|
15
|
+
string: ['tsconfig', 'js'],
|
|
16
|
+
count: ['verbose'],
|
|
17
|
+
alias: { verbose: ['v'] },
|
|
18
|
+
default: { jestPreset: true, verbose: 0 },
|
|
19
|
+
coerce: {
|
|
20
|
+
js(val) {
|
|
21
|
+
const res = val.trim().toLowerCase();
|
|
22
|
+
if (!['babel', 'ts'].includes(res))
|
|
23
|
+
throw new Error(`The 'js' option must be 'babel' or 'ts', given: '${val}'.`);
|
|
24
|
+
return res;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
// deprecated
|
|
29
|
+
if (parsedArgv.allowJs != null) {
|
|
30
|
+
if (parsedArgv.js)
|
|
31
|
+
throw new Error("The 'allowJs' and 'js' options cannot be set together.");
|
|
32
|
+
parsedArgv.js = parsedArgv.allowJs ? 'ts' : undefined;
|
|
33
|
+
}
|
|
34
|
+
let command = parsedArgv._.shift();
|
|
35
|
+
const isHelp = command === 'help';
|
|
36
|
+
if (isHelp)
|
|
37
|
+
command = parsedArgv._.shift();
|
|
38
|
+
if (!VALID_COMMANDS.includes(command))
|
|
39
|
+
command = 'help';
|
|
40
|
+
const { run, help } = require(`./${command.replace(/:/g, '/')}`);
|
|
41
|
+
const cmd = isHelp && command !== 'help' ? help : run;
|
|
42
|
+
return cmd(parsedArgv, logger);
|
|
43
|
+
}
|
|
44
|
+
const errorHasMessage = (err) => {
|
|
45
|
+
if (typeof err !== 'object' || err === null)
|
|
46
|
+
return false;
|
|
47
|
+
return 'message' in err;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
async function processArgv() {
|
|
53
|
+
try {
|
|
54
|
+
await cli(process.argv.slice(2));
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (errorHasMessage(err)) {
|
|
59
|
+
logger.fatal(err.message);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|