-
Notifications
You must be signed in to change notification settings - Fork 392
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
chore: migrate from jest to vitest #4396
Changes from 39 commits
bcf86b9
c678adf
df4fb25
ba32129
c547611
045acda
32ce3fa
9407101
a28c0a0
cf3b131
dddc404
4bcae68
ebc40ec
f6669f9
de4cb42
4909030
1c3d5fc
147904a
78e5639
321c1d5
eb7319a
b3df5b2
a5e2e6d
a804c83
00b229f
5d4aa0e
00236a6
2372384
d4b1aed
6b20fd8
0329a43
3f48a35
ee4f3ab
98b6d78
5a6e294
1f306bc
6550ff9
ce2beae
39def4e
74351ce
4fd44e7
3b2954e
7457eb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { mergeConfig, defineProject } from 'vitest/config'; | ||
import sharedConfig from '../../../vitest.shared.mjs'; | ||
import pkg from './package.json'; | ||
|
||
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` | ||
nolanlawson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// See https://github.com/vitest-dev/vitest/discussions/3964 | ||
// Using `src` also ensures that the test coverage is accurately reported | ||
alias: Object.fromEntries( | ||
Object.keys(pkg.dependencies ?? {}) | ||
.filter((dep) => dep.startsWith('@lwc/')) | ||
.map((dep) => [dep, `${dep}/src`]) | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it matter if we define an alias for a package that's not actually used? Could we just move this to the root config and define aliases for all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried doing this, but it messed with the I can give this another shot, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it! 3b2954e |
||
}, | ||
}) | ||
); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineProject, mergeConfig } from 'vitest/config'; | ||
import baseConfig from '../../../vitest.shared.mjs'; | ||
import pkg from './package.json'; | ||
|
||
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 | ||
// Using `src` also ensures that the test coverage is accurately reported | ||
alias: Object.fromEntries( | ||
Object.keys(pkg.dependencies ?? {}) | ||
.filter((dep) => dep.startsWith('@lwc/')) | ||
.map((dep) => [dep, `${dep}/src`]) | ||
), | ||
}, | ||
}) | ||
); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineProject, mergeConfig } from 'vitest/config'; | ||
import baseConfig from '../../../vitest.shared.mjs'; | ||
import pkg from './package.json'; | ||
|
||
export default mergeConfig( | ||
baseConfig, | ||
defineProject({ | ||
test: { | ||
name: 'lwc-engine-core', | ||
// 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 | ||
// Using `src` also ensures that the test coverage is accurately reported | ||
alias: Object.fromEntries( | ||
Object.keys(pkg.dependencies ?? {}) | ||
.filter((dep) => dep.startsWith('@lwc/')) | ||
.map((dep) => [dep, `${dep}/src`]) | ||
), | ||
}, | ||
}) | ||
); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { defineProject, mergeConfig } from 'vitest/config'; | ||
import baseConfig from '../../../vitest.shared.mjs'; | ||
import pkg from './package.json'; | ||
|
||
export default mergeConfig( | ||
baseConfig, | ||
defineProject({ | ||
test: { | ||
name: 'lwc-engine-dom', | ||
environment: 'jsdom', | ||
// 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 | ||
// Using `src` also ensures that the test coverage is accurately reported | ||
alias: Object.fromEntries( | ||
Object.keys(pkg.dependencies ?? {}) | ||
.filter((dep) => dep.startsWith('@lwc/')) | ||
.map((dep) => [dep, `${dep}/src`]) | ||
), | ||
}, | ||
}) | ||
); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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'); | ||
|
@@ -49,7 +60,7 @@ async function compileFixture({ input, dirname }: { input: string; dirname: stri | |
|
||
await bundle.write({ | ||
file: outputFile, | ||
format: 'cjs', | ||
format: 'esm', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jest doesn't like ES Modules and Vitest doesn't like CJS... Hopefully this is fine. |
||
exports: 'named', | ||
}); | ||
|
||
|
@@ -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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineProject, mergeConfig } from 'vitest/config'; | ||
import baseConfig from '../../../vitest.shared.mjs'; | ||
import pkg from './package.json'; | ||
|
||
export default mergeConfig( | ||
baseConfig, | ||
defineProject({ | ||
test: { | ||
name: 'lwc-engine-server', | ||
// 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 | ||
// Using `src` also ensures that the test coverage is accurately reported | ||
alias: Object.fromEntries( | ||
Object.keys(pkg.dependencies ?? {}) | ||
.filter((dep) => dep.startsWith('@lwc/')) | ||
.map((dep) => [dep, `${dep}/src`]) | ||
), | ||
}, | ||
}) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed, only needed for Jest