Skip to content

Commit

Permalink
chore(release): 29.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Jul 8, 2024
1 parent 7a3abe4 commit 8f8f96a
Show file tree
Hide file tree
Showing 30 changed files with 2,624 additions and 23 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## 29.2.0 (2024-07-08)


### Bug Fixes

* 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)


### Features

* feat(cli): allow migrating cjs `presets` to `transform` config ([22fb027](https://github.com/kulshekhar/ts-jest/commit/22fb027))
* feat(presets): add util functions to create ESM presets ([06f78ed](https://github.com/kulshekhar/ts-jest/commit/06f78ed))
* feat(presets): add util functions to create CJS presets ([f9cc3c0](https://github.com/kulshekhar/ts-jest/commit/f9cc3c0))


### Code refactoring

* refactor: replace lodash deps with native js implementation ([40f1708](https://github.com/kulshekhar/ts-jest/commit/40f1708))
* refactor: use `TsJestTransformerOptions` type everywhere possibly ([7d001be](https://github.com/kulshekhar/ts-jest/commit/7d001be))
* refactor(cli): use new preset util functions to initialize test config ([c2b56ca](https://github.com/kulshekhar/ts-jest/commit/c2b56ca))
* refactor(presets): use create preset util functions for cjs presets ([922d6d0](https://github.com/kulshekhar/ts-jest/commit/922d6d0))
* test: switch `react-app` to use Vite ([827c8ad](https://github.com/kulshekhar/ts-jest/commit/827c8ad))


### DEPRECATIONS

* refactor(cli): deprecate cli option `babel` ([9617029](https://github.com/kulshekhar/ts-jest/commit/9617029)). Please use CLI argument `--js babel` instead.
* `createJestPreset` is deprecated. Please check documentation at https://kulshekhar.github.io/ts-jest/docs/getting-started/presets to see alternative solutions.



## [29.1.5](https://github.com/kulshekhar/ts-jest/compare/v29.1.4...v29.1.5) (2024-06-16)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-jest",
"version": "29.1.5",
"version": "29.2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
Expand Down
41 changes: 21 additions & 20 deletions website/docs/getting-started/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Starting from **v28.0.0**, `ts-jest` will gradually opt in adoption of `esbuild`

:::caution

If you are using custom `transform` config, please remove `preset` from your Jest config to avoid issues that Jest doesn't transform files correctly.
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.

:::

Expand Down Expand Up @@ -81,44 +81,45 @@ export default jestConfig

### Advanced

Any preset can also be used with other options.
If you're already using another preset, you might want only some specific settings from the chosen `ts-jest` preset.
In this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use case):
There are several util functions to create and extend the existing presets:

- `createDefaultPreset`: for default preset
- `createDefaultLegacyPreset`: for default preset in legacy mode
- `createDefaultEsmPreset`: for default ESM preset
- `createDefaultEsmLegacyPreset`: for default ESM preset in legacy mode
- `createJsWithTsPreset`: for `js-with-ts` preset
- `createJsWithTsLegacyPreset`: for `js-with-ts` preset in legacy mode
- `createJsWithTsEsmPreset`: for `js-with-ts` ESM preset
- `createJsWithTsEsmLegacyPreset`: for `js-with-ts` ESM preset in legacy mode
- `createJsWithBabelPreset`: for `js-with-babel` preset
- `createJsWithBabelLegacyPreset`: for `js-with-babel` preset in legacy mode
- `createJsWithBabelEsmPreset`: for `js-with-babel` ESM preset
- `createJsWithBabelEsmLegacyPreset`: for `js-with-babel` ESM preset in legacy mode

Example:

```js tab
// jest.config.js
const { defaults: tsjPreset } = require('ts-jest/presets')
// const { defaultsESM: tsjPreset } = require('ts-jest/presets')
// const { jsWithTs: tsjPreset } = require('ts-jest/presets')
// const { jsWithTsESM: tsjPreset } = require('ts-jest/presets')
// const { jsWithBabel: tsjPreset } = require('ts-jest/presets')
// const { jsWithBabelESM: tsjPreset } = require('ts-jest/presets')
const { createDefaultPreset } = require('ts-jest')

/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
// [...]
transform: {
...tsjPreset.transform,
...createDefaultPreset().transform,
// [...]
},
}
```

```ts tab
// jest.config.ts
import type { JestConfigWithTsJest } from 'ts-jest'

import { defaults as tsjPreset } from 'ts-jest/presets'
// import { defaultsESM as tsjPreset } from 'ts-jest/presets';
// import { jsWithTs as tsjPreset } from 'ts-jest/presets';
// import { jsWithTsESM as tsjPreset } from 'ts-jest/presets';
// import { jsWithBabel as tsjPreset } from 'ts-jest/presets';
// import { jsWithBabelESM as tsjPreset } from 'ts-jest/presets';
import { createDefaultPreset, type JestConfigWithTsJest } from 'ts-jest'

const jestConfig: JestConfigWithTsJest = {
// [...]
transform: {
...tsjPreset.transform,
...createDefaultPreset().transform,
// [...]
},
}
Expand Down
76 changes: 76 additions & 0 deletions website/versioned_docs/version-29.2/babel7-or-ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
id: babel7-or-ts
title: Babel7 or TypeScript
---

In Sept. 2018 Babel7 got released with an interesting preset: `@babel/preset-typescript`.

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).

## Limitations

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`:

#### No type-checking

This is the big **PRO** of using TypeScript vs Babel, you have type-checking out of the box.

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.

Here TypeScript will throw while Babel won't:

```ts
const str: string = 42
```

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.

---

#### No `namespace`

```ts
namespace app {
export const VERSION = '1.0.0'
export class App {
/* ... */
}
}
```

---

#### No `const enum`

```ts
const enum Directions {
Up,
Down,
Left,
Right,
}
```

---

#### No declaration merging (`enum`, `namespace`, ...)

You won't be able to do [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html).

---

#### No legacy `import`/`export`

```ts
import lib = require('lib')
// ...
export = myVar
```

---

#### No caret type-casting with JSX enabled

```ts
const val = <string>input
```
174 changes: 174 additions & 0 deletions website/versioned_docs/version-29.2/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
---
id: contributing
title: Contributing
---

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.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Pull Request Process

1. Ensure the tests are passing and that you have latest `main` branch merged in.
2. Update the `docs/` with details of your changes if required.
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.
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.

_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_

## E2E Testing

### Preparing

The preparation of E2E test directory is done in `scripts/e2e.js`. Here is the process:

```plantuml
start
:bundle ts-jest;
note right
will build ts-jest before creating the bundle
end note
:create temp work dir;
note right
`e2e/~__workdir_symlink__` links to it
except on CI environments
end note
while (for each template)
note right
templates are in `e2e/~__templates__/`
end note
if (template's build directory) then (exists)
:wipe but `node_modules` dir;
else (not exists)
:create;
endif
:copy files from template's dir to its build dir;
if (package lock file) then (exists)
:read metadata;
if (package lock file) then (has changed)
:remove `node_modules` dir;
:npm install (or ci);
:npm install ts-jest bundle;
else if (ts-jest bundle) then (has changed)
:npm install ts-jest bundle;
else (hasn't changed)
endif
:write updated metadata;
else (not exists)
endif
endwhile (done)
:all templates ready;
stop
```

### Running

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`):

```plantuml
start
:create work dir;
note right
It'll be different per test-case
and per template basis.
end note
-> e2e/~__workdir_symlink__/{template}/{test-case};
if (has a node_modules dir?) then (yes)
:symlink node_modules;
note left
avoid re-running npm install
for each test case and template;
end note
else (no)
endif
:copy files from template;
note right
all files in template dir are
copied to test case work dir
except `node_modules` and
`package-lock.json`
end note
while (for each file in test case dir)
if (is snapshot dir) then (yes)
:symlink dir;
note left
snapshots directories are symlinked
to test case source dir so that
updating them would update in the
source folder
end note
else if (is jest.config.js) then (yes)
if (jest.config.js is function?) then (yes)
:call with parent content;
note left
allows for
extending
end note
else (no)
endif
else (others)
:copy;
note right
all files in test case source
dir are copied to the work dir
except `node_modules` and
`package-lock.json`
end note
endif
endwhile
:create special files;
note right
some special files are created
to handle hooks for example and
grab `process()` IO for later
expectations
end note
:update package.json;
note right
set a custom but fixed name
and version in package.json
which is specific to the
test case + template
end note
#tomato:run tests;
while (for each snapshot) is (missing in test case)
:copy;
note right
while we symlinked each snapshots
directory, newly created snapshots
in non existing dir will need to
be copied over into
e2e/~__cases__/{test-case}
end note
endwhile
:return results;
stop
```
Loading

0 comments on commit 8f8f96a

Please sign in to comment.