ts-jest 27.0.4 → 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.
Files changed (43) hide show
  1. package/.ts-jest-digest +1 -1
  2. package/CHANGELOG.md +59 -0
  3. package/CONTRIBUTING.md +95 -42
  4. package/README.md +3 -3
  5. package/TROUBLESHOOTING.md +37 -3
  6. package/dist/cli/config/init.js +17 -17
  7. package/dist/cli/config/migrate.js +23 -19
  8. package/dist/cli/helpers/presets.js +2 -2
  9. package/dist/cli/index.js +14 -7
  10. package/dist/compiler/compiler-utils.js +3 -3
  11. package/dist/compiler/index.d.ts +3 -0
  12. package/dist/compiler/index.js +15 -0
  13. package/dist/compiler/ts-compiler.d.ts +1 -1
  14. package/dist/compiler/ts-compiler.js +38 -35
  15. package/dist/compiler/ts-jest-compiler.d.ts +1 -1
  16. package/dist/config/config-set.js +64 -37
  17. package/dist/config/index.d.ts +2 -0
  18. package/dist/config/index.js +14 -0
  19. package/dist/config/paths-to-module-name-mapper.js +11 -10
  20. package/dist/index.d.ts +8 -0
  21. package/dist/index.js +18 -0
  22. package/dist/presets/create-jest-preset.js +2 -2
  23. package/dist/transformers/hoist-jest.d.ts +4 -1
  24. package/dist/transformers/hoist-jest.js +72 -94
  25. package/dist/transformers/path-mapping.d.ts +2 -2
  26. package/dist/transformers/path-mapping.js +33 -26
  27. package/dist/ts-jest-transformer.d.ts +3 -1
  28. package/dist/ts-jest-transformer.js +84 -47
  29. package/dist/types.d.ts +2 -2
  30. package/dist/utils/backports.js +9 -2
  31. package/dist/utils/get-package-version.js +1 -1
  32. package/dist/utils/importer.js +21 -18
  33. package/dist/utils/index.d.ts +4 -0
  34. package/dist/utils/index.js +15 -0
  35. package/dist/utils/json.js +1 -1
  36. package/dist/utils/jsonable-value.js +1 -1
  37. package/dist/utils/logger.js +3 -3
  38. package/dist/utils/sha1.js +1 -1
  39. package/dist/utils/ts-error.js +1 -1
  40. package/dist/utils/version-checkers.js +3 -3
  41. package/package.json +39 -42
  42. package/presets/index.d.ts +1 -1
  43. package/utils/index.js +13 -0
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- 728a5836db2d1522482a6d839e7cb4bf9dc045c0
1
+ 605af00ea20195c659a2337af7e3921155cf4587
package/CHANGELOG.md CHANGED
@@ -1,3 +1,62 @@
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
+
26
+ ## [27.0.7](https://github.com/kulshekhar/ts-jest/compare/v27.0.6...v27.0.7) (2021-10-16)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * correct `lodash` import ([#2978](https://github.com/kulshekhar/ts-jest/issues/2978)) ([8b60679](https://github.com/kulshekhar/ts-jest/commit/8b60679574eb60a3c8109ffd389b64b86a167e72)), closes [#2977](https://github.com/kulshekhar/ts-jest/issues/2977)
32
+
33
+
34
+
35
+ ## [27.0.6](https://github.com/kulshekhar/ts-jest/compare/v27.0.5...v27.0.6) (2021-10-14)
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * use specific `lodash` package instead of full package `lodash` ([#2959](https://github.com/kulshekhar/ts-jest/issues/2959)) ([dc89fe5](https://github.com/kulshekhar/ts-jest/commit/dc89fe55f2b77da76443f827fe3055f07cf4809c)), closes [#2954](https://github.com/kulshekhar/ts-jest/issues/2954)
41
+
42
+
43
+
44
+ ## [27.0.5](https://github.com/kulshekhar/ts-jest/compare/v27.0.4...v27.0.5) (2021-08-14)
45
+
46
+
47
+ ### Bug Fixes
48
+
49
+ * **cli:** add migration `tsConfig` option for `ts-jest` config options ([#2794](https://github.com/kulshekhar/ts-jest/issues/2794)) ([781710b](https://github.com/kulshekhar/ts-jest/commit/781710bf6b84853fffbb02543062a726fe1ad9c2)), closes [#2764](https://github.com/kulshekhar/ts-jest/issues/2764)
50
+ * **cli:** fix `config:init` genarate invalid type comment ([#2773](https://github.com/kulshekhar/ts-jest/issues/2773)) ([ede8a20](https://github.com/kulshekhar/ts-jest/commit/ede8a2061e20b717c0d56e4d81a3cd0ec7db8b1a)), closes [#2772](https://github.com/kulshekhar/ts-jest/issues/2772)
51
+ * **config:** handle `./` in tsconfig `paths` for `pathsToModuleNameMapper` ([#2797](https://github.com/kulshekhar/ts-jest/issues/2797)) ([42ff5e4](https://github.com/kulshekhar/ts-jest/commit/42ff5e469fb5d315b92e85eee105e5a040949c01)), closes [#2709](https://github.com/kulshekhar/ts-jest/issues/2709)
52
+
53
+
54
+ ### Code Refactoring
55
+
56
+ * use native `Buffer.from` and `mkdird` ([#2774](https://github.com/kulshekhar/ts-jest/issues/2774)) ([4869660](https://github.com/kulshekhar/ts-jest/commit/4869660e3917deb063745c5acaf079123d6d2ca8))
57
+
58
+
59
+
1
60
  ## [27.0.4](https://github.com/kulshekhar/ts-jest/compare/v27.0.3...v27.0.4) (2021-07-21)
2
61
 
3
62
 
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 [slack](https://bit.ly/3bRHFPQ) or [issue](https://github.com/kulshekhar/ts-jest/issues) with the owners of this repository before making a change.
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 Request Process
9
+ ## Workflow and Pull Requests
8
10
 
9
- 1. Ensure the tests are passing and that you have latest `master` branch merged in.
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
- ## Code of Conduct
13
+ _Before_ submitting a pull request, please make sure the following is done…
15
14
 
16
- ### Our Pledge
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
- In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
17
+ Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type:
19
18
 
20
- ### Our Standards
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
- Examples of behavior that contributes to creating a positive environment include:
25
+ Note: Replace `<your_username>` with your GitHub username
23
26
 
24
- - Using welcoming and inclusive language
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
- Examples of unacceptable behavior by participants include:
29
+ 3. Make sure you have a compatible version of `node` installed (As of April 14th 2021, `v14.x` is recommended).
31
30
 
32
- - The use of sexualized language or imagery and unwelcome sexual attention or advances
33
- - Trolling, insulting/derogatory comments, and personal or political attacks
34
- - Public or private harassment
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
- ### Our Responsibilities
35
+ 4. Run `npm ci`. `ts-jest` will automatically build source files into `dist/` after installing dependencies.
39
36
 
40
- Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
37
+ 5. Ensure the test suite passes via `npm run test`.
41
38
 
42
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
39
+ ### Testing
43
40
 
44
- ### Scope
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
- This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
44
+ ##### Unit tests
47
45
 
48
- ### Enforcement
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
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
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
- Project maintainers who do not follow or enforce the Code of Conduct in good
58
- faith may face temporary or permanent repercussions as determined by other
59
- members of the project's leadership.
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
- ### Attribution
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
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
64
- available at [http://contributor-covenant.org/version/1/4][version]
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
- [homepage]: http://contributor-covenant.org
67
- [version]: http://contributor-covenant.org/version/1/4/
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/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  <a href="https://www.npmjs.com/package/ts-jest"><img src="https://img.shields.io/npm/v/ts-jest/latest.svg?style=flat-square" alt="NPM version" /> </a>
7
7
  <a href="https://www.npmjs.com/package/ts-jest"><img src="https://img.shields.io/npm/dm/ts-jest.svg?style=flat-square" alt="NPM downloads"/> </a>
8
8
  <a href="https://snyk.io/test/github/kulshekhar/ts-jest"><img src="https://snyk.io/test/github/kulshekhar/ts-jest/badge.svg?style=flat-square" alt="Known vulnerabilities"/> </a>
9
- <a href="https://coveralls.io/github/kulshekhar/ts-jest?branch=master"><img src="https://coveralls.io/repos/github/kulshekhar/ts-jest/badge.svg?branch=master" alt="Coverage status"/> </a>
10
- <a href="https://actions-badge.atrox.dev/kulshekhar/ts-jest/goto?ref=master"><img alt="GitHub actions" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fkulshekhar%2Fts-jest%2Fbadge%3Fref%3Dmaster&style=flat-square" /> </a>
11
- <a href="https://github.com/kulshekhar/ts-jest/blob/master/LICENSE.md"><img src="https://img.shields.io/npm/l/ts-jest.svg?style=flat-square" alt="GitHub license"/> </a>
9
+ <a href="https://coveralls.io/github/kulshekhar/ts-jest?branch=main"><img src="https://coveralls.io/repos/github/kulshekhar/ts-jest/badge.svg?branch=main" alt="Coverage status"/> </a>
10
+ <a href="https://actions-badge.atrox.dev/kulshekhar/ts-jest/goto?ref=main"><img alt="GitHub actions" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fkulshekhar%2Fts-jest%2Fbadge%3Fref%3Dmain&style=flat-square" /> </a>
11
+ <a href="https://github.com/kulshekhar/ts-jest/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/ts-jest.svg?style=flat-square" alt="GitHub license"/> </a>
12
12
  </p>
13
13
 
14
14
  <img src="./icon.png" align="right" title="ts-jest Logo" width="128" height="128">
@@ -10,7 +10,7 @@ Cannot find module "" from ""
10
10
 
11
11
  - Check if `rootDir` is referenced correctly. If not add this on your existing jest configuration.
12
12
 
13
- ```javascipt
13
+ ```javascript
14
14
  module.exports = {
15
15
  ...
16
16
  roots: ["<rootDir>"]
@@ -19,7 +19,7 @@ module.exports = {
19
19
 
20
20
  - Check if module directories are included on your jest configuration. If not add this on your existing jest configuration.
21
21
 
22
- ```javascipt
22
+ ```javascript
23
23
  module.exports = {
24
24
  ...
25
25
  moduleDirectories: ["node_modules","<module-directory>"],
@@ -29,7 +29,7 @@ module.exports = {
29
29
 
30
30
  - Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration.
31
31
 
32
- ```javascipt
32
+ ```javascript
33
33
  module.exports = {
34
34
  ...
35
35
  moduleNameMapper: {
@@ -39,3 +39,37 @@ module.exports = {
39
39
  ```
40
40
 
41
41
  - Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command `git mv <source> <destination>` and commit changes.
42
+
43
+ ## Transform (node)-module explicitly
44
+
45
+ ### PROBLEM
46
+
47
+ SyntaxError: Cannot use import statement outside a module
48
+
49
+ ### SOLUTION
50
+
51
+ One of the node modules hasn't the correct syntax for Jests execution step. It needs to
52
+ be transformed first.
53
+
54
+ There is a good chance that the error message shows which module is affected:
55
+
56
+ ```shell
57
+ SyntaxError: Cannot use import statement outside a module
58
+ > 22 | import Component from "../../node_modules/some-module/lib";
59
+ | ^
60
+ ```
61
+
62
+ In this case **some-module** is the problem and needs to be transformed.
63
+ By adding the following line to the configuration file it will tell Jest which modules
64
+ shouldnt be ignored during the transformation step:
65
+
66
+ ```javascript
67
+ module.exports = {
68
+ ...
69
+ transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]
70
+ };
71
+ ```
72
+
73
+ **some-module** and **another-module** will be transformed.
74
+
75
+ For more information see [here](https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module) and [here](https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns).
@@ -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 " + file + " does not exists.");
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 " + file + " already exists.");
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 " + file + " must be a .js file or the package.json.");
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 " + pkgFile + ".");
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
- content.push("/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */");
122
+ content.push("/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */");
123
123
  content.push('module.exports = {');
124
124
  if (jestPreset) {
125
- content.push(" preset: '" + preset.name + "',");
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: " + json5_1.stringify(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 \"" + filePath + "\".\n");
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, il = from.length, j = to.length; i < il; i++, j++)
56
- to[j] = from[i];
57
- return to;
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 " + file + " does not exists.");
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 " + file + " must be a JavaScript or JSON 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 '" + 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");
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: " + stringify(preset.value.transform, undefined, ' ') + "\nIf it is the case, you can safely remove the \"transform\" from what I've migrated.\n");
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("" + prefix + stringify(migratedConfig, undefined, ' ') + "\n");
185
+ process.stdout.write("".concat(prefix).concat(stringify(migratedConfig, undefined, ' '), "\n"));
182
186
  if (footNotes.length) {
183
- process.stderr.write("\n" + footNotes.join('\n') + "\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("../../../" + fullName.replace(/^ts-jest\//, '') + "/jest-preset");
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 { " + this.jsVarName + ": " + varName + " } = require('ts-jest/presets')";
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 logger_1 = require("../utils/logger");
46
+ var utils_1 = require("../utils");
47
47
  var VALID_COMMANDS = ['help', 'config:migrate', 'config:init'];
48
- var logger = logger_1.rootLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'cli', _a[bs_logger_1.LogContexts.application] = 'ts-jest', _a));
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: '" + val + "'.");
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("./" + command.replace(/:/g, '/')), run = _a.run, help = _a.help;
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
- logger.fatal(err_1.message);
100
- process.exit(1);
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 json_1 = require("../utils/json");
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," + base64Map;
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 json_1.stringify(sourceMap);
23
+ return (0, utils_1.stringify)(sourceMap);
24
24
  };
@@ -0,0 +1,3 @@
1
+ export * from './compiler-utils';
2
+ export * from './ts-compiler';
3
+ export * from './ts-jest-compiler';
@@ -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/config-set';
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;