Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Jest@28 #152

Merged
merged 9 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2.1

supported-jest-versions: &supported-jest-versions ["local", "26", "27"]
supported-jest-versions: &supported-jest-versions ["local", "26", "27", "28"]

deploy_filters: &deploy_filters
filters:
Expand All @@ -15,7 +15,7 @@ executors:
node:
working_directory: ~/lwc-test
docker:
- image: circleci/node:14
- image: cimg/node:14.19


commands:
Expand Down Expand Up @@ -59,7 +59,14 @@ jobs:
steps:
- run:
name: Override version of jest@<<parameters.jest-version>>
command: yarn add jest@<<parameters.jest-version>> -W --dev
command: |
yarn remove jest jest-environment-jsdom -W --dev
yarn add jest@<<parameters.jest-version>> -W --dev
- when:
condition:
equal: [<<parameters.jest-version>>, "28"]
steps:
- run: yarn add jest-environment-jsdom@<<parameters.jest-version>> -W --dev
- run:
name: Run linter
command: yarn lint
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"@lwc/wire-service": "^2.11.3",
"@types/jest": "^27.5.0",
"eslint": "^8.14.0",
"jest": "^27.5.1",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"lerna": "^4.0.0",
"prettier": "^2.6.2"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/@lwc/jest-preset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Tools to assist with testing Lightning Web Components (LWC) with Jest. This proj
yarn add --dev @lwc/jest-preset @lwc/compiler @lwc/engine-dom @lwc/synthetic-shadow
```

If your project is using **Jest 28** and above, you will also need install `jest-environment-jsdom` separately:

```
yarn add --dev jest-environment-jsdom
```

### Configuration

Add the preset to your `jest.config.js` like so:
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/jest-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@lwc/compiler": "*",
"@lwc/engine-dom": "*",
"@lwc/synthetic-shadow": "*",
"jest": "^26 || ^27"
"jest": "^26 || ^27 || ^28"
},
"dependencies": {
"@lwc/jest-resolver": "11.3.0",
Expand Down
12 changes: 9 additions & 3 deletions packages/@lwc/jest-preset/src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ const config = global['lwc-jest'] || {};
const { nativeShadow } = config;

if (!nativeShadow) {
if (ShadowRoot.prototype.constructor.toString().includes('function SyntheticShadowRoot')
|| EventTarget.prototype.addEventListener.toString().includes('function patchedAddEventListener')) {
throw new Error('@lwc/synthetic-shadow is being loaded twice. Please examine your jest/jsdom configuration.')
if (
ShadowRoot.prototype.constructor.toString().includes('function SyntheticShadowRoot') ||
EventTarget.prototype.addEventListener
.toString()
.includes('function patchedAddEventListener')
) {
throw new Error(
'@lwc/synthetic-shadow is being loaded twice. Please examine your jest/jsdom configuration.'
);
}
require('@lwc/synthetic-shadow/dist/synthetic-shadow.js');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/jest-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"/src/index.js"
],
"peerDependencies": {
"jest": "^26 || ^27"
"jest": "^26 || ^27 || ^28"
},
"engines": {
"node": ">=10"
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/jest-resolver/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function isImplicitHTMLImport(importee, { basedir }) {
function getLwcPath(path, options) {
if (path.endsWith('?scoped=true')) {
// remove query param for scoped styles
path = path.substring(0, path.length - 12)
path = path.substring(0, path.length - 12);
}
// If is a special LWC package, resolve it from commonjs
if (WHITELISTED_LWC_PACKAGES[path]) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/jest-serializer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"lwc"
],
"dependencies": {
"pretty-format": "^27.4.6"
"pretty-format": "^28.1.0"
},
"peerDependencies": {
"jest": "^26 || ^27"
"jest": "^26 || ^27 || ^28"
},
"engines": {
"node": ">=10"
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/jest-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"peerDependencies": {
"@lwc/compiler": "*",
"jest": "^26 || ^27"
"jest": "^26 || ^27 || ^28"
},
"engines": {
"node": ">=10"
Expand Down
Loading