Skip to content

[Feature]: Expose readRawConfig from jest-config #13348

Closed

Description

🚀 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:

  1. Read the InitialOptions from user's jest config
  2. Override some options to plug into globals, coverage, etc.
  3. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions