Skip to content

test(integration): begin moving from Karma to Web Test Runner #5386

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

Merged
merged 40 commits into from
Jun 13, 2025

Conversation

wjhsf
Copy link
Collaborator

@wjhsf wjhsf commented Jun 12, 2025

Details

Karma has been deprecated for a long time, and the recent end of life for sauce v2 is forcing us to finally move to something else. We've decided to move to Web Test Runner. One of the key differences between the two is that Web Test Runner is based on modern ESM imports, so there's minimal bundling and maximal modularity, while our Karma tests are an absolute mess of adding wrappers, injecting globals, and bundling in far too many different ways. Untangling all of the Karma tests so that they work with Web Test Runner is a pretty big lift, so this PR aims to just get something running in CI, even though it's only a fraction of the tests that are passing (and I've fudged a bunch of the matchers, so a bunch of the passing tests are fake). After this PR, there will be plenty more:

  1. Get all of the basic tests running
  2. Re-implement the missing matchers (Karma uses jasmine while WTR uses chai)
  3. Get all the basic tests passing
  4. Re-introduce the different env var test scenarios
  5. Do all of this for hydration tests as well
  6. etc.

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 May 20, 2025 14:05
Turns out `import @web/test-runner-mocha` _seemed_ to expose the mocha globals, but they were actually still being replaced because the autorun script from the test framework has its own inlined copy of mocha. Also a lot of tests were failing because some kind of watcher registered by the test framework was getting confused by the setup stuff being run twice.
way simpler to rollup the test file, same as karma does
by skipping all the broken ones
will switch everything over later
@wjhsf wjhsf requested a review from a team as a code owner June 12, 2025 15:56
// Cache reused between each compilation to speed up the compilation time.
let cache;

export default async (ctx) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a custom wrapper of @lwc/rollup-plugin. It's largely copied from the one used for Karma tests. The primary reason we have this seems to be so that we can use different configs based on the file path of tests.

I don't like that pattern, and eventually I want to investigate using a normal human config file or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are our custom matchers. The bulk of the file is just copied from the karma version. Hopefully can be simplified once they are actually implemented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied from Karma and cleaned up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New setup specific to WTR, largely related to bridging the gaps between frameworks.

TEMPLATE_CLASS_NAME_OBJECT_BINDING,
};

window.TestUtils = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sometimes importing from test-utils and sometimes accessing window.TestUtils is a really annoying pattern. Eventually I want to clean up the tests and have everything import from ./helpers/utils.mjs.

wjhsf added 3 commits June 12, 2025 13:37
the test files originally had changes that got reverted
Copy link
Collaborator

@divmain divmain left a comment

Choose a reason for hiding this comment

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

This looks great. It queues up the remaining work pretty well and makes it so that the work can be split or handed off another engineer as needed. :shipit:

- release
- 'spring*'
- 'summer*'
- 'winter*'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be better to just run on master at first, since older branches won't have the tweaks that are necessary for the Karma-to-WTR migration. We can still run Karma locally for back-ported bug fixes.

@@ -218,7 +218,7 @@ export default tseslint.config(
},
},
{
files: ['packages/@lwc/integration-karma/**'],
files: ['packages/@lwc/integration-karma/**', 'packages/@lwc/integration-not-karma/**'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Excellent package name.

});
};

const defaultRollupPlugin = createRollupPlugin();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah this is a bit weird. It's okay for now, but it seems like something that the rollup plugin should be able to handle for us, without creating three different versions of the plugin.

}
});
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just making sure I understand: this is a placeholder, where actual implementations of the custom matchers will be implemented in future PRs? If so, 👍

@wjhsf wjhsf merged commit 7bb5be4 into master Jun 13, 2025
6 of 7 checks passed
@wjhsf wjhsf deleted the wjh/web-test-runner branch June 13, 2025 19:04
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