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

Support snapshot tests

liamondrop opened this issue · comments

Currently, when running Jest tests with snapshots, the stryker-jest-runner will fail.

Code to reproduce:

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toMatchSnapshot();
});

Error message:

One or more tests failed in the initial test run:
	adds 1 + 2 to equal 3
		Error: expect(value).toMatchSnapshot()

New snapshot was not written. The update flag must be explicitly passed to write a new snapshot.

This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default.

Hi, thanks for the report. Just to make sure, you do have a snapshot for the test on disk?

I'm not at all familiar with Jest, but could this issue be caused by our sandboxing?

I'm not at all familiar with Jest, but could this issue be caused by our sandboxing?

Probably yes. Did you add the snapshot files in the files array in your stryker.conf.js file?

@mthmulders yes, Jest automatically generates the snapshot files, stores them in a __snapshots__ directory and checks the outputs against these.

@nicojs no I didn't add the snapshot files in the files array. I will give that a try.

@nicojs that was the ticket. The following minimal config gets the tests running with snapshots.

  config.set({
    files: [
      "src/**/__tests__/**/*.js",
      "src/**/__snapshots__/*.snap",
      {
        pattern: "src/**/*.js",
        mutated: true,
        included: false
      }
    ],
    testRunner: "jest",
    mutator: "javascript",
    coverageAnalysis: "off"
  });

I hadn't realized exactly what the "files" array was intended to do, so would be helpful to add that to the README for this repo at a minimum. I can make a PR.

Thanks!