-
Notifications
You must be signed in to change notification settings - Fork 427
chore(integration-karma): migrate to webdriverio/vitest #4594
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
Changes from 6 commits
ff6631c
4ea2f54
86ed5f4
72f3ede
8474bec
a7c0e39
8712d71
70bed5a
a0ed880
51cc9fa
3ef0206
de2bb0a
9fd8b3b
a3c3751
9e7798f
d52038f
f5b4dc7
3a32fcd
c197eb3
096008b
68d7ea1
798a969
486a949
1970bbb
235ef5c
7f11657
4e30c2c
dc65971
b49c646
dc6299f
ebfa2be
2671dfa
6cf87e1
5a46cfb
4bc1d5d
908a076
d5ab33d
fb02d76
a8f41b4
daac79a
f48aa83
3d8854d
59036eb
70b32b8
c2aa02a
cf26d0c
f72a3c2
64a902b
87d1d51
9cce7e6
45e7aca
ef4765e
d5a9d45
dc5824c
ee657fa
44a9bf9
2f298db
53c9716
03935de
6a9fb2c
50ad791
de390dd
679a5af
7a9ecfc
cecee30
6fe2d02
cb6f47a
d755571
95c4587
fdbb7e8
4478da4
b3b89b4
1acf596
47a2628
a7a4fc5
f962501
c109fbf
15feb98
4756b0e
e3613fe
f1471a4
d7e97db
b4309d9
477d555
f739211
a9f4801
68329a2
b3ee369
8f18ec7
dece5dd
9170f97
78cba8f
c84b3ba
87051b8
4050ee0
0b3b0df
26a7229
582e6c7
012bd64
fb897bb
3f5e923
3bd9cdf
8063042
1897f92
ca1f992
263dd0f
a7d7330
5acb1b5
0851ec8
6806648
69c72c9
cc36de4
29ec4e5
3b30a10
b8d5312
066549d
db88d27
799ee56
41990c0
39e60e3
ce70151
7f838dc
73a6a14
0b58515
3bfc774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,5 +103,6 @@ | |
| "http-cache-semantics": "4.1.1", | ||
| "semver": "7.6.0" | ||
| }, | ||
| "dependencies": {} | ||
| "dependencies": {}, | ||
| "packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "extends": "../../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "esModuleInterop": true, | ||
| "noEmit": true, | ||
| "allowJs": true, | ||
| "target": "ESNext", | ||
| "lib": ["ES2015.Promise", "DOM"], | ||
|
Contributor
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. Why
Contributor
Author
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 haven't given much thought yet to the tsconfig. I started out migrating the spec.js files to spec.ts before I decided on polyfillig jasmine and keeping the tests mostly unchanged. So it is pretty minimal right now. |
||
| "types": ["vitest/globals", "@vitest/browser/providers/playwright"], | ||
| "paths": { | ||
| "test-utils": ["./vitest-helpers/test-utils.ts"] | ||
| } | ||
| }, | ||
| "files": ["../../lwc/types.d.ts"], | ||
| "include": [ | ||
| "vitest-scripts/**/*.ts", | ||
| "vitest-helpers/*.ts", | ||
| "test/**/*.spec.ts", | ||
| "test/**/*.spec.js" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // globalThis.process = { | ||
| // env: { | ||
| // API_VERSION: 63, | ||
| // DISABLE_STATIC_CONTENT_OPTIMIZATION: false, | ||
| // ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL: false, | ||
| // ENABLE_SYNTHETIC_SHADOW_IN_HYDRATION: false, | ||
| // FORCE_NATIVE_SHADOW_MODE_FOR_TEST: false, | ||
| // LWC_VERSION: "8.1.0", | ||
| // NATIVE_SHADOW: false, | ||
| // NODE_ENV: "development", | ||
| // } | ||
| // }; | ||
| // globalThis.lwcRuntimeFlags = { | ||
| // DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE: false | ||
| // }; | ||
| import type { GlobalSetupContext } from 'vitest/node'; | ||
|
|
||
| export default function setup({ provide }: GlobalSetupContext) { | ||
| provide('wsPort', 3000); | ||
| } | ||
|
|
||
| declare module 'vitest' { | ||
| export interface ProvidedContext { | ||
| wsPort: number; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * 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 | ||
| */ | ||
|
|
||
| window.HydrateTest = (function (lwc, testUtils) { | ||
| testUtils.setHooks({ | ||
| sanitizeHtmlContent: (content) => content, | ||
| }); | ||
|
||
|
|
||
| // As of this writing, Firefox does not support programmatic access to parsing DSD, | ||
| // i.e. `Document.parseHTMLUnsafe` | ||
| // See: https://developer.mozilla.org/en-US/docs/Web/API/Document/parseHTMLUnsafe_static | ||
| function testSupportsProgrammaticDSD() { | ||
| const html = '<div><template shadowrootmode="open"></template></div>'; | ||
| try { | ||
| return !!Document.parseHTMLUnsafe(html).body.firstChild.shadowRoot; | ||
| } catch (_err) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| const browserSupportsProgrammaticDSD = testSupportsProgrammaticDSD(); | ||
|
|
||
| function parseStringToDom(html) { | ||
| if (browserSupportsProgrammaticDSD) { | ||
| return Document.parseHTMLUnsafe(html).body.firstChild; | ||
| } else { | ||
| return new DOMParser().parseFromString(html, 'text/html').body.firstChild; | ||
| } | ||
| } | ||
|
|
||
| function polyfillDeclarativeShadowDom(root) { | ||
| root.querySelectorAll('template[shadowrootmode]').forEach((template) => { | ||
| const mode = template.getAttribute('shadowrootmode'); | ||
| const shadowRoot = template.parentNode.attachShadow({ mode }); | ||
| shadowRoot.appendChild(template.content); | ||
| template.remove(); | ||
|
|
||
| polyfillDeclarativeShadowDom(shadowRoot); | ||
| }); | ||
| } | ||
|
|
||
| function appendTestTarget(ssrText) { | ||
| const div = document.createElement('div'); | ||
|
|
||
| const testTarget = parseStringToDom(ssrText); | ||
| if (!browserSupportsProgrammaticDSD) { | ||
| polyfillDeclarativeShadowDom(testTarget); | ||
| } | ||
| div.appendChild(testTarget); | ||
|
|
||
| document.body.appendChild(div); | ||
|
|
||
| return div; | ||
| } | ||
|
|
||
| function runTest(ssrRendered, Component, testConfig) { | ||
| const container = appendTestTarget(ssrRendered); | ||
| const selector = container.firstChild.tagName.toLowerCase(); | ||
| let target = container.querySelector(selector); | ||
|
|
||
| let testResult; | ||
| const consoleSpy = testUtils.spyConsole(); | ||
|
|
||
| if (testConfig.test) { | ||
| const snapshot = testConfig.snapshot ? testConfig.snapshot(target) : {}; | ||
|
|
||
| const props = testConfig.props || {}; | ||
| const clientProps = testConfig.clientProps || props; | ||
|
|
||
| lwc.hydrateComponent(target, Component, clientProps); | ||
|
|
||
| // let's select again the target, it should be the same elements as in the snapshot | ||
| target = container.querySelector(selector); | ||
| testResult = testConfig.test(target, snapshot, consoleSpy.calls); | ||
| } else if (testConfig.advancedTest) { | ||
| testResult = testConfig.advancedTest(target, { | ||
| Component, | ||
| hydrateComponent: lwc.hydrateComponent.bind(lwc), | ||
| consoleSpy, | ||
| container, | ||
| selector, | ||
| }); | ||
| } | ||
|
|
||
| consoleSpy.reset(); | ||
|
|
||
| return testResult; | ||
| } | ||
|
|
||
| return { | ||
| runTest, | ||
| }; | ||
| })(window.LWC, window.TestUtils); | ||
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.
What does adding this
packageManagerdo?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.
I think installing yarn with Node 22 corepack does that. It shows up every time I run yarn. I intend to remove this diff once I'm done.