Skip to content

jest rootDir #23

Open
Open
@manuphatak

Description

@manuphatak

Hello 👋

At ThinkCERCA we're experiencing an issue with jest's config. Jest has a optimization tool called jest-haste-map which appears to walk the entire rootDir looking for javascript code. This includes node_modules from old frontend code in a different directory, it includes javascript included with ruby in our vendor directory. And on our CI server, it includes everything cached by npm & yarn in thinkCERCA/.semaphore-cache. As you might imagine, there's all sorts of clashes happening. For whatever reason, certain snapshot tests reliably fail on our CI server.

I found 2 solutions:

  1. Delete npm/yarn cache on our CI server.

  2. Change jest's rootDir from thinkCERCA/ to thinkCERCA/client

Since create-react-app limits our ability to customize our configuration, solution 2 required a little bit of hackery that's worth sharing.

I copied in @zeal/react-scripts/scripts/test.js and @zeal/react-scripts/scripts/utils/createJestConfig.js to our codebase and made some changes to move jest's rootDir. I posted a diff of the changes here: https://gist.github.com/bionikspoon/af66c22122dc19f57ebf0e04b0137935

About half the changes are a product of copying the file over to our local project directory, the other half are for moving jest's rootDir.

These changes may or may not belong in your repo, you decide. If they are, happy to help any way I can.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions