Skip to content

Conversation

wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Oct 6, 2025

Details

There are a few scenarios where the runtime has an internal global state, such as tracking warnings that only get logged once. Tests, however, often need to run in isolation, so the internal global state must be reset. When running integration tests, the framework exposes a family of helpers, all prefixed with __lwcReset. When encountered within the integration tests, it is not obvious where these functions come from, or why they exist. In order to remove some "magic" from the tests, this PR consolidates the reset functions into a single test helper file, which explains each function and points to its source.

Additionally, to reduce test framework "magic" (and negligibly improve performance), this PR eliminates the global afterEach in favor of including an explicit afterEach only where required.

Lastly, this PR changes the NODE_ENV check from test-karma-lwc to test-lwc-integration because we don't use Karma any more.

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 wjhsf requested a review from a team as a code owner October 6, 2025 16:24
@@ -1,36 +0,0 @@
describe('clean DOM', () => {
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 test asserted, in Karma, that the DOM is clean after every test. However, because WTR runs each spec file independently, all that this test asserts is that the DOM is clean after each test in this file. There are assertions built into the resetDOM helper, so we do not need a specific test just to validate the test helper.


// Falsy values that are *not* treated as removing the attribute when set
const falsyValuesThatDoNotRemove = [0, false, '', NaN].map((value) => ({ value }));
describe.runIf(process.env.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL)(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

View this diff with whitespace ignored. I noticed that every describe checks for the polyfill flag, so I just hoisted that to the top to simplify the rest of the logic.

@wjhsf wjhsf merged commit d866116 into master Oct 6, 2025
14 of 18 checks passed
@wjhsf wjhsf deleted the wjh/clean-up-resets branch October 6, 2025 18:38
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