Skip to content

Commit 5158fd4

Browse files
committed
chore: simplify jest config
1 parent 893f548 commit 5158fd4

File tree

11 files changed

+174
-66
lines changed

11 files changed

+174
-66
lines changed

.codesandbox/ci.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"node": "16",
2+
"node": "20",
33
"publishDirectory": {
44
"@alauda/ui": "release"
55
},

.github/workflows/release-beta.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v3
1717
with:
18-
node-version: 16
18+
node-version: 20
1919
cache: yarn
2020

2121
- name: Install dependencies

.github/workflows/release-prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Node.js
1919
uses: actions/setup-node@v3
2020
with:
21-
node-version: 16
21+
node-version: 20
2222
cache: yarn
2323

2424
- name: Install dependencies

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup Node.js
2020
uses: actions/setup-node@v3
2121
with:
22-
node-version: 16
22+
node-version: 20
2323
cache: yarn
2424

2525
- name: Install Dependencies

.github/workflows/stories.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v3
1717
with:
18-
node-version: 16
18+
node-version: 20
1919
cache: yarn
2020

2121
- name: Install dependencies

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup Node.js
1414
uses: actions/setup-node@v3
1515
with:
16-
node-version: 16
16+
node-version: 20
1717
cache: yarn
1818

1919
- name: Install Dependencies

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

jest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { Config } from '@jest/types';
22

33
const config: Config.InitialOptions = {
44
preset: 'jest-preset-angular',
5-
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
65
testMatch: ['<rootDir>/src/**/+(*.)+(spec|test).+(ts|js)?(x)'],
6+
testEnvironment: 'jsdom',
7+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
78
coverageReporters: ['text', 'html'],
89
coverageDirectory: '<rootDir>/coverage',
910
modulePathIgnorePatterns: [

jest.setup.ts

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,24 @@
11
import 'jest-preset-angular/setup-jest';
22

3-
import { getTestBed } from '@angular/core/testing';
4-
import {
5-
BrowserDynamicTestingModule,
6-
platformBrowserDynamicTesting,
7-
} from '@angular/platform-browser-dynamic/testing';
8-
9-
getTestBed().resetTestEnvironment();
10-
getTestBed().initTestEnvironment(
11-
BrowserDynamicTestingModule,
12-
platformBrowserDynamicTesting(),
13-
{ teardown: { destroyAfterEach: false } },
14-
);
15-
16-
Object.defineProperty(document, 'doctype', {
17-
value: '<!DOCTYPE html>',
18-
});
19-
20-
Object.defineProperty(window, 'CSS', { value: null });
21-
22-
Object.defineProperty(window, 'getComputedStyle', {
23-
value() {
24-
return {
25-
display: 'none',
26-
appearance: ['-webkit-appearance'],
27-
};
3+
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
4+
globalThis.ngJest = {
5+
testEnvironmentOptions: {
6+
errorOnUnknownElements: true,
7+
errorOnUnknownProperties: true,
288
},
29-
});
9+
};
3010

11+
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
3112
Object.defineProperty(window, 'matchMedia', {
32-
value() {
33-
return {
34-
matches: 'light',
35-
addListener: () => undefined as void,
36-
addEventListener: () => undefined as void,
37-
};
38-
},
39-
});
40-
41-
/**
42-
* ISSUE: https://github.com/angular/material2/issues/7101
43-
* Workaround for JSDOM missing transform property
44-
*/
45-
Object.defineProperty(document.body.style, 'transform', {
46-
value() {
47-
return {
48-
enumerable: true,
49-
configurable: true,
50-
};
51-
},
13+
writable: true,
14+
value: jest.fn().mockImplementation(query => ({
15+
matches: false,
16+
media: query,
17+
onchange: null,
18+
addListener: jest.fn(), // deprecated
19+
removeListener: jest.fn(), // deprecated
20+
addEventListener: jest.fn(),
21+
removeEventListener: jest.fn(),
22+
dispatchEvent: jest.fn(),
23+
})),
5224
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"JounQin <[email protected]> (https://www.1stG.me)"
1010
],
1111
"license": "MIT",
12+
"packageManager": "[email protected]",
1213
"keywords": [
1314
"alauda",
1415
"angular",
@@ -88,6 +89,7 @@
8889
"jest": "^29.6.4",
8990
"jest-junit": "^16.0.0",
9091
"jest-preset-angular": "^13.1.1",
92+
"jsdom": "^23.2.0",
9193
"lint-staged": "^14.0.1",
9294
"ng-packagr": "^16.2.2",
9395
"npm-run-all": "^4.1.5",

0 commit comments

Comments
 (0)