Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

CRA You need Jest version >= 22.0.0 to use Stryker error #49

Closed
protosimon opened this issue May 15, 2018 · 10 comments
Closed

CRA You need Jest version >= 22.0.0 to use Stryker error #49

protosimon opened this issue May 15, 2018 · 10 comments

Comments

@protosimon
Copy link

protosimon commented May 15, 2018

First of all, I am elated to find a mutation test framework for JS. I come from a quick check and PIT testing background and place a high value on the quality of tests. I am trying to configure stryker with my CRA project and getting the following error even-though the peer dependencies are met. An entry in the CRA docs on how to configure stryker would be great for devs and growing the community.

image

stryker.conf.js

 module.exports = function (config) {
  config.set({
    jest: {
      project: 'react'
    },
    testRunner: 'jest',
    mutator: 'javascript',
    coverageAnalysis: 'off',
    mutate: ['src/**/*.js']
  });
};

I have the following dependencies and jest config in package.json

 "devDependencies": {
    "axe-testcafe": "^1.1.0",
    "axios-mock-adapter": "^1.12.0",
    "chalk": "^2.4.0",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "eslint": "~4.12.1",
    "eslint-config-react-app": "^2.1.0",
    "eslint-plugin-testcafe": "^0.2.1",
    "flow-bin": "~0.70.0",
    "flow-typed": "2.4.0",
    "gulp": "^3.9.1",
    "gulp-maven-deploy": "~0.2.0",
    "jest-emotion": "^9.0.0-0",
    "react-scripts": "1.1.4",
    "redux-devtools-extension": "^2.13.2",
    "stryker": "0.21.0",
    "stryker-api": "0.15.0",
    "stryker-jest-runner": "^0.7.0",
    "testcafe": "^0.19.2"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.js",
      "!**/mock-backend/**",
      "!**/types/**"
    ]
  }
@mthmulders
Copy link
Collaborator

Hi @protosimon, thanks for taking the time to report this. Can you please do an npm ls jest to verify which version of Jest you're using?

@protosimon
Copy link
Author

@mthmulders, I am using jest@20.0.4 that's pulled down by react-scripts.

@mthmulders
Copy link
Collaborator

Thanks! Didn't know they had v20. I'm using the TypeScript-flavour of CRA, which has v22.
It seems to me that CRA has had a Jest upgrade recently, but unfortunately it has not been released yet?

@nicojs
Copy link
Member

nicojs commented May 16, 2018

I guess not:

image

We've overlooked this.

@mthmulders how much work would it be to also support v20?

@mthmulders
Copy link
Collaborator

Oh, CRA has a next branch, which has Jest 22, and a master (probably used for releases) which has Jest 20. Who'd have known...

We had a good reason to bump Jest to 20: Jest #5401 was biting us when we tried to run Jest from Stryker. I have no clue what it would take to downgrade Jest back to 22, since the general remark seems to be to "just upgrade Jest" :-(

@mthmulders
Copy link
Collaborator

You might try to use stryker-jest-runner@0.6.0, stryker-api@0.13.0 and stryker@0.19.1 in the meantime, and see if that works. The difference between stryker-jest-runner@0.6.0 and stryker-jest-runner@0.7.0 is that it bumps stryker-api and adds support for the TypeScript-flavour of CRA.
Can you see if that works for you?

@nicojs
Copy link
Member

nicojs commented May 17, 2018

I'm no react expert, but can't @protosimon just install a new version of Jest? Sure he would have 2 jest versions in his node_modules (one node_modules/jest (v22) and one node_modules/react-scripts/jest (v20)), but that shouldn't be a problem right?

@mthmulders
Copy link
Collaborator

Since he's using CRA, I think he cannot. Quoting @gaearon in facebook/jest #5119:

It is not supported to update Jest manually in a CRA project.

@nicojs
Copy link
Member

nicojs commented May 17, 2018

The way I see it, your not upgrading the react-scripts version of jest, instead installing a brand new one right next to it.

It seems to work for me:

npx create-react-app my-app
cd my-app
npm i -D jest@22
npm ls | grep jest

# ... outputs:
+-- jest@22.4.3
# ...
  +-- jest@20.0.4
# ...
stryker init
# < choose jest, no transpilers >
vi stryker.conf.js
# < change some things: mutate array (only mutate App.js), disable coverage analysis >
stryker run
[2018-05-17 09:55:58.040] [INFO] ConfigReader - Using stryker.conf.js in the current working directory.
[2018-05-17 09:55:58.384] [INFO] InputFileResolver - Found 1 of 15 file(s) to be mutated.
[2018-05-17 09:55:58.389] [INFO] InitialTestExecutor - Starting initial test run. This may take a while.
[2018-05-17 09:56:03.485] [INFO] InitialTestExecutor - Initial test run succeeded. Ran 1 tests in 5 seconds.
[2018-05-17 09:56:03.523] [INFO] Stryker - 1 Mutant(s) generated
[2018-05-17 09:56:03.527] [INFO] SandboxPool - Creating 8 test runners (based on CPU count)
Mutation testing  [==================================================] 100% (ETC 0.0s) 1/1 tested (0 survived)

Ran 0.00 tests per mutant on average.
----------|---------|----------|-----------|------------|----------|---------|
File      | % score | # killed | # timeout | # survived | # no cov | # error |
----------|---------|----------|-----------|------------|----------|---------|
All files |  100.00 |        0 |         1 |          0 |        0 |       0 |
 App.js   |  100.00 |        0 |         1 |          0 |        0 |       0 |
----------|---------|----------|-----------|------------|----------|---------|
[2018-05-17 09:56:18.815] [INFO] Stryker - Done in 20 seconds.
...

@protosimon could you give it a go?

@nicojs
Copy link
Member

nicojs commented Aug 3, 2018

Closing it for now. Please comment again when you still have problems.

@nicojs nicojs closed this as completed Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants