Accessing the test runner config in a plugin #2615
Unanswered
scottohara
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a number of old, legacy side-projects that use:
With Karma now officially deprecated I've been looking at alternatives, but many of the modern choices (Jest, Vitest etc.) push you towards emulated DOM environments (jsdom, happy-dom etc.).
Although slower, I place a high value on the confidence I get from running my test suite in the actual browsers that my app runs in. So I'm looking into @web/test-runner as a possible Karma replacement.
As most of these projects are legacy, the current webpack setup does a lot of things that isn't readily or easily transferable to esbuild/rollup (at least not without some migration effort), so I'm looking for an easy way to keep most of the existing setup unchanged and simply swap out the test runner.
I've started exploring the idea of creating a @web/test-runner plugin that is a port of karma-webpack.
(I'm aware this runs counter to the Modern Web ethos of "going buildless" by leveraging browser support for ESM-first testing).
The plan
In essence, the plugin's
serverStart()
hook would inspect thefiles
pattern(s) in the test runner config, resolve them to a list of actual files, and convert that list of files into webpack "entries" (one per test file); before running the webpack process.Then, the plugin's
serve()
hook would intercept requests from the browser for each test file, and respond with the bundled content of the corresponding webpack asset.Usage
Issues
The first stumbling block I've hit is that the
serverStart()
hook receives an argument of typeServerStartParams
which contains aconfig: DevServerCoreConfig
property.This is the @web/dev-server config. What I need though is access to the @web/test-runner config, where the
files
patterns are specified.When writing a test runner plugin, is there a way to access the test runner config in the
serverStart()
hook?Beta Was this translation helpful? Give feedback.
All reactions