Skip to content

Commit 8f8f96a

Browse files
committed
chore(release): 29.2.0
1 parent 7a3abe4 commit 8f8f96a

30 files changed

+2624
-23
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
## 29.2.0 (2024-07-08)
2+
3+
4+
### Bug Fixes
5+
6+
* fix: don't show warning message with Node16/NodeNext ([99c4f49](https://github.com/kulshekhar/ts-jest/commit/99c4f49)), closes [#4266](https://github.com/kulshekhar/ts-jest/issues/4266)
7+
8+
9+
### Features
10+
11+
* feat(cli): allow migrating cjs `presets` to `transform` config ([22fb027](https://github.com/kulshekhar/ts-jest/commit/22fb027))
12+
* feat(presets): add util functions to create ESM presets ([06f78ed](https://github.com/kulshekhar/ts-jest/commit/06f78ed))
13+
* feat(presets): add util functions to create CJS presets ([f9cc3c0](https://github.com/kulshekhar/ts-jest/commit/f9cc3c0))
14+
15+
16+
### Code refactoring
17+
18+
* refactor: replace lodash deps with native js implementation ([40f1708](https://github.com/kulshekhar/ts-jest/commit/40f1708))
19+
* refactor: use `TsJestTransformerOptions` type everywhere possibly ([7d001be](https://github.com/kulshekhar/ts-jest/commit/7d001be))
20+
* refactor(cli): use new preset util functions to initialize test config ([c2b56ca](https://github.com/kulshekhar/ts-jest/commit/c2b56ca))
21+
* refactor(presets): use create preset util functions for cjs presets ([922d6d0](https://github.com/kulshekhar/ts-jest/commit/922d6d0))
22+
* test: switch `react-app` to use Vite ([827c8ad](https://github.com/kulshekhar/ts-jest/commit/827c8ad))
23+
24+
25+
### DEPRECATIONS
26+
27+
* refactor(cli): deprecate cli option `babel` ([9617029](https://github.com/kulshekhar/ts-jest/commit/9617029)). Please use CLI argument `--js babel` instead.
28+
* `createJestPreset` is deprecated. Please check documentation at https://kulshekhar.github.io/ts-jest/docs/getting-started/presets to see alternative solutions.
29+
30+
31+
132
## [29.1.5](https://github.com/kulshekhar/ts-jest/compare/v29.1.4...v29.1.5) (2024-06-16)
233

334

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-jest",
3-
"version": "29.1.5",
3+
"version": "29.2.0",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"bin": {

website/docs/getting-started/presets.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Starting from **v28.0.0**, `ts-jest` will gradually opt in adoption of `esbuild`
1313

1414
:::caution
1515

16-
If you are using custom `transform` config, please remove `preset` from your Jest config to avoid issues that Jest doesn't transform files correctly.
16+
The list of `preset` below is now deprecated in favor of util functions. If one is using `preset` in Jest config, please run `npx ts-jest config:migrate` or look into [Advanced](#advanced) section below for alternative solutions.
1717

1818
:::
1919

@@ -81,44 +81,45 @@ export default jestConfig
8181

8282
### Advanced
8383

84-
Any preset can also be used with other options.
85-
If you're already using another preset, you might want only some specific settings from the chosen `ts-jest` preset.
86-
In this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):
84+
There are several util functions to create and extend the existing presets:
85+
86+
- `createDefaultPreset`: for default preset
87+
- `createDefaultLegacyPreset`: for default preset in legacy mode
88+
- `createDefaultEsmPreset`: for default ESM preset
89+
- `createDefaultEsmLegacyPreset`: for default ESM preset in legacy mode
90+
- `createJsWithTsPreset`: for `js-with-ts` preset
91+
- `createJsWithTsLegacyPreset`: for `js-with-ts` preset in legacy mode
92+
- `createJsWithTsEsmPreset`: for `js-with-ts` ESM preset
93+
- `createJsWithTsEsmLegacyPreset`: for `js-with-ts` ESM preset in legacy mode
94+
- `createJsWithBabelPreset`: for `js-with-babel` preset
95+
- `createJsWithBabelLegacyPreset`: for `js-with-babel` preset in legacy mode
96+
- `createJsWithBabelEsmPreset`: for `js-with-babel` ESM preset
97+
- `createJsWithBabelEsmLegacyPreset`: for `js-with-babel` ESM preset in legacy mode
98+
99+
Example:
87100

88101
```js tab
89102
// jest.config.js
90-
const { defaults: tsjPreset } = require('ts-jest/presets')
91-
// const { defaultsESM: tsjPreset } = require('ts-jest/presets')
92-
// const { jsWithTs: tsjPreset } = require('ts-jest/presets')
93-
// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')
94-
// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')
95-
// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')
103+
const { createDefaultPreset } = require('ts-jest')
96104

97105
/** @type {import('ts-jest').JestConfigWithTsJest} */
98106
module.exports = {
99107
// [...]
100108
transform: {
101-
...tsjPreset.transform,
109+
...createDefaultPreset().transform,
102110
// [...]
103111
},
104112
}
105113
```
106114

107115
```ts tab
108116
// jest.config.ts
109-
import type { JestConfigWithTsJest } from 'ts-jest'
110-
111-
import { defaults as tsjPreset } from 'ts-jest/presets'
112-
// import { defaultsESM as tsjPreset } from 'ts-jest/presets';
113-
// import { jsWithTs as tsjPreset } from 'ts-jest/presets';
114-
// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets';
115-
// import { jsWithBabel as tsjPreset } from 'ts-jest/presets';
116-
// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets';
117+
import { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'
117118

118119
const jestConfig: JestConfigWithTsJest = {
119120
// [...]
120121
transform: {
121-
...tsjPreset.transform,
122+
...createDefaultPreset().transform,
122123
// [...]
123124
},
124125
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
id: babel7-or-ts
3+
title: Babel7 or TypeScript
4+
---
5+
6+
In Sept. 2018 Babel7 got released with an interesting preset: `@babel/preset-typescript`.
7+
8+
The goal is to make it easy for users using Babel to try TypeScript without moving out from Babel, just by adding a preset in their Babel config (here is the [MSDN blog post](https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/) about TypeScript and Babel 7).
9+
10+
## Limitations
11+
12+
While `@babel/preset-typescript` is a great preset, you must know the limitation of it. Here is what is possible with TypeScript (and `ts-jest`), which is not with Babel7 and `@babel/preset-typescript`:
13+
14+
#### No type-checking
15+
16+
This is the big **PRO** of using TypeScript vs Babel, you have type-checking out of the box.
17+
18+
You'll get a more fluent TDD experience (when using `ts-jest`) since files will be type-checked at the same time they're compiled and ran.
19+
20+
Here TypeScript will throw while Babel won't:
21+
22+
```ts
23+
const str: string = 42
24+
```
25+
26+
With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and are compiled in that scope.
27+
28+
---
29+
30+
#### No `namespace`
31+
32+
```ts
33+
namespace app {
34+
export const VERSION = '1.0.0'
35+
export class App {
36+
/* ... */
37+
}
38+
}
39+
```
40+
41+
---
42+
43+
#### No `const enum`
44+
45+
```ts
46+
const enum Directions {
47+
Up,
48+
Down,
49+
Left,
50+
Right,
51+
}
52+
```
53+
54+
---
55+
56+
#### No declaration merging (`enum`, `namespace`, ...)
57+
58+
You won't be able to do [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html).
59+
60+
---
61+
62+
#### No legacy `import`/`export`
63+
64+
```ts
65+
import lib = require('lib')
66+
// ...
67+
export = myVar
68+
```
69+
70+
---
71+
72+
#### No caret type-casting with JSX enabled
73+
74+
```ts
75+
const val = <string>input
76+
```
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
---
2+
id: contributing
3+
title: Contributing
4+
---
5+
6+
When contributing to this repository, please first discuss the change you wish to make via [`ts-jest` GitHub discussion](https://github.com/kulshekhar/ts-jest/discussions) or [issue](https://github.com/kulshekhar/ts-jest/issues) with the owners of this repository before making a change.
7+
8+
Please note we have a code of conduct, please follow it in all your interactions with the project.
9+
10+
## Pull Request Process
11+
12+
1. Ensure the tests are passing and that you have latest `main` branch merged in.
13+
2. Update the `docs/` with details of your changes if required.
14+
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.
15+
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.
16+
17+
_These are internal technical documents. If you're not a contributor to `ts-jest`, but simply trying to use the library you'll find nothing of value here_
18+
19+
## E2E Testing
20+
21+
### Preparing
22+
23+
The preparation of E2E test directory is done in `scripts/e2e.js`. Here is the process:
24+
25+
```plantuml
26+
start
27+
28+
:bundle ts-jest;
29+
note right
30+
will build ts-jest before creating the bundle
31+
end note
32+
33+
:create temp work dir;
34+
note right
35+
`e2e/~__workdir_symlink__` links to it
36+
except on CI environments
37+
end note
38+
39+
while (for each template)
40+
note right
41+
templates are in `e2e/~__templates__/`
42+
end note
43+
44+
if (template's build directory) then (exists)
45+
:wipe but `node_modules` dir;
46+
else (not exists)
47+
:create;
48+
endif
49+
50+
:copy files from template's dir to its build dir;
51+
52+
if (package lock file) then (exists)
53+
:read metadata;
54+
55+
if (package lock file) then (has changed)
56+
:remove `node_modules` dir;
57+
58+
:npm install (or ci);
59+
60+
:npm install ts-jest bundle;
61+
62+
else if (ts-jest bundle) then (has changed)
63+
:npm install ts-jest bundle;
64+
65+
else (hasn't changed)
66+
endif
67+
:write updated metadata;
68+
69+
else (not exists)
70+
endif
71+
72+
endwhile (done)
73+
74+
:all templates ready;
75+
76+
stop
77+
```
78+
79+
### Running
80+
81+
When a test-case needs to be run with a given template within tests, here is what's happening (in `e2e/__helpers__/test-case/runtime.ts`):
82+
83+
```plantuml
84+
start
85+
86+
:create work dir;
87+
note right
88+
It'll be different per test-case
89+
and per template basis.
90+
end note
91+
-> e2e/~__workdir_symlink__/{template}/{test-case};
92+
93+
if (has a node_modules dir?) then (yes)
94+
:symlink node_modules;
95+
note left
96+
avoid re-running npm install
97+
for each test case and template;
98+
end note
99+
else (no)
100+
endif
101+
102+
:copy files from template;
103+
note right
104+
all files in template dir are
105+
copied to test case work dir
106+
except `node_modules` and
107+
`package-lock.json`
108+
end note
109+
110+
while (for each file in test case dir)
111+
if (is snapshot dir) then (yes)
112+
:symlink dir;
113+
note left
114+
snapshots directories are symlinked
115+
to test case source dir so that
116+
updating them would update in the
117+
source folder
118+
end note
119+
120+
else if (is jest.config.js) then (yes)
121+
if (jest.config.js is function?) then (yes)
122+
:call with parent content;
123+
note left
124+
allows for
125+
extending
126+
end note
127+
else (no)
128+
endif
129+
130+
else (others)
131+
:copy;
132+
note right
133+
all files in test case source
134+
dir are copied to the work dir
135+
except `node_modules` and
136+
`package-lock.json`
137+
end note
138+
139+
endif
140+
endwhile
141+
142+
:create special files;
143+
note right
144+
some special files are created
145+
to handle hooks for example and
146+
grab `process()` IO for later
147+
expectations
148+
end note
149+
150+
:update package.json;
151+
note right
152+
set a custom but fixed name
153+
and version in package.json
154+
which is specific to the
155+
test case + template
156+
end note
157+
158+
#tomato:run tests;
159+
160+
while (for each snapshot) is (missing in test case)
161+
:copy;
162+
note right
163+
while we symlinked each snapshots
164+
directory, newly created snapshots
165+
in non existing dir will need to
166+
be copied over into
167+
e2e/~__cases__/{test-case}
168+
end note
169+
endwhile
170+
171+
:return results;
172+
173+
stop
174+
```

0 commit comments

Comments
 (0)