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: Start migration from jest to vitest #4398

Closed
wants to merge 11 commits into from
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"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:vi": "vitest run --workspace vitest.workspace.js",
"test:vi:ci": "vitest run --workspace vitest.workspace.js --coverage",
"test": "jest --config ./scripts/jest/root.config.js",
"test:bespoke": "nx run-many --target=test",
"test:debug": "node --inspect node_modules/.bin/jest --config ./scripts/jest/root.config.js --runInBand --watch",
Expand Down Expand Up @@ -49,6 +51,8 @@
"@types/jest": "^29.5.12",
"@types/node": "^20.14.10",
"@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 @@ -71,7 +75,8 @@
"ts-jest": "^29.2.2",
"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
11 changes: 11 additions & 0 deletions packages/@lwc/babel-plugin-component/vitest.config.js
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';

export default mergeConfig(
baseConfig,
defineProject({
test: {
name: 'babel-plugin-component',
},
})
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`transformSync > dynamic components > should not allow dynamic components when experimentalDynamicDirective is set to false > "LWC1128: Invalid lwc:dynamic usage. The LWC dynamic directive must be enabled in order to use this feature." 1`] = `[Error: LWC1128: Invalid lwc:dynamic usage. The LWC dynamic directive must be enabled in order to use this feature.]`;
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 @@ -198,13 +199,13 @@ describe('transformSync', () => {
experimentalDynamicDirective: false,
...TRANSFORMATION_OPTIONS,
})
).toThrowErrorMatchingInlineSnapshot(
).toThrowErrorMatchingSnapshot(
'"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
14 changes: 14 additions & 0 deletions packages/@lwc/compiler/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineProject, mergeConfig } from 'vitest/config';
import baseConfig from '../../../vitest.shared';

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

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

export default mergeConfig(
baseConfig,
defineProject({
test: {
name: 'lwc-engine-dom',
environment: 'jsdom',
},
})
);
11 changes: 11 additions & 0 deletions packages/@lwc/errors/vitest.config.js
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';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: 'lwc-errors',
},
})
);
9 changes: 5 additions & 4 deletions packages/@lwc/features/src/__tests__/setFeatureFlag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { MockInstance, vi } from 'vitest';
import { lwcRuntimeFlags, setFeatureFlag } from '../index';

describe('setFeatureFlag', () => {
['development', 'production'].forEach((env) => {
describe(`${env} mode`, () => {
let originalNodeEnv: any;
let info: jest.SpyInstance;
let error: jest.SpyInstance;
let info: MockInstance;
let error: MockInstance;

beforeEach(() => {
originalNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = env;
info = jest.spyOn(console, 'info').mockImplementation(() => {});
error = jest.spyOn(console, 'error').mockImplementation(() => {});
info = vi.spyOn(console, 'info').mockImplementation(() => {});
error = vi.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(() => {
Expand Down
11 changes: 11 additions & 0 deletions packages/@lwc/features/vitest.config.js
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';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: 'lwc-features',
},
})
);
14 changes: 14 additions & 0 deletions packages/@lwc/rollup-plugin/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineProject, mergeConfig } from 'vitest/config';
import baseConfig from '../../../vitest.shared';

export default mergeConfig(
baseConfig,
defineProject({
test: {
name: 'rollup-plugin-lwc-compiler',
alias: {
'@lwc/shared': '@lwc/shared/src',
},
},
})
);
11 changes: 11 additions & 0 deletions packages/@lwc/shared/vitest.config.js
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';

export default mergeConfig(
baseConfig,
defineProject({
test: {
name: 'lwc-shared',
},
})
);
13 changes: 7 additions & 6 deletions packages/@lwc/signals/src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { vi } from 'vitest';
import { Signal } from './signal';

describe('signal protocol', () => {
Expand All @@ -17,29 +18,29 @@ describe('signal protocol', () => {
const s = new Signal();
expect('subscribe' in s).toBe(true);
expect(typeof s.subscribe).toBe('function');
const onUpdate = jest.fn();
const onUpdate = vi.fn();
expect(() => s.subscribe(onUpdate)).not.toThrow();
});

it('should be able to notify subscribers', () => {
const s = new Signal();
const onUpdate = jest.fn();
const onUpdate = vi.fn();
s.subscribe(onUpdate);
s.value = 1;
expect(onUpdate).toHaveBeenCalledTimes(1);
});

it('subscribe should return an unsubscribe function', () => {
const s = new Signal();
const onUpdate = jest.fn();
const onUpdate = vi.fn();
const unsubscribe = s.subscribe(onUpdate);
expect(typeof unsubscribe).toBe('function');
});

it('should not notify once unsubscribed', () => {
const s = new Signal(0);
const onUpdate1 = jest.fn();
const onUpdate2 = jest.fn();
const onUpdate1 = vi.fn();
const onUpdate2 = vi.fn();
const unsubscribe1 = s.subscribe(onUpdate1);
const unsubscribe2 = s.subscribe(onUpdate2);

Expand All @@ -62,7 +63,7 @@ describe('signal protocol', () => {

it('SignalBaseClass does not subscribe duplicate OnUpdate callback functions', () => {
const s = new Signal(0);
const onUpdate = jest.fn();
const onUpdate = vi.fn();
s.subscribe(onUpdate);
s.subscribe(onUpdate);

Expand Down
11 changes: 11 additions & 0 deletions packages/@lwc/signals/vitest.config.js
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';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: 'lwc-signals',
},
})
);
11 changes: 11 additions & 0 deletions packages/@lwc/style-compiler/vitest.config.js
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';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: 'lwc-style-compiler',
},
})
);
Loading