stryker-mutator / stryker-jest-runner

A plugin to use the Jest test runner and framework in Stryker, the JavaScript mutation testing framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default jest config file jest.config.js is ignored.

andy128k opened this issue · comments

Thanks for opening this issue! Could you please post your stryker.conf.js?

This works

module.exports = function(config) {
  config.set({
    files: [
      { pattern: "assets/**/*.js", mutated: true, included: false },
    ],
    testRunner: "jest",
    mutator: "javascript",
    transpilers: ["babel"],
    reporter: ["html", "baseline", "clear-text", "progress"],
    coverageAnalysis: "off",
    babelrcFile: ".babelrc",
    jest: {
        project: 'default',
        config: require(__dirname + '/jest.config.js')
    },
    "logLevel": "all",
  });
};

but this doesn't

module.exports = function(config) {
  config.set({
    files: [
      { pattern: "assets/**/*.js", mutated: true, included: false },
    ],
    testRunner: "jest",
    mutator: "javascript",
    transpilers: ["babel"],
    reporter: ["html", "baseline", "clear-text", "progress"],
    coverageAnalysis: "off",
    babelrcFile: ".babelrc",
//    jest: {
//        project: 'default',
//        config: require(__dirname + '/jest.config.js')
//    },
    "logLevel": "all",
  });
};

That the expected behavior. If you don't specify anything related to your jest config, the plugin will look for a jest config in your package.json. If you want to require a file, you will have to do that with the config you provided here.

How do you suggest we make this clearer in the README for this package? Or perhaps combined with more extensive logging?

But jest.config.js is recognized by Jest itself.

Good point! If Jest can find it by default, I would expect Stryker to find it as well by default. What are your thoughts @Archcry ?

According to the Configuring Jest page you can indeed choose to specify the jest configuration in the jest.config.js. It seems like jest is trying to load the package.json first and then tries to fall back on the jest.config.js. I think we can replicate this functionality in Stryker by trying to load the package.json config first and if that does not succeed load the jest.config.js.

The page does not explicitly state which config is tried first though, thoughts on that?

@Archcry, try it out with a little expiriment? :)

It first looks for jest.config.js and then it will look in your package.json for a jest property.
I tested this with:

// jest.config.js
module.exports = {
    verbose: true,
};

And package.json:

"scripts": {
    "test": "jest"
  },
"jest": {
    "collectCoverage": true,
    "collectCoverageFrom": [
      "sum.js"
    ],
    "coverageDirectory": "./coverage"
  }

The result was a Jest run without coverage. If I remove the jest.config.js file I do get a coverage result from Jest.