Skip to content
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

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

Closed
nicojs opened this issue Sep 30, 2022 · 2 comments · Fixed by #13356
Closed

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

nicojs opened this issue Sep 30, 2022 · 2 comments · Fixed by #13356

Comments

@nicojs
Copy link
Contributor

nicojs commented 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:

  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.

@SimenB
Copy link
Member

SimenB commented Sep 30, 2022

Very happy to take a PR implementing this! 🙂

@github-actions
Copy link

github-actions bot commented Nov 3, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants