diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index ad14e65f60..bb109260b9 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -64,12 +64,12 @@ jobs: run: yarn bundlesize - name: Check types run: yarn test:types - - name: Run Jest tests + - name: Run unit tests run: yarn test:ci - - name: Upload Jest coverage report + - name: Upload unit test coverage report uses: actions/upload-artifact@v3 with: - name: jest-coverage-report + name: test-coverage-report path: coverage/ - name: Run benchmark smoke tests run: CHROME_BINARY=${{ steps.setup-chrome.outputs.chrome-path }} BENCHMARK_SMOKE_TEST=1 yarn test:performance diff --git a/package.json b/package.json index 1e1f40b850..049275c002 100644 --- a/package.json +++ b/package.json @@ -18,10 +18,10 @@ "build:performance:benchmarks": "nx build @lwc/perf-benchmarks", "copy-fork": "./scripts/tasks/unsafe-external-contributor-ci-workaround.sh", "dev": "nx run-many --target=dev --all --parallel=999 --exclude=@lwc/perf-benchmarks,@lwc/perf-benchmarks-components,@lwc/integration-tests,lwc", - "test": "jest --config ./scripts/jest/root.config.js", + "test": "vitest --workspace vitest.workspace.mjs", "test:bespoke": "nx run-many --target=test", - "test:debug": "node --inspect node_modules/.bin/jest --config ./scripts/jest/root.config.js --runInBand --watch", - "test:ci": "yarn test --no-cache --coverage --runInBand", + "test:debug": "vitest --workspace vitest.workspace.mjs --inspect-brk --no-file-parallelism", + "test:ci": "vitest run --workspace vitest.workspace.mjs --coverage", "test:karma": "nx test @lwc/integration-karma", "test:integration": "nx sauce @lwc/integration-tests", "test:performance": "nx test @lwc/perf-benchmarks", @@ -39,16 +39,17 @@ "@eslint/compat": "^1.1.1", "@eslint/js": "^9.7.0", "@lwc/eslint-plugin-lwc-internal": "link:./scripts/eslint-plugin", - "@lwc/jest-utils-lwc-internals": "link:./scripts/jest/utils", + "@lwc/test-utils-lwc-internals": "link:./scripts/test-utils", "@rollup/plugin-commonjs": "^26.0.1", "@rollup/plugin-inject": "^5.0.5", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-replace": "^5.0.7", "@rollup/plugin-typescript": "^11.1.6", "@types/babel__core": "^7.20.5", - "@types/jest": "^29.5.12", "@types/node": "^20.14.11", "@types/prettier": "^2.7.3", + "@vitest/coverage-v8": "^2.0.3", + "@vitest/ui": "^2.0.3", "bytes": "^3.1.2", "es-module-lexer": "^1.5.4", "eslint": "^9.7.0", @@ -60,18 +61,17 @@ "globals": "^15.8.0", "husky": "^9.1.1", "isbinaryfile": "^5.0.2", - "jest": "^29.7.0", - "jest-environment-jsdom": "^29.7.0", + "jsdom": "^24.1.1", "lint-staged": "^15.2.7", "magic-string": "^0.30.10", "nx": "19.5.1", "prettier": "^2.8.8", "rollup": "^4.19.0", "terser": "^5.31.3", - "ts-jest": "^29.2.3", "tslib": "^2.6.3", "typescript": "5.5.3", - "typescript-eslint": "^7.16.1" + "typescript-eslint": "^7.16.1", + "vitest": "^2.0.3" }, "lint-staged": { "*.{js,mjs,ts}": "eslint", diff --git a/packages/@lwc/babel-plugin-component/jest.config.js b/packages/@lwc/babel-plugin-component/jest.config.js deleted file mode 100644 index cb34547936..0000000000 --- a/packages/@lwc/babel-plugin-component/jest.config.js +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ -const BASE_CONFIG = require('../../../scripts/jest/base.config'); - -module.exports = { - ...BASE_CONFIG, - displayName: 'babel-plugin-component', -}; diff --git a/packages/@lwc/babel-plugin-component/src/__tests__/index.spec.ts b/packages/@lwc/babel-plugin-component/src/__tests__/index.spec.ts index 89f295736f..da96012f26 100644 --- a/packages/@lwc/babel-plugin-component/src/__tests__/index.spec.ts +++ b/packages/@lwc/babel-plugin-component/src/__tests__/index.spec.ts @@ -8,7 +8,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { transformSync } from '@babel/core'; import { LWC_VERSION, HIGHEST_API_VERSION } from '@lwc/shared'; -import { testFixtureDir } from '@lwc/jest-utils-lwc-internals'; +import { testFixtureDir } from '@lwc/test-utils-lwc-internals'; import plugin from '../index'; const BASE_OPTS = { diff --git a/packages/@lwc/babel-plugin-component/vitest.config.mjs b/packages/@lwc/babel-plugin-component/vitest.config.mjs new file mode 100644 index 0000000000..a5a963a4d0 --- /dev/null +++ b/packages/@lwc/babel-plugin-component/vitest.config.mjs @@ -0,0 +1,21 @@ +import { mergeConfig, defineProject } from 'vitest/config'; +import sharedConfig from '../../../vitest.shared.mjs'; +import pkg from '../../../package.json'; +const LWC_VERSION = pkg.version; + +export default mergeConfig( + sharedConfig, + defineProject({ + test: { + name: 'babel-plugin-component', + // Workaround to fix `const enum`, which is required because we use e.g. `APIFeature` from `@lwc/shared` + // See https://github.com/vitest-dev/vitest/discussions/3964 + alias: { + '@lwc/shared': '@lwc/shared/src', + }, + }, + define: { + 'process.env.LWC_VERSION': JSON.stringify(LWC_VERSION), + }, + }) +); diff --git a/packages/@lwc/compiler/jest.config.js b/packages/@lwc/compiler/jest.config.js deleted file mode 100644 index 1288a49391..0000000000 --- a/packages/@lwc/compiler/jest.config.js +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ -const BASE_CONFIG = require('../../../scripts/jest/base.config'); - -module.exports = { - ...BASE_CONFIG, - displayName: 'lwc-compiler', -}; diff --git a/packages/@lwc/compiler/src/transformers/__tests__/transform-html.spec.ts b/packages/@lwc/compiler/src/transformers/__tests__/transform-html.spec.ts index 1af4ae7ff3..ed7ea2a68c 100644 --- a/packages/@lwc/compiler/src/transformers/__tests__/transform-html.spec.ts +++ b/packages/@lwc/compiler/src/transformers/__tests__/transform-html.spec.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ +import { vi } from 'vitest'; import { APIVersion, noop } from '@lwc/shared'; import { TransformOptions } from '../../options'; import { transformSync } from '../transformer'; @@ -199,12 +200,12 @@ describe('transformSync', () => { ...TRANSFORMATION_OPTIONS, }) ).toThrowErrorMatchingInlineSnapshot( - '"LWC1128: Invalid lwc:dynamic usage. The LWC dynamic directive must be enabled in order to use this feature."' + `[Error: LWC1128: Invalid lwc:dynamic usage. The LWC dynamic directive must be enabled in order to use this feature.]` ); }); it('gathers metrics around use of the deprecated dynamic components', () => { - const incrementCounter = jest.fn(); + const incrementCounter = vi.fn(); const template = `