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

chore(integration-karma): migrate to playwright/vitest #4594

Open
wants to merge 122 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
ff6631c
chore(@lwc/integration-karma): migrate to vitest
cardoso Sep 26, 2024
4ea2f54
chore(@lwc/integration-karma): tsify test-utils
cardoso Sep 28, 2024
86ed5f4
chore(@lwc/integration-karma): compatibility layer
cardoso Sep 28, 2024
72f3ede
chore(@lwc/integration-karma): fix console
cardoso Sep 28, 2024
8474bec
chore(@lwc/integration-karma): fix resolution
cardoso Sep 28, 2024
a7c0e39
chore(@lwc/integration-karma): resolve modules
cardoso Sep 28, 2024
8712d71
fix(@lwc/integration-karma): composedPath tests
cardoso Sep 29, 2024
70bed5a
chore: add composedPath helpers
cardoso Sep 29, 2024
a0ed880
fix: event-methods
cardoso Sep 29, 2024
51cc9fa
feat: use vitest mock
cardoso Sep 29, 2024
3ef0206
fix: starting lwc vitest plugin from scratch
cardoso Sep 29, 2024
de2bb0a
fix: simplified lwc vitest plugin 300+ tests pass
cardoso Sep 29, 2024
9fd8b3b
fix: added jasmine.createSpy() compat
cardoso Sep 29, 2024
a3c3751
fix: implemented toEqualWireSettings
cardoso Sep 29, 2024
9e7798f
fix: template imports
cardoso Sep 30, 2024
d52038f
fix: jasmine createSpy
cardoso Sep 30, 2024
f5b4dc7
chore: update plugin
cardoso Oct 1, 2024
3a32fcd
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 1, 2024
c197eb3
chore: remove screenshots
cardoso Oct 1, 2024
096008b
chore: remove more screenshots
cardoso Oct 1, 2024
68d7ea1
chore: git ignore screenshots
cardoso Oct 1, 2024
798a969
fix: jasmine createSpy
cardoso Oct 1, 2024
486a949
fix: revert freezeTemplate test
cardoso Oct 1, 2024
1970bbb
fix: polyfill jasmine.arrayWithExactContents
cardoso Oct 1, 2024
235ef5c
chore: revert more test changes
cardoso Oct 1, 2024
7f11657
fix: css imports
cardoso Oct 1, 2024
4e30c2c
fix: some wire tests
cardoso Oct 1, 2024
dc65971
fix: enable dynamic components
cardoso Oct 1, 2024
b49c646
fix: enable dynamic components
cardoso Oct 1, 2024
dc6299f
fix: polyfill spy.and.returnValue
cardoso Oct 2, 2024
ebfa2be
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 2, 2024
2671dfa
fix: html rootDir resolution
cardoso Oct 2, 2024
6cf87e1
fix: update done callbacks to promises
cardoso Oct 2, 2024
5a46cfb
fix: polyfill spy.and.callFake
cardoso Oct 2, 2024
4bc1d5d
fix: add toHaveSize matcher
cardoso Oct 2, 2024
908a076
fix: polyfill createSpy().calls.reset()
cardoso Oct 2, 2024
d5ab33d
fix: polyfill spyOn().calls
cardoso Oct 2, 2024
fb02d76
fix: polyfill jasmine.any
cardoso Oct 2, 2024
a8f41b4
fix: polyfill spyOn().and.callThrough
cardoso Oct 2, 2024
daac79a
fix: done callback to promise
cardoso Oct 2, 2024
f48aa83
fix: polyfill xit
cardoso Oct 2, 2024
3d8854d
fix: use mockClear for callThrough polyfill
cardoso Oct 2, 2024
59036eb
fix: stub NATIVE_SHADOW env
cardoso Oct 2, 2024
70b32b8
fix: expect toMatch should receive string
cardoso Oct 2, 2024
c2aa02a
fix: polyfill xdescribe
cardoso Oct 2, 2024
cf26d0c
fix: disable native custom element lifecycle
cardoso Oct 2, 2024
f72a3c2
fix: polyfill spy.calls.mostRecent()
cardoso Oct 2, 2024
64a902b
fix: constructor import
cardoso Oct 2, 2024
87d1d51
fix: jasmine polyfills any, objectContaining, and arrayWithExactContents
cardoso Oct 2, 2024
9cce7e6
chore: add test:browser:debug script
cardoso Oct 2, 2024
45e7aca
fix: error in test/rendeing/slotting
cardoso Oct 2, 2024
ef4765e
fix: passWithNoTests
cardoso Oct 2, 2024
d5a9d45
chore: update vitest packages
cardoso Oct 2, 2024
dc5824c
feat: disable vite postcss processing
cardoso Oct 3, 2024
ee657fa
fix: add LWC_VERSION env
cardoso Oct 3, 2024
44a9bf9
fix: disable css?scoped=true vite transform
cardoso Oct 3, 2024
2f298db
fix: expect toMatch string
cardoso Oct 3, 2024
53c9716
fix: polyfill createSpy().calls.count()
cardoso Oct 3, 2024
03935de
fix: patch vite:css plugin
cardoso Oct 3, 2024
6a9fb2c
chore: add wip script for test-hydration
cardoso Oct 3, 2024
50ad791
test(hydration): implement plugin
cardoso Oct 3, 2024
de390dd
chore: simpligy hydration plugin
cardoso Oct 3, 2024
679a5af
chore: simplify generated test code
cardoso Oct 3, 2024
7a9ecfc
fix: sanitizeHtmlContent
cardoso Oct 4, 2024
cecee30
fix: add filename to vm scriot
cardoso Oct 4, 2024
6fe2d02
fix: setHooks in hydration tests
cardoso Oct 4, 2024
cb6f47a
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 4, 2024
d755571
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 7, 2024
95c4587
fix: types in lwc vitest plugin
cardoso Oct 7, 2024
fdbb7e8
fix: run ffi transform
cardoso Oct 7, 2024
4478da4
fix: inject @lwc/engine-dom script tag
cardoso Oct 7, 2024
b3b89b4
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 7, 2024
1acf596
fix: iife source map
cardoso Oct 7, 2024
47a2628
chore: remove unused Watcher.ts
cardoso Oct 8, 2024
a7a4fc5
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 8, 2024
f962501
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 8, 2024
c109fbf
fix: hycration test source maps
cardoso Oct 8, 2024
15feb98
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 8, 2024
4756b0e
fix: not.toHaveSize matcher
cardoso Oct 8, 2024
e3613fe
fix: prevent some comments from disappearing
cardoso Oct 9, 2024
f1471a4
fix: keep version comments
cardoso Oct 9, 2024
d7e97db
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 9, 2024
b4309d9
fix: support ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL
cardoso Oct 9, 2024
477d555
fix: support ENABLE_SYNTHETIC_SHADOW_IN_HYDRATION
cardoso Oct 9, 2024
f739211
fix: support DISABLE_STATIC_CONTENT_OPTIMIZATION
cardoso Oct 9, 2024
a9f4801
chore: revert changes to rollup-plugin
cardoso Oct 10, 2024
68329a2
fix: improve test failure location for ShadowRoot.elementsFromPoint
cardoso Oct 10, 2024
b3ee369
fix: remove dependency of test-utils on lwc
cardoso Oct 10, 2024
8f18ec7
chore: remove unused toEqualWireSettings matcher
cardoso Oct 10, 2024
dece5dd
fix: watch files
cardoso Oct 10, 2024
9170f97
fix: watch files in test-hydration
cardoso Oct 10, 2024
78cba8f
revert: watch files (error with invalid namespace symbol)
cardoso Oct 11, 2024
c84b3ba
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 11, 2024
87051b8
chore: split vitest setup files
cardoso Oct 11, 2024
4050ee0
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 11, 2024
0b3b0df
feat: speed up hydration tests by 2x
cardoso Oct 12, 2024
26a7229
fix: disable passWithNoTests for hydration
cardoso Oct 12, 2024
582e6c7
fix: remove unneeded ?iife query param
cardoso Oct 14, 2024
012bd64
chore: separate config plugin
cardoso Oct 14, 2024
fb897bb
chore: separate vite plugins in folder
cardoso Oct 14, 2024
3f5e923
fix: different names for tests
cardoso Oct 14, 2024
3bd9cdf
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 14, 2024
8063042
chore: update vitest to 2.1.3
cardoso Oct 14, 2024
1897f92
chore: shorten test names
cardoso Oct 14, 2024
ca1f992
fix: use transform to replace NODE_ENV
cardoso Oct 14, 2024
263dd0f
chore: consolidate plugins
cardoso Oct 14, 2024
a7d7330
fix: handling API_VERSION env var in tests
cardoso Oct 14, 2024
5acb1b5
chore: begin support for coverage
cardoso Oct 14, 2024
0851ec8
chore: add workspace file
cardoso Oct 15, 2024
6806648
fix: scripts running all tests
cardoso Oct 15, 2024
69c72c9
fix: enable source maps
cardoso Oct 15, 2024
cc36de4
fix: enable excludeAfterRemap
cardoso Oct 15, 2024
29ec4e5
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 16, 2024
3b30a10
fix: move @vitest/browser dependency to root
cardoso Oct 16, 2024
b8d5312
chore: transition to webdriverio
cardoso Oct 17, 2024
066549d
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 17, 2024
db88d27
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 17, 2024
799ee56
feat: webdriverio browser config
cardoso Oct 18, 2024
41990c0
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 18, 2024
39e60e3
fix: import framework files via testerScripts
cardoso Oct 18, 2024
ce70151
fix: use global LWC in hydration tests
cardoso Oct 18, 2024
7f838dc
Merge branch 'master' of https:/salesforce/lwc into vites…
cardoso Oct 18, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ packages/@lwc/integration-tests/errorShots/
packages/@lwc/integration-tests/results/
packages/@lwc/integration-tests/.env

packages/@lwc/integration-karma/**/__screenshots__/

# custom node_modules for testing
!packages/@lwc/module-resolver/src/__tests__/**/node_modules/
!packages/@lwc/rollup-plugin/src/__tests__/**/node_modules/
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@
"http-cache-semantics": "4.1.1",
"semver": "7.6.0"
},
"dependencies": {}
"dependencies": {},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does adding this packageManager do?

Copy link
Contributor Author

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.

}
18 changes: 18 additions & 0 deletions packages/@lwc/integration-karma/helpers/test-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,23 @@ afterAll(function () {
throwIfConsoleCalled();
});

const { createSpy } = jasmine;

jasmine.createSpy = function () {
const spy = createSpy();

spy.mockClear = function () {
spy.calls.reset();
};

spy.mock = {
get calls() {
return spy.calls.allArgs();
},
};

return spy;
};

// The default of 5000ms seems to get surpassed frequently in Safari 14 in SauceLabs
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
45 changes: 45 additions & 0 deletions packages/@lwc/integration-karma/helpers/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ window.TestUtils = (function (lwc, jasmine, beforeAll) {
: windowErrorListener(callback);
}

const getNormalizedFunctionAsString = (fn) => fn.toString().replace(/(\s|\n)/g, '');

const customMatchers = {
toLogErrorDev: consoleDevMatcherFactory('error'),
toLogError: consoleDevMatcherFactory('error', true),
Expand All @@ -343,6 +345,29 @@ window.TestUtils = (function (lwc, jasmine, beforeAll) {
windowErrorListener,
true
),
toEqualWireSettings: function () {
return {
compare: function (actual, expected) {
Object.keys(actual).forEach((currentKey) => {
const normalizedActual = Object.assign({}, actual[currentKey], {
config: getNormalizedFunctionAsString(actual[currentKey].config),
});

const normalizedExpected = Object.assign({}, expected[currentKey], {
config: getNormalizedFunctionAsString(
expected[currentKey].config || function () {}
),
});

expect(normalizedActual).toEqual(normalizedExpected);
});

return {
pass: true,
};
},
};
},
};

beforeAll(function () {
Expand Down Expand Up @@ -642,6 +667,24 @@ window.TestUtils = (function (lwc, jasmine, beforeAll) {
TEMPLATE_CLASS_NAME_OBJECT_BINDING: process.env.API_VERSION >= 62,
};

/**
* Returns a promise that resolves with the composed path of the event.
* @param {Event} event - The event to be dispatched and whose composed path is to be resolved.
* @param {EventTarget} target - The target to which the event listener is added.
* @param {EventTarget} dispatcher - The dispatcher that dispatches the event.
* @returns {Promise<EventTarget[]>} A promise that resolves with the composed path of the event.
*/
async function expectComposedPath(event, target, dispatcher = target) {
const composedPath = await new Promise((resolve) => {
target.addEventListener(event.type, (event) => {
resolve(event.composedPath());
});
dispatcher.dispatchEvent(event);
});

return composedPath;
}

return {
clearRegister,
extractDataIds,
Expand All @@ -667,6 +710,8 @@ window.TestUtils = (function (lwc, jasmine, beforeAll) {
expectConsoleCalls,
expectConsoleCallsDev,
catchUnhandledRejectionsAndErrors,
spyOn,
expectComposedPath,
...apiFeatures,
};
})(LWC, jasmine, beforeAll);
8 changes: 6 additions & 2 deletions packages/@lwc/integration-karma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"hydration:sauce:ci": "../../../scripts/ci/retry.sh karma start ./scripts/karma-configs/hydration/sauce.js --single-run",
"sauce": "karma start ./scripts/karma-configs/test/sauce.js --single-run",
"sauce:ci": "../../../scripts/ci/retry.sh karma start ./scripts/karma-configs/test/sauce.js --single-run",
"coverage": "node ./scripts/merge-coverage.js"
"coverage": "node ./scripts/merge-coverage.js",
"test:browser": "vitest --config=./vitest.config.mjs"
},
"//": {
"karma-sauce-launcher-fix-firefox": "using a fork to work around https:/karma-runner/karma-sauce-launcher/issues/275"
Expand All @@ -23,6 +24,8 @@
"@lwc/rollup-plugin": "8.1.2",
"@lwc/synthetic-shadow": "8.1.2",
"@types/jasmine": "^5.1.4",
"@types/karma-jasmine": "^4.0.5",
"@vitest/browser": "^2.1.1",
"chokidar": "^4.0.1",
"istanbul-lib-coverage": "^3.2.2",
"istanbul-lib-report": "^3.0.1",
Expand All @@ -31,6 +34,7 @@
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "^2.2.1",
"karma-jasmine": "^5.1.0",
"karma-sauce-launcher-fix-firefox": "3.0.1"
"karma-sauce-launcher-fix-firefox": "3.0.1",
"playwright": "^1.47.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,6 @@ function testInvalidComponentConstructor(name, ctor) {
});
}

beforeAll(function () {
const getNormalizedFunctionAsString = (fn) => fn.toString().replace(/(\s|\n)/g, '');

jasmine.addMatchers({
toEqualWireSettings: function () {
return {
compare: function (actual, expected) {
Object.keys(actual).forEach((currentKey) => {
const normalizedActual = Object.assign({}, actual[currentKey], {
config: getNormalizedFunctionAsString(actual[currentKey].config),
});

const normalizedExpected = Object.assign({}, expected[currentKey], {
config: getNormalizedFunctionAsString(
expected[currentKey].config || function () {}
),
});

expect(normalizedActual).toEqual(normalizedExpected);
});

return {
pass: true,
Comment on lines -20 to -42
Copy link
Contributor Author

@cardoso cardoso Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This beforeAll() was just adding a custom matcher. I moved it to the test scripts in karma and implemented the equivalent in the vitest scripts.

};
},
};
},
});
});

testInvalidComponentConstructor('null', null);
testInvalidComponentConstructor('undefined', undefined);
testInvalidComponentConstructor('String', 'component');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Container from 'x/container';
import Two from 'x/two';
import Shadow from 'x/shadow';

// @ts-check

describe('Light DOM styling at the global level', () => {
it('styles bleed into other light DOM but not shadow DOM components in root context', () => {
const elm = createElement('x-container', { is: Container });
Expand Down
Loading