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

[DO NOT MERGE] Trigger CI for #4396: chore: migrate from jest to vitest #4410

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bcf86b9
chore: test @lwc/shared with vitest
cardoso Jul 21, 2024
c678adf
chore: migrate @lwc/style-compiler to vitest
cardoso Jul 21, 2024
df4fb25
chore: migrate @lwc/errors to vitest
cardoso Jul 21, 2024
ba32129
chore: migrate @lwc/features to vitest
cardoso Jul 21, 2024
c547611
chore: migrate @lwc/signals to vitest
cardoso Jul 21, 2024
045acda
chore: migrate @lwc/rollup-plugin to vitest
cardoso Jul 21, 2024
32ce3fa
chore: migrate @lwc/engine-core to vitest
cardoso Jul 21, 2024
9407101
chore: migrate @lwc/engine-dom to vitest
cardoso Jul 21, 2024
a28c0a0
chore: migrate @lwc/compiler to vitest
cardoso Jul 21, 2024
cf3b131
chore: migrate @lwc/babel-plugin-component to vitest
cardoso Jul 21, 2024
dddc404
chore: add vitest coverage
cardoso Jul 22, 2024
4bcae68
Merge branch 'master' of https://github.com/salesforce/lwc into vitest
cardoso Jul 24, 2024
ebc40ec
chore: migrate @lwc/template-compiler to vitest
cardoso Jul 24, 2024
f6669f9
chore: use .ts for vitest workspace config
cardoso Jul 24, 2024
de4cb42
chore: change test scripts to vitest
cardoso Jul 24, 2024
4909030
chore: change vitest shared config to ts
cardoso Jul 24, 2024
1c3d5fc
chore: migrate @lwc/module-resolver to vitest
cardoso Jul 24, 2024
147904a
chore: remove rollup plugins from shared vitest config
cardoso Jul 25, 2024
78e5639
chore: migrate @lwc/engine-server to vitest
cardoso Jul 25, 2024
321c1d5
chore: set lwc engine-server hooks in mock
cardoso Jul 25, 2024
eb7319a
chore: migrate lwc package to vitest
cardoso Jul 25, 2024
b3df5b2
Merge remote-tracking branch 'origin/master' into vitest
nolanlawson Jul 25, 2024
a5e2e6d
fix: allow for testing @lwc/ssr-compiler with env var
nolanlawson Jul 25, 2024
a804c83
test: fix inline snapshot
nolanlawson Jul 25, 2024
00b229f
test: remove jest entirely
nolanlawson Jul 25, 2024
5d4aa0e
test: fix lwc package
nolanlawson Jul 25, 2024
00236a6
test: make yarn test run in interactive mode
nolanlawson Jul 25, 2024
2372384
test: make vitest globals work in the IDE
nolanlawson Jul 25, 2024
d4b1aed
test: rename from jest to test
nolanlawson Jul 25, 2024
6b20fd8
test: remove unnecessary config
nolanlawson Jul 25, 2024
0329a43
test: fix test:types
nolanlawson Jul 25, 2024
3f48a35
Merge remote-tracking branch 'origin/master' into vitest
nolanlawson Jul 26, 2024
ee4f3ab
fix: use .mjs to avoid warning and do not import all rollup plugins
nolanlawson Jul 26, 2024
98b6d78
fix: avoid rollup plugins entirely
nolanlawson Jul 26, 2024
5a6e294
fix: fix coverage tests
nolanlawson Jul 26, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
12 changes: 0 additions & 12 deletions packages/@lwc/babel-plugin-component/jest.config.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
21 changes: 21 additions & 0 deletions packages/@lwc/babel-plugin-component/vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -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),
},
})
);
12 changes: 0 additions & 12 deletions packages/@lwc/compiler/jest.config.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = `
<template>
<x-dynamic lwc:dynamic={ctor}></x-dynamic>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { noop } from '@lwc/shared';
import { TransformOptions } from '../../options';
import { transform, transformSync } from '../transformer';
Expand Down Expand Up @@ -121,7 +122,7 @@ it('should not apply babel plugins when Lightning Web Security is off', async ()

describe('instrumentation', () => {
it('should gather metrics for transforming dynamic imports', async () => {
const incrementCounter = jest.fn();
const incrementCounter = vi.fn();
const actual = `
export async function test() {
const x = await import("foo");
Expand Down
16 changes: 16 additions & 0 deletions packages/@lwc/compiler/vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineProject, mergeConfig } from 'vitest/config';
import baseConfig from '../../../vitest.shared.mjs';

export default mergeConfig(
baseConfig,
defineProject({
test: {
name: 'lwc-compiler',
// 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',
},
},
})
);
14 changes: 0 additions & 14 deletions packages/@lwc/engine-core/jest.config.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/@lwc/engine-core/vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineProject, mergeConfig } from 'vitest/config';
import baseConfig from '../../../vitest.shared.mjs';

export default mergeConfig(
baseConfig,
defineProject({
test: {
name: 'lwc-engine-core',
},
})
);
14 changes: 0 additions & 14 deletions packages/@lwc/engine-dom/jest.config.js

This file was deleted.

12 changes: 12 additions & 0 deletions packages/@lwc/engine-dom/vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineProject, mergeConfig } from 'vitest/config';
import baseConfig from '../../../vitest.shared.mjs';

export default mergeConfig(
baseConfig,
defineProject({
test: {
name: 'lwc-engine-dom',
environment: 'jsdom',
},
})
);
17 changes: 0 additions & 17 deletions packages/@lwc/engine-server/jest.config.js

This file was deleted.

31 changes: 16 additions & 15 deletions packages/@lwc/engine-server/src/__tests__/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import path from 'path';

import { rollup } from 'rollup';
import lwcRollupPlugin from '@lwc/rollup-plugin';
import { testFixtureDir, formatHTML } from '@lwc/jest-utils-lwc-internals';
import { vi } from 'vitest';
import { testFixtureDir, formatHTML } from '@lwc/test-utils-lwc-internals';
import type * as lwc from '../index';

interface FixtureModule {
Expand All @@ -20,7 +21,17 @@ interface FixtureModule {
features?: any[];
}

jest.setTimeout(10_000 /* 10 seconds */);
vi.setConfig({ testTimeout: 10_000 /* 10 seconds */ });

vi.mock('lwc', async () => {
const lwcEngineServer = await import('../index');
lwcEngineServer!.setHooks({
sanitizeHtmlContent(content: unknown) {
return content as string;
},
});
return lwcEngineServer;
});

async function compileFixture({ input, dirname }: { input: string; dirname: string }) {
const modulesDir = path.resolve(dirname, './modules');
Expand Down Expand Up @@ -49,7 +60,7 @@ async function compileFixture({ input, dirname }: { input: string; dirname: stri

await bundle.write({
file: outputFile,
format: 'cjs',
format: 'esm',
exports: 'named',
});

Expand Down Expand Up @@ -80,24 +91,14 @@ function testFixtures() {
// On top of this, the engine also checks if the component constructor is an instance of
// the LightningElement. Therefor the compiled module should also be evaluated in the
// same sandbox registry as the engine.
let lwcEngineServer: typeof lwc | undefined;
let module: FixtureModule | undefined;
jest.isolateModules(() => {
lwcEngineServer = require('../index');
module = require(compiledFixturePath);
});
const lwcEngineServer = await import('../index');
const module = (await import(compiledFixturePath)) as FixtureModule;

const features = module!.features ?? [];
features.forEach((flag) => {
lwcEngineServer!.setFeatureFlagForTest(flag, true);
});

lwcEngineServer!.setHooks({
sanitizeHtmlContent(content: unknown) {
return content as string;
},
});

let result;
let err;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { rollup, RollupLog } from 'rollup';
import replace from '@rollup/plugin-replace';
import virtual from '@rollup/plugin-virtual';
import lwcRollupPlugin from '@lwc/rollup-plugin';
import { vi } from 'vitest';
import * as engineServer from '../index';

/**
Expand All @@ -20,7 +21,7 @@ import * as engineServer from '../index';
* robust than snapshots, which may have invalid/incorrect HTML.
*/

jest.setTimeout(10_000 /* 10 seconds */);
vi.setConfig({ testTimeout: 10_000 /* 10 seconds */ });

// Compile a component to an HTML string, using the full LWC compilation pipeline
async function compileComponent(tagName: string, componentName: string) {
Expand Down
11 changes: 11 additions & 0 deletions packages/@lwc/engine-server/vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineProject, mergeConfig } from 'vitest/config';
import baseConfig from '../../../vitest.shared.mjs';

export default mergeConfig(
baseConfig,
defineProject({
test: {
name: 'lwc-engine-server',
},
})
);
12 changes: 0 additions & 12 deletions packages/@lwc/errors/jest.config.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/@lwc/errors/vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../../../vitest.shared.mjs';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: 'lwc-errors',
},
})
);
15 changes: 0 additions & 15 deletions packages/@lwc/features/jest.config.js

This file was deleted.

Loading
Loading