Description
openedon Sep 30, 2022
🚀 Feature Proposal
I would love for jest-config
to expose a new readRawConfig
. It reads the Config.InitialOptions
from (jest.config.js, jest.config.ts, jest.config.cjs, package.json, etc) without validating them.
I'd be happy to implement this in a PR!
Motivation
The StrykerJS jest-runner plugin roughly works as follows:
- Read the
InitialOptions
from user's jest config - Override some options to plug into globals, coverage, etc.
- Runs Jest using
runCLI
providing the config as JSON.
Since Jest doesn't support a way to do step 1, we are forced to recreate the config loading in our plugin. Since Jest keeps adding configuration file formats, it is quite a lot of work to keep up with this.
See these issues:
stryker-mutator/stryker-js#3710
stryker-mutator/stryker-js#3480
Example
import { readRawConfig } from 'jest-config';
import { runCLI } from 'jest';
const rawConfig: Config.InitialOptions = await readRawConfig('./jest.config.ts');
// override some stuff
rawConfig.setupFilesAfterEnv = ['./my-stryker-hook-file.js'];
await runCLI({ config: JSON.stringify(rawConfig) });
Alternatives
I've tried using the currently exported readConfig
function, but it fills out the rawOptions with all kinds of normalized options. Of I later pass them to runCLI
I get a bunch of warnings:
bunch of warnings
● Validation Warning:
Unknown option "nonFlagArgs" with value [] was found.
This is probably a typing mistake. Fixing it will remove this message.
Configuration Documentation:
https://jestjs.io/docs/configuration
node_modules/jest-validate/build/utils.js:101
● Validation Warning:
Unknown option "testPathPattern" with value "" was found.
This is probably a typing mistake. Fixing it will remove this message.
Configuration Documentation:
https://jestjs.io/docs/configuration
Pitch
Supporting mutation testing is supportive the platform idea.