Skip to content

Commit 52beb10

Browse files
authored
chore(release): 12.0.0 (#1464)
1 parent af24ddf commit 52beb10

File tree

24 files changed

+895
-90
lines changed

24 files changed

+895
-90
lines changed

CHANGELOG.md

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [12.0.0-next.2](https://github.com/thymikee/jest-preset-angular/compare/v12.0.0-next.1...v12.0.0-next.2) (2022-05-08)
1+
# [12.0.0](https://github.com/thymikee/jest-preset-angular/compare/v12.0.0-next.2...v12.0.0) (2022-05-10)
22

33

44
### Bug Fixes
@@ -9,31 +9,24 @@
99

1010
### Features
1111

12+
* **config:** add `setup-jest.mjs` for ESM mode ([#1463](https://github.com/thymikee/jest-preset-angular/issues/1463)) ([cc6ce3f](https://github.com/thymikee/jest-preset-angular/commit/cc6ce3fd92d00d8b5d71bec535ce2d625a4cc48c))
1213
* add an option to configure which file processed by `esbuild` ([#1455](https://github.com/thymikee/jest-preset-angular/issues/1455)) ([b58d089](https://github.com/thymikee/jest-preset-angular/commit/b58d089c255a600707a35cabcfa62fb413f8153b)), closes [#1413](https://github.com/thymikee/jest-preset-angular/issues/1413) [#1437](https://github.com/thymikee/jest-preset-angular/issues/1437)
1314
* drop support Node 12 ([04195d5](https://github.com/thymikee/jest-preset-angular/commit/04195d5326e370e76e6f76d1e2c9cf277cf975a0))
1415
* exclude `ng-jest-resolver` from default/esm presets ([#1440](https://github.com/thymikee/jest-preset-angular/issues/1440)) ([56673c4](https://github.com/thymikee/jest-preset-angular/commit/56673c4c086e6a4bf8fada5c196c5a50481b04f0))
15-
* **presets:** use `.mjs` extension for ESM preset ([#1448](https://github.com/thymikee/jest-preset-angular/issues/1448)) ([cf7239d](https://github.com/thymikee/jest-preset-angular/commit/cf7239d55a0b3d33c7e6f55f9eb0adae54e9ea3f))
1616
* remove `reflect-metadata` in `setup-jest` ([#1428](https://github.com/thymikee/jest-preset-angular/issues/1428)) ([5a36729](https://github.com/thymikee/jest-preset-angular/commit/5a367293ba490d7d717963b099db7531c347d1f4))
1717
* remove `zone-patch` and its fallback ([#1427](https://github.com/thymikee/jest-preset-angular/issues/1427)) ([bf9ea44](https://github.com/thymikee/jest-preset-angular/commit/bf9ea44a643311f3bbfbcbc67b493aa000336bee))
18-
* use `import 'zone.js'` and `import 'zone.js/testing'` in `setup-jest` ([#1429](https://github.com/thymikee/jest-preset-angular/issues/1429)) ([55f4375](https://github.com/thymikee/jest-preset-angular/commit/55f4375c6671319c5ab5579c03f3fa06e8ade320))
18+
* allow running `ngcc` with specific `tsconfig` path ([#1418](https://github.com/thymikee/jest-preset-angular/issues/1418)) ([5f535b5](https://github.com/thymikee/jest-preset-angular/commit/5f535b59227daea6e64e4886b0ea0bd5fd7c1365)), closes [#1348](https://github.com/thymikee/jest-preset-angular/issues/1348)
19+
* allow skip `ngcc` via `skipNgcc` option via `globalThis` ([#1417](https://github.com/thymikee/jest-preset-angular/issues/1417)) ([7950b5c](https://github.com/thymikee/jest-preset-angular/commit/7950b5cedfab066a268b16f5c87b5ad3670c6888)), closes [#1396](https://github.com/thymikee/jest-preset-angular/issues/1396)
20+
* remove `ngcc-jest-processor` entry file ([#1414](https://github.com/thymikee/jest-preset-angular/issues/1414)) ([2c5fd20](https://github.com/thymikee/jest-preset-angular/commit/2c5fd20f0535f5441d8bcb477538defdd9529926))
1921

2022

2123
## BREAKING CHANGES
2224

23-
* Since Angular 11, the minimum version of `zone.js` is 0.11.x and Angular 10 is EOL, so now we can use zone patch directly from `zone.js`.
25+
* Since **Angular 11**, the minimum version of `zone.js` is **0.11.x** and Angular 10 is EOL, so now we can use zone patch directly from `zone.js`.
2426
If one is not using `[email protected]`, please upgrade.
2527
* Now we are using Angular AST transformers, `reflect-metadata` is not needed anymore.
26-
* `setup-jest` now is identical to the file which is generated by Angular CLI for Karma + Jasmine, `test.ts`, in which `jest-preset-angular` put
27-
```js
28-
import 'zone.js';
29-
import 'zone.js/testing';
30-
```
31-
* Jest 28 correctly resolves Angular package format files so the `ng-jest-resolver` can be marked as optional
32-
* Node 12 is no longer support
33-
* ESM preset now uses `.mjs` extensions which cannot use with `require` syntax. One wishes to import this preset in `js` Jest config file should do
34-
```js
35-
import esmPreset from 'jest-preset-angular/presets/defaults-esm/jest-preset.mjs';
36-
```
28+
* **Jest 28** correctly resolves Angular package format files so the `ng-jest-resolver` is now optional.
29+
* **Node 12** is no longer support
3730
* Previously, we always checked file extension `.mjs` and any files from `node_modules` excluding `tslib` to be processed with `esbuild`.
3831
With the new option `processWithEsbuild`, now we put default all `.mjs` files to be processed by `esbuild`. Files like `lodash-es` default isn't processed by `esbuild`.
3932
If you wish to use `esbuild` to process such files, please configure in your Jest config like
@@ -48,30 +41,8 @@ module.exports = {
4841
}
4942
}
5043
```
51-
52-
53-
# [12.0.0-next.1](https://github.com/thymikee/jest-preset-angular/compare/v12.0.0-next.0...v12.0.0-next.1) (2022-04-26)
54-
55-
56-
### Features
57-
58-
* allow running `ngcc` with specific `tsconfig` path ([#1418](https://github.com/thymikee/jest-preset-angular/issues/1418)) ([5f535b5](https://github.com/thymikee/jest-preset-angular/commit/5f535b59227daea6e64e4886b0ea0bd5fd7c1365)), closes [#1348](https://github.com/thymikee/jest-preset-angular/issues/1348)
59-
* allow skip `ngcc` via `skipNgcc` option via `globalThis` ([#1417](https://github.com/thymikee/jest-preset-angular/issues/1417)) ([7950b5c](https://github.com/thymikee/jest-preset-angular/commit/7950b5cedfab066a268b16f5c87b5ad3670c6888)), closes [#1396](https://github.com/thymikee/jest-preset-angular/issues/1396)
60-
61-
62-
63-
# [12.0.0-next.0](https://github.com/thymikee/jest-preset-angular/compare/v11.1.1...v12.0.0-next.0) (2022-04-24)
64-
65-
66-
### Features
67-
68-
* remove `ngcc-jest-processor` entry file ([#1414](https://github.com/thymikee/jest-preset-angular/issues/1414)) ([2c5fd20](https://github.com/thymikee/jest-preset-angular/commit/2c5fd20f0535f5441d8bcb477538defdd9529926))
69-
70-
71-
## BREAKING CHANGES
72-
73-
* Drop Angular 10 support
74-
* Require Jest 28
44+
* **Angular 10** is no longer support
45+
* Require **Jest 28**
7546
* `ngcc-jest-processor` entry file is now removed. One should use `jest-preset-angular/global-setup` instead.
7647

7748

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-preset-angular",
3-
"version": "12.0.0-next.2",
3+
"version": "12.0.0",
44
"description": "Jest preset configuration for Angular projects",
55
"license": "MIT",
66
"engines": {

website/docs/getting-started/presets.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ All presets come with default `ts-jest` config options.
4545
If you want to override any of the options, you'll need to use the JavaScript version of Jest config,
4646
copy the original options and override the options you need:
4747

48+
:::important
49+
50+
If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest`
51+
options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get
52+
errors.
53+
54+
:::
55+
4856
```js
4957
// jest.config.js
5058
const { defaults: jestNgPreset } = require('jest-preset-angular/presets');
@@ -81,11 +89,3 @@ const config: InitialOptionsTsJest = {
8189

8290
export default config;
8391
```
84-
85-
:::important
86-
87-
If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest`
88-
options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get
89-
errors.
90-
91-
:::

website/docs/getting-started/test-environment.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ id: test-environment
33
title: Test environment
44
---
55

6-
If you look at [`setup-jest.ts`](https://github.com/thymikee/jest-preset-angular/blob/main/src/config/setup-jest.ts),
7-
what we're doing here is we're adding globals required by Angular. With the included [jest-zone-patch](https://github.com/thymikee/jest-preset-angular/tree/main/src/zone-patch)
6+
If you look at [`setup-jest.js`](https://github.com/thymikee/jest-preset-angular/blob/main/setup-jest.js),
7+
what we're doing here is we're adding globals required by Angular. With the included [Angular zone patch](https://github.com/angular/angular/tree/main/packages/zone.js)
88
we also make sure Jest test methods run in Zone context. Then we initialize the Angular testing environment like normal.
9+
10+
While `setup-jest.js` above is for running Jest with **CommonJS** mode, we also provide [`setup-jest.mjs`](https://github.com/thymikee/jest-preset-angular/blob/main/setup-jest.mjs)
11+
to run with **ESM** mode.

website/versioned_docs/version-10.x/getting-started/presets.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ All presets come with default `ts-jest` config options.
4545
If you want to override any of the options, you'll need to use the JavaScript version of Jest config,
4646
copy the original options and override the options you need:
4747

48+
:::important
49+
50+
If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest`
51+
options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get
52+
errors.
53+
54+
:::
55+
4856
```js
4957
// jest.config.js
5058
const { defaults: jestNgPreset } = require('jest-preset-angular/presets');
@@ -81,11 +89,3 @@ const config: InitialOptionsTsJest = {
8189

8290
export default config;
8391
```
84-
85-
:::important
86-
87-
If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest`
88-
options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get
89-
errors.
90-
91-
:::

website/versioned_docs/version-11.0/getting-started/presets.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ All presets come with default `ts-jest` config options.
4545
If you want to override any of the options, you'll need to use the JavaScript version of Jest config,
4646
copy the original options and override the options you need:
4747

48+
:::important
49+
50+
If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest`
51+
options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get
52+
errors.
53+
54+
:::
55+
4856
```js
4957
// jest.config.js
5058
const { defaults: jestNgPreset } = require('jest-preset-angular/presets');
@@ -81,11 +89,3 @@ const config: InitialOptionsTsJest = {
8189

8290
export default config;
8391
```
84-
85-
:::important
86-
87-
If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest`
88-
options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get
89-
errors.
90-
91-
:::

website/versioned_docs/version-11.1/getting-started/presets.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ All presets come with default `ts-jest` config options.
4545
If you want to override any of the options, you'll need to use the JavaScript version of Jest config,
4646
copy the original options and override the options you need:
4747

48+
:::important
49+
50+
If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest`
51+
options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get
52+
errors.
53+
54+
:::
55+
4856
```js
4957
// jest.config.js
5058
const { defaults: jestNgPreset } = require('jest-preset-angular/presets');
@@ -81,11 +89,3 @@ const config: InitialOptionsTsJest = {
8189

8290
export default config;
8391
```
84-
85-
:::important
86-
87-
If you choose to override `globals` in order to point at a specific tsconfig, you will need to make sure that original `ts-jest`
88-
options provided through the default preset are defined to the `globals.ts-jest` section too, otherwise you will get
89-
errors.
90-
91-
:::
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
id: installation
3+
title: Installation
4+
---
5+
6+
### Dependencies
7+
8+
You can install `jest-preset-angular` and dependencies all at once with one of the following commands.
9+
10+
#### NPM
11+
12+
```sh
13+
npm install -D jest jest-preset-angular @types/jest
14+
```
15+
16+
#### Yarn
17+
18+
```sh
19+
yarn add -D jest jest-preset-angular @types/jest
20+
```
21+
22+
### Configuration
23+
24+
In your project root, create `setup-jest.ts` file with following contents:
25+
26+
```ts
27+
import 'jest-preset-angular/setup-jest';
28+
```
29+
30+
Add the following section:
31+
32+
- to your root `jest.config.js`
33+
34+
```js
35+
// jest.config.js
36+
module.exports = {
37+
preset: 'jest-preset-angular',
38+
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
39+
globalSetup: 'jest-preset-angular/global-setup',
40+
};
41+
```
42+
43+
- or to your root `package.json`
44+
45+
```json
46+
{
47+
"jest": {
48+
"preset": "jest-preset-angular",
49+
"setupFilesAfterEnv": ["<rootDir>/setup-jest.ts"],
50+
"globalSetup": "jest-preset-angular/global-setup"
51+
}
52+
}
53+
```
54+
55+
Adjust your `tsconfig.spec.json` to be:
56+
57+
```json
58+
{
59+
"extends": "./tsconfig.json",
60+
"compilerOptions": {
61+
"outDir": "./out-tsc/spec",
62+
"module": "CommonJs",
63+
"types": ["jest"]
64+
},
65+
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
66+
}
67+
```
68+
69+
### Customizing
70+
71+
#### Global mocks
72+
73+
`jest-preset-angular` uses `JSDOM` which is different from normal browsers. You might need some global browser mocks to
74+
stimulate the behaviors of real browsers in `JSDOM`. To add global mocks, you can do the following:
75+
76+
- Create a file `jest-global-mocks.ts` to your root project.
77+
- Import it in your global setup file:
78+
79+
```ts
80+
// Assuming that your global setup file is setup-jest.ts
81+
import 'jest-preset-angular/setup-jest';
82+
import './jest-global-mocks';
83+
```
84+
85+
:::tip
86+
87+
An example for `jest-global-mocks.ts`
88+
89+
```
90+
Object.defineProperty(window, 'CSS', { value: null });
91+
Object.defineProperty(document, 'doctype', {
92+
value: '<!DOCTYPE html>',
93+
});
94+
Object.defineProperty(window, 'getComputedStyle', {
95+
value: () => {
96+
return {
97+
display: 'none',
98+
appearance: ['-webkit-appearance'],
99+
};
100+
},
101+
});
102+
/**
103+
* ISSUE: https://github.com/angular/material2/issues/7101
104+
* Workaround for JSDOM missing transform property
105+
*/
106+
Object.defineProperty(document.body.style, 'transform', {
107+
value: () => {
108+
return {
109+
enumerable: true,
110+
configurable: true,
111+
};
112+
},
113+
});
114+
```
115+
116+
:::
117+
118+
#### Avoid karma conflicts
119+
120+
By Angular CLI defaults you'll have a `src/test.ts` file which will be picked up by jest. To circumvent this you can either rename it to `src/karmaTest.ts` or hide it from jest by adding `<rootDir>/src/test.ts` to jest `testPathIgnorePatterns` option.

0 commit comments

Comments
 (0)