Jest: Jest complains about non-existent obsolete snapshots which it fails to remove

Created on 7 May 2019  ยท  3Comments  ยท  Source: facebook/jest

๐Ÿ› Bug Report

We can't figure out why this is happening on this PR https://github.com/zowe/zowe-cli/pull/366.
Running the unit tests fails because it says there are 7 obsolete snapshot files. However, when you try to use the -u flag on jest, we get failure messages complaining that jest could not delete some .snap files, which don't exist. I don't know how it is determining that there are obsolete snapshots. Confusingly, it also tried to delete more than seven files. This has happened on at least four different machines checking out the branch of the below repo

Sorry I don't have a more minimal example, but since I don't know what is causing it I can't make another example. Hopefully we are just missing something simple, but it doesn't seem jest is working as intended

Example output:

 FAIL  packages/zosfiles/__tests__/api/methods/download/Download.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosfiles\__tests__\api\methods\download\__snapshots__\Download.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zosfiles/__tests__/api/methods/delete/Delete.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosfiles\__tests__\api\methods\delete\__snapshots__\Delete.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zosfiles/__tests__/cli/upload/Upload.definition.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosfiles\__tests__\cli\upload\__snapshots__\Upload.definition.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zosconsole/__tests__/IssueCommand.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosconsole\__tests__\__snapshots__\IssueCommand.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/workflows/__tests__/cli/archive/workflow/Archive.workflow.handler.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\workflows\__tests__\cli\archive\workflow\__snapshots__\Archive.workflow.handler.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zosconsole/__tests__/CollectCommand.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosconsole\__tests__\__snapshots__\CollectCommand.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zostso/__tests__/api/PingTso.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zostso\__tests__\api\__snapshots__\PingTso.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zosfiles/__tests__/cli/delete/uss/Uss.handler.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosfiles\__tests__\cli\delete\uss\__snapshots__\Uss.handler.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/utils/__tests__/CoreUtils.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\utils\__tests__\__snapshots__\CoreUtils.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/workflows/__tests__/cli/delete/deleteArchivedWorkflow/Delete.archived.common.handler.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\workflows\__tests__\cli\delete\deleteArchivedWorkflow\__snapshots__\Delete.archived.common.handler.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zosconsole/__tests__/ConsoleResponseService.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosconsole\__tests__\__snapshots__\ConsoleResponseService.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zosfiles/__tests__/cli/invoke/Invoke.definition.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosfiles\__tests__\cli\invoke\__snapshots__\Invoke.definition.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/zosfiles/__tests__/cli/delete/uss/Uss.definition.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\zosfiles\__tests__\cli\delete\uss\__snapshots__\Uss.definition.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

 FAIL  packages/provisioning/__tests__/api/ProvisionPublishedTemplate.unit.test.ts
  โ— Test suite failed to run

    ENOENT: no such file or directory, unlink 'C:\nodejs\zowe-cli\packages\provisioning\__tests__\api\__snapshots__\ProvisionPublishedTemplate.unit.test.ts.snap'

      at SnapshotState.save (node_modules/jest-snapshot/build/State.js:114:21)

To Reproduce

clone https://github.com/matthewpwilson/zowe-cli
checkout branch upload-lts
npm i --@brightside:registry=https://api.bintray.com/npm/ca/brightside
npm run test:unit or npm run test:unit -- -u

Expected behavior

Jest should not say there are obsolete snapshots, or else it should be able to delete them if they exist

Link to repl or repo (highly encouraged)

https://github.com/matthewpwilson/zowe-cli/tree/upload-lts

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Windows 7
    CPU: (8) x64 Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz
  Binaries:
    Node: 10.15.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.4.1 - C:\nodejs\zowe-cli\node_modules\.bin\npm.CMD

Bug Report Needs Repro Needs Triage

Most helpful comment

This was happening to me because I was mocking fs.existsSync and forgot to call jest.resetAllMocks() after. Looks like you have the same problem

All 3 comments

This was happening to me because I was mocking fs.existsSync and forgot to call jest.resetAllMocks() after. Looks like you have the same problem

Thanks Nitive. That solved the problem for me

Had the same problem, can confirm it's because I was mocking fs and didn't call jest.resetAllMocks. Thanks guys for the tip!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jardakotesovec picture jardakotesovec  ยท  3Comments

Antho2407 picture Antho2407  ยท  3Comments

hramos picture hramos  ยท  3Comments

paularmstrong picture paularmstrong  ยท  3Comments

samzhang111 picture samzhang111  ยท  3Comments