Skip to content

test(wtr): clean up hydration test logic @W-19098266#5487

Merged
wjhsf merged 44 commits intomasterfrom
wjh/wtr-clean-hydration
Sep 16, 2025
Merged

test(wtr): clean up hydration test logic @W-19098266#5487
wjhsf merged 44 commits intomasterfrom
wjh/wtr-clean-hydration

Conversation

@wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Sep 11, 2025

Details

The hydration tests are complicated because they require running component code on the server and in the browser. For Karma, this meant that there was a lot of bundling/wrapping/indirection happening. It makes for a very confusing code base, so as part of the migration to Web Test Runner I have been trying to clean things up where I can. My goal with this PR is to remove unnecessary indirection and try to get the generated code as small as possible.

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.
  • 💔 Yes, it does introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.
  • 🔬 Yes, it does include an observable change.

GUS work item

wjhsf and others added 30 commits September 2, 2025 18:01
There's no setup/teardown needed, it's a single test, and WTR provides per-file encapsulation
working toward just importing and executing things, but not quite there yet
two env vars for the same goal is unnecessary
I think the last one was a concurrency related timeout,
which was previously addressed.
helper files shouldn't have side effects; all setup should be in the setup file
all tests are run in isolation
@wjhsf wjhsf requested a review from a team as a code owner September 11, 2025 20:56
return output[0].code;
}

function throwOnUnexpectedConsoleCalls(runnable, expectedConsoleCalls = {}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added in #4649 to suppress logs for cosmetic reasons. WTR surfaces logs differently, so we don't need to keep it.

${testConfig}
${moduleCode}
`(async () => {
const {default: config} = await import('./${configPath}');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converting from IIFE to ESM import because the config file doesn't need to be bundled, it just works.

${componentDefCSR};
return await runTest(ssrRendered, Main, config);
});
runTest(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved as much logic as I could from the generated code into runTest.

if (source === 'test-utils') {
return '/helpers/utils.js';
} else if (source === 'wire-service') {
if (source === 'wire-service') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer import from test-utils, so we don't need to resolve it. (I missed this in the other PRs.)

@@ -1,3 +1,4 @@
import { importMapsPlugin } from '@web/dev-server-import-maps';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved from the base config to this config, because only this config needs this plugin.

return testResult;
}
// Must be sync to properly register tests; async behavior can happen in before/after blocks
export function runTest(configPath, componentPath, ssrRendered, focused) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this to define the tests (and use idiomatic setup/teardown) rather than be a helper within a test.

"@lwc/synthetic-shadow": "8.21.6",
"@types/chai": "^5.2.2",
"@types/jasmine": "^5.1.9",
"@vitest/spy": "^3.2.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explicitly declaring an already-used transitive dependency.

@wjhsf wjhsf enabled auto-merge (squash) September 16, 2025 18:33
@wjhsf
Copy link
Contributor Author

wjhsf commented Sep 16, 2025

/nucleus ignore --reason meh

@wjhsf wjhsf merged commit 58111d0 into master Sep 16, 2025
7 checks passed
@wjhsf wjhsf deleted the wjh/wtr-clean-hydration branch September 16, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants