Skip to content

Commit 3a03a76

Browse files
authored
test(wtr): remove usage of global TestUtils from hydration tests @W-19098266 (#5489)
* test(wtr): update tests to use relative path to utils instead of weird fake module * test(wtr): revert removing TestUtils * test(wtr): remove useless describe There's no setup/teardown needed, it's a single test, and WTR provides per-file encapsulation * test(wtr): replace IIFE script with module import * test(wtr): clean up SSR execution script working toward just importing and executing things, but not quite there yet * test(wtr): always use DISABLE_SYNTHETIC two env vars for the same goal is unnecessary * test(wtr): enable all hydration tests I think the last one was a concurrency related timeout, which was previously addressed. * test(wtr): remove side effect from signals helper helper files shouldn't have side effects; all setup should be in the setup file * test(wtr): import directly from file, not from barrel exporter * test(wtr): change bulk export statement to individual exports * test(wtr): remove unnecessary aria re-export * test(wtr): fix a few more ARIA util imports * chore: move comment for nicer aesthetic * test(wtr): remove unused option * test(wtr): fix another ARIA util import * test(wtr): import directly from hooks file rather than utils * test(wtr): import directly from signals file rather than utils * test(wtr): import directly from console helper rather than utils * test(wtr): import directly from constants helper rather than utils * test(wtr): only import what is needed from LWC * test(wtr): split lwc:dynamic load helpers into separate file * test(wtr): avoid relying on global LWC * test(wtr): remove unnecessary wrapping of hydration test config * test(wtr): remove test-utils logic from resolveImport no longer necessary * test(wtr): move plugin from shared config to only config that uses it * test(wtr): remove useless guid all tests are run in isolation * test(wtr): remove unnecessary test-utils global * test(wtr): clean up component definition * test(wtr): change component in test from IIFE to import * test(wtr): shift logic out of wrapper into static test runner file we want to keep the generated wrappers as thin as possible and use regular js files as much as possible * test(wtr): make test setup/teardown more idiomatic * test(wtr): clean up module compilation * chore(wtr): make dependency on @vitest/spy explicit * test(wtr): remove console suppression It was originally implemented to suppress distracting warnings in Karma tests, but WTR's log output is different / managed differently. * test(wtr): clean up names and comments * test(wtr): move and rename file * test(wtr): remove usage of global TestUtils from hydration tests * test(wtr): remove LWC import from utils It breaks hydration tests if there's an import from LWC. * test(wtr): remove unused external deps
1 parent 58111d0 commit 3a03a76

File tree

71 files changed

+198
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+198
-95
lines changed

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ export default tseslint.config(
361361
globals: {
362362
lwcRuntimeFlags: true,
363363
process: true,
364-
TestUtils: true,
365364
...globals.browser,
366365
...globals.jasmine,
367366
},

packages/@lwc/integration-not-karma/configs/plugins/serve-hydration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function compileModule(input, targetSSR, format) {
5050
}),
5151
],
5252

53-
external: ['lwc', '@lwc/ssr-runtime', 'test-utils', '@test/loader'], // @todo: add ssr modules for test-utils and @test/loader
53+
external: ['lwc', '@lwc/ssr-runtime'],
5454

5555
onwarn(warning, warn) {
5656
// Ignore warnings from our own Rollup plugin

packages/@lwc/integration-not-karma/configs/plugins/serve-integration.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ const transform = async (ctx) => {
8484
cache,
8585
plugins: [customLwcRollupPlugin],
8686

87-
// Rollup should not attempt to resolve the engine and the test utils, Karma takes care of injecting it
88-
// globally in the page before running the tests.
8987
external: [
9088
'lwc',
9189
'wire-service',
92-
'@test/loader',
9390
// Some helper files export functions that mutate a global state. The setup file calls
9491
// some of those functions and does not get bundled. Including the helper files in the
9592
// bundle would create a separate global state, causing tests to fail. We don't need to
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { __unstable__ReportingControl } from 'lwc';
2+
3+
/**
4+
*
5+
* @param dispatcher
6+
* @param runtimeEvents List of runtime events to filter by. If no list is provided, all events will be dispatched.
7+
*/
8+
export function attachReportingControlDispatcher(dispatcher, runtimeEvents) {
9+
__unstable__ReportingControl.attachDispatcher((eventName, payload) => {
10+
if (!runtimeEvents || runtimeEvents.includes(eventName)) {
11+
dispatcher(eventName, payload);
12+
}
13+
});
14+
}
15+
16+
export function detachReportingControlDispatcher() {
17+
__unstable__ReportingControl.detachDispatcher();
18+
}

packages/@lwc/integration-not-karma/helpers/setup.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ import { JestAsymmetricMatchers, JestChaiExpect, JestExtend } from '@vitest/expe
33
import * as chai from 'chai';
44
import { spyOn, fn } from '@vitest/spy';
55
import { registerCustomMatchers } from './matchers/index.js';
6-
import * as TestUtils from './utils.js';
76
import { initSignals } from './signals.js';
87

98
initSignals();
109

11-
// FIXME: As a relic of the Karma tests, some test files rely on the global object,
12-
// rather than importing from `test-utils`.
13-
window.TestUtils = TestUtils;
14-
1510
// allows using expect.extend instead of chai.use to extend plugins
1611
chai.use(JestExtend);
1712
// adds all jest matchers to expect

packages/@lwc/integration-not-karma/helpers/utils.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
* An as yet uncategorized mishmash of helpers, relics of Karma
33
*/
4-
import { __unstable__ReportingControl } from 'lwc';
54

65
// Listen for errors thrown directly by the callback
76
function directErrorListener(callback) {
@@ -47,23 +46,6 @@ export function customElementCallbackReactionErrorListener(callback) {
4746
: windowErrorListener(callback);
4847
}
4948

50-
/**
51-
*
52-
* @param dispatcher
53-
* @param runtimeEvents List of runtime events to filter by. If no list is provided, all events will be dispatched.
54-
*/
55-
export function attachReportingControlDispatcher(dispatcher, runtimeEvents) {
56-
__unstable__ReportingControl.attachDispatcher((eventName, payload) => {
57-
if (!runtimeEvents || runtimeEvents.includes(eventName)) {
58-
dispatcher(eventName, payload);
59-
}
60-
});
61-
}
62-
63-
export function detachReportingControlDispatcher() {
64-
__unstable__ReportingControl.detachDispatcher();
65-
}
66-
6749
export function extractDataIds(root) {
6850
const nodes = {};
6951

packages/@lwc/integration-not-karma/test-hydration/attributes/falsy-mismatch/index.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expectConsoleCallsDev } from '../../../helpers/utils.js';
2+
13
export default {
24
props: {
35
isFalse: false,
@@ -28,7 +30,7 @@ export default {
2830
expect(divs[i].getAttribute('data-foo')).toEqual(expectedAttrValues[i]);
2931
}
3032

31-
TestUtils.expectConsoleCallsDev(consoleCalls, {
33+
expectConsoleCallsDev(consoleCalls, {
3234
error: [],
3335
warn: [
3436
'Hydration attribute mismatch on: <div> - rendered on server: data-foo=null - expected on client: data-foo="undefined"',

packages/@lwc/integration-not-karma/test-hydration/context/index.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expectConsoleCalls } from '../../helpers/utils.js';
2+
13
export default {
24
// server is expected to generate the same console error as the client
35
expectedSSRConsoleCalls: {
@@ -40,7 +42,7 @@ export default {
4042
// Expect an error as one context was generated twice.
4143
// Expect an error as one context was malformed (did not define connectContext or disconnectContext methods).
4244
// Expect server/client context output parity (no hydration warnings)
43-
TestUtils.expectConsoleCalls(consoleCalls, {
45+
expectConsoleCalls(consoleCalls, {
4446
error: [],
4547
warn: [
4648
'Attempted to connect to trusted context but received the following error',

packages/@lwc/integration-not-karma/test-hydration/errors/already-hydrated/index.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expectConsoleCalls } from '../../../helpers/utils.js';
2+
13
export default {
24
advancedTest(target, { Component, hydrateComponent, consoleSpy }) {
35
hydrateComponent(target, Component, {});
@@ -6,7 +8,7 @@ export default {
68

79
const consoleCalls = consoleSpy.calls;
810

9-
TestUtils.expectConsoleCalls(consoleCalls, {
11+
expectConsoleCalls(consoleCalls, {
1012
warn: ['"hydrateComponent" expects an element that is not hydrated.'],
1113
});
1214
},

packages/@lwc/integration-not-karma/test-hydration/inner-outer-html/index.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { extractDataIds } from '../../helpers/utils.js';
2+
13
export default {
24
props: {},
35
advancedTest(target, { consoleSpy }) {
4-
const ids = Object.entries(TestUtils.extractDataIds(target)).filter(
6+
const ids = Object.entries(extractDataIds(target)).filter(
57
([id]) => !id.endsWith('.shadowRoot')
68
);
79
for (const [id, node] of ids) {

0 commit comments

Comments
 (0)