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

Support for jest.config.js? #10

Open
ktalebian opened this issue Jul 24, 2019 · 10 comments
Open

Support for jest.config.js? #10

ktalebian opened this issue Jul 24, 2019 · 10 comments
Assignees

Comments

@ktalebian
Copy link

ktalebian commented Jul 24, 2019

This works great, but I use jest.config.js instead of using the package.json and when running the ratchet, it appends the new thresholds into package.json.

I tried jest-coverage-ratchet --config-path ./jest.config.js with no success. Even logged console.log(configPath) here https://github.com/Koleok/jest-coverage-ratchet/blob/master/src/index.js#L19. It did show the path to jest.config.js but still bumped the package.json

@Koleok
Copy link
Owner

Koleok commented Sep 1, 2019

This is a pretty common case and worth supporting 👍

@Koleok Koleok self-assigned this Sep 1, 2019
@SimplyComplexable
Copy link

@Koleok any update on this?

@ktalebian
Copy link
Author

@SimplyComplexable doesn't look any new PR was closed recently.

@jamestalmond
Copy link

I would love this feature.

@Koleok
Copy link
Owner

Koleok commented Feb 18, 2020

Well its cool to see that someone is using this 😅 I will try to get this done in the PM hours this week, I haven't used it in my daily work for a few years so it had just left my mental inbox so to speak :)

@Koleok
Copy link
Owner

Koleok commented Feb 26, 2020

I was able to find some time for this in the past few days, turns out its a little bit tricky to re-write a jest.confg.js file in a responsible way as opposed to a jest.config.json, simply because I can't just assume that file is

module.exports = {
  // config
}

It may be something like:

const cleverConfigLogicBasedOnEnv = {
  // ...
}

module.exports = {
  ...cleverConfigLogicBasedOnEnv,
  // rest of config
}

Certainly it can be done, it will just take some regexs and logic that will have to evolve over time as edge cases come up. With this in mind, I think the first pass will just support jest.config.json files while some thought is put into how to effectively deal with .js.

As a workaround until then, you could make a file called something like jest.coverageConfig.json that was there just for the purpose of ratcheting, then import that and spread it into your jest.config.js
jest.coverageConfig.json

{
  "coverageThreshold": {
    "global": {
      "lines": 86.67,
      "statements": 74.29,
      "functions": 10,
      "branches": 50
    }
  }
}

jest.config.js

const coverageConfig = require('./jest.coverageConfig.json')

module.exports = {
  ...coverageConfig,
  // rest of your config
}

then just make sure that you are running the command like

jest-coverage-ratchet --configPath ./jest.coverageConfig.json

@ZuBB
Copy link

ZuBB commented Mar 30, 2020

Hi @Koleok !

Just wanted to note next

simply because I can't just assume that file is...

thats true. different setups are possible.

However, in readme you already do some assumptions

I know what happens when you assume, but jest-coverage-ratchet makes the following assumptions about your project.

I would ask you to make one more.

BTW thanks for great lib

@Koleok
Copy link
Owner

Koleok commented Mar 31, 2020

@ZuBB Fair enough 👌 , lets give it a try with that assumption, seems there are few enough users of this lib that its not a crazy experiment to assume a certain format of jest.config.js, I'll push up the new version over the next few days with that packed in 👍

@rkristelijn
Copy link

rkristelijn commented Sep 29, 2021

I found a workaround for this using the current version;

TL;DR import the thresholds directly from package.json

  1. npm i -D jest-coverage-ratchet
  2. add to package.json:
{
  "scripts": {
    "test:coverage": "jest-coverage-ratchet",
  }
}
  1. npm run test:coverage (package.json now contains "jest": {})
  2. update jest.config.js:
const jestConfig = require('./package.json').jest;

module.exports = {
  ...jestConfig,
}

@dbudwin
Copy link

dbudwin commented Apr 1, 2022

There is a new package based on jest-coverage-ratchet that will do this that is still being maintained called jest-coverage-thresholds-bumper.

https://github.com/Litee/jest-coverage-thresholds-bumper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants