Feature Request: Support for .ts config files
Currently only .mjs, .cjs and .js config files are supported.
For type safety and autocomplete information, it would be nice to be able to use .ts files for configuration.
Optional proposal
As a possible solution, tsx could be used as a dependency and when checking for the currently supported config files are not found, load tsx and try to load .mts, .cts and .ts extensions.
If you are interested/not opposed, I could provide a pull request.
If you want to build a TS config, why not just trample it to JS like you’d need to with any other delivery of TS and the use that fine in the dev server? It doesn’t feel with the trouble to build that process into he project without more information.
Hello @Westbrook
I'm afraid I don't fully understand what you mean.
I would like to write my web-test-runner.config.js file as a TypeScript file (i.e. web-test-runner.config.ts), primarily in order to more easily understand the API of the configuration (i.e. autocompletion).
At the moment, I do not need to manually transpile my TypeScript files, as our vite plugin takes care of that.
I’m asking why whatever is transpiling your TS can’t also do the same for your config?
It is certainly possible to compile the config to .js, but we generally don't have transpiled files in our repository, which we would also need to keep in sync or create a wrapper around the web-test-runner binary.
Both of these approaches are possible, but not desirable.
From your answers I gather you are opposed to this feature?
If this is about config autocomplete, its pretty trivial to add a jsdoc type to the config to the object. Alternatively, we could consider a defineConfig helper that takes a typed object so you also get autocomplete.
I’m also not sure why you would need to keep the transpiled file in your repo or wrap WTR. You can transpile in the prescription of your WTR command and then .gitignore the JS version while pointing to it in your text command.
Lots of options here when you list this with Pascal’s options.
This feature request is primarily about convenience. The proposed solutions all work, so there is no blocker. But as e.g. tools like vite and storybook support .ts config files, I wanted to ask, whether this project could also enable this.
As maintainers for this project, it is your prerogative to reject this request. I will be disappointed, but I can certainly live with the jsdoc approach.
The downside of adding this to web-test-runner is:
- more maintenance for maintainers
- more surface area for things to go wrong
Plus, as a user, you have more control if you transpile your TypeScript your own way (and gitignore the output if desired).
You can, for example, require people working in your repo to
npm run dev<- compiles any typescript files (whether source files or config files)- optionally
npm run test:watchafter the dev script is going to run test-runner in watch mode reading JS files - EDIT: there are also some nice cross-platform packages to run scripts in parallel with a single command, which can be used in a
devscript- https://npmjs.com/@schummar/runp
- https://npmjs.com/concurrently
- https://npmjs.com/npm-run-all
- etc
I think this is overall simpler and makes maintenance easier and keeps test-runner good at what it does, while the convenience loss is very small.
You can do this in a plain JS file:
// @ts-check
/** @type {import('@web/test-runner').TestRunnerConfig} */
export default {
// this will have type checking, intellisense, etc
}