Skip to content

Commit 90beca8

Browse files
authored
Merge pull request #787 from huafu/fix-testing-utils
Fix testing utils & cache digest & docs related to presets
2 parents 645558b + 89ad06a commit 90beca8

33 files changed

Lines changed: 431 additions & 144 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ These instructions will get you setup to use `ts-jest` in your project. For more
3030
| | using npm | using yarn |
3131
|---:|---|---|
3232
| **Prerequisites** | `npm i -D jest typescript` | `yarn add --dev jest typescript` |
33-
| **Installing** | `npm i -D ts-jest` | `yarn add --dev ts-jest` |
33+
| **Installing** | `npm i -D ts-jest @types/jest` | `yarn add --dev ts-jest @types/jest` |
3434
| **Creating config** | `node_modules/.bin/ts-jest config:init` | `yarn ts-jest config:init` |
3535
| **Running tests** | `npm t` or `node_modules/.bin/jest` | `yarn test` or `yarn jest` |
3636

docs/user/config/index.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,18 @@ module.exports = {
5454

5555
Any preset can also be used with other options.
5656
If you're already using another preset, you might want only some specific settings from the chosen `ts-jest` preset.
57-
In this case you'll need to use the JavaScript version of Jest config:
57+
In this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use-case):
5858

5959
```js
6060
// jest.config.js
61-
const tsJestPresets = require('ts-jest/presets');
62-
63-
const preset = tsJestPresets.defaults
64-
// const preset = tsJestPresets.jsWithTs
65-
// const preset = tsJestPresets.jsWithBabel
61+
const { defaults: tsjPreset } = require('ts-jest/presets');
62+
// const { jsWithTs: tsjPreset } = require('ts-jest/presets');
63+
// const { jsWithBabel: tsjPreset } = require('ts-jest/presets');
6664

6765
module.exports = {
6866
// [...]
6967
transform: {
70-
...preset.transform,
68+
...tsjPreset.transform,
7169
// [...]
7270
}
7371
}
@@ -133,7 +131,7 @@ module.exports = {
133131

134132
```js
135133
// jest.config.js
136-
const { pathsToModuleNameMapper } = require('ts-jest');
134+
const { pathsToModuleNameMapper } = require('ts-jest/utils');
137135
// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file
138136
// which contains the path mapping (ie the `compilerOptions.paths` option):
139137
const { compilerOptions } = require('./tsconfig');

docs/user/config/stringifyContentPathRegex.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ In the `jest.config.js` version, you could do as in the `package.json` version o
1818

1919
```js
2020
// jest.config.js
21-
const { jestPreset } = require('ts-jest');
21+
// Here `defaults` can be replaced with any other preset
22+
const { defaults: tsjPreset } = require('ts-jest/presets');
2223

2324
module.exports = {
2425
// [...]
2526
moduleFileExtensions: [
26-
...jestPreset.moduleFileExtensions,
27+
...tsjPreset.moduleFileExtensions,
2728
'html'
2829
],
2930
transform: {
30-
...jestPreset.transform,
31+
...tsjPreset.transform,
3132
'\\.html$': 'ts-jest'
3233
}
3334
globals: {

docs/user/install.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ You can install `ts-jest` and dependencies all at once with the following comman
1313
Using `npm`:
1414

1515
```sh
16-
npm install --save-dev jest typescript ts-jest
16+
npm install --save-dev jest typescript ts-jest @types/jest
1717
```
1818

1919
</div><div class="col-md-6" markdown="block">
2020

2121
Using `yarn`:
2222

2323
```sh
24-
yarn add --dev jest typescript ts-jest
24+
yarn add --dev jest typescript ts-jest @types/jest
2525
```
2626

2727
</div></div>
@@ -55,7 +55,7 @@ yarn ts-jest config:init
5555
This will create a basic Jest configuration file which will make Jest know about your `.ts` files and handle them correctly.
5656

5757
You can also use the `jest --init` command (prefixed with either `npx` or `yarn` depending on what you're using) to have more options related to Jest.
58-
However, answer `no` to the Jest question about whether or not to enable Typescript. Instead, add the line: `preset: "ts-jest"` to the the `jest.config.js` file afterwards.
58+
However, answer `no` to the Jest question about whether or not to enable Typescript. Instead, add the line: `preset: "ts-jest"` to the `jest.config.js` file afterwards.
5959

6060
### Customizing
6161

docs/user/react-native/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ In the same way that you moved Babel config, move Jest config from `jest` key of
2525

2626
```js
2727
// jest.config.js
28-
const { jestPreset: tsJest } = require('ts-jest');
28+
const { defaults: tsjPreset } = require('ts-jest/presets');
2929

3030
module.exports = {
31-
...tsJest,
31+
...tsjPreset,
3232
preset: 'react-native',
3333
transform: {
34-
...tsJest.transform,
34+
...tsjPreset.transform,
3535
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
3636
},
3737
globals: {

docs/user/test-helpers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const foo = {
2727

2828
```ts
2929
// foo.spec.ts
30-
import { mocked } from 'ts-jest'
30+
import { mocked } from 'ts-jest/utils'
3131
import { foo } from './foo'
3232
jest.mock('./foo')
3333

e2e/__cases__/deep/src/Tests/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const cfg = {}
22

33
if (require('jest/package.json').version.split('.').shift() === '22') {
4-
Object.assign(cfg, require('ts-jest').jestPreset)
4+
Object.assign(cfg, require('ts-jest/presets').defaults)
55
} else {
66
cfg.preset = 'ts-jest'
77
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { mocked } from 'ts-jest'
2+
import { foo } from './to-mock'
3+
jest.mock('./to-mock')
4+
5+
test('foo', () => {
6+
foo()
7+
// it should log that the helper moved
8+
expect(mocked(foo).mock.calls.length).toBe(1)
9+
})

e2e/__cases__/test-helpers/fail.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mocked } from 'ts-jest'
1+
import { mocked } from 'ts-jest/utils'
22
import { foo, bar } from './to-mock'
33
jest.mock('./to-mock')
44

e2e/__cases__/test-helpers/pass.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mocked } from 'ts-jest'
1+
import { mocked } from 'ts-jest/utils'
22
import { foo, bar } from './to-mock'
33
jest.mock('./to-mock')
44

0 commit comments

Comments
 (0)