lint-staged: jest can't find babel when i'm using gitDir

Hello okonet, thank you for your great work. I’m trying to use jest with lint staged, but when i’m using the “gitDir” option jest can’t find babel-jest and so every test fails.

My config:

{
    "gitDir": "../",
    "linters": {
        "*.js": [
            "prettier --single-quote --trailing-comma all --write",
            "git add",
            "eslint --ignore-path ./gui/.gitignore",
            "jest --config ./gui/jest.json --bail --findRelatedTests"
        ],
        "*.css": [
            "stylelint"
        ]
    }
}

My folder structure: gitFolder -> gui (frontend-app)

^^^^^^ SyntaxError: Unexpected token import at transformAndBuildScript (gui/node_modules/jest-runtime/build/transform.js:320:12)

I think the problem is that jest can’t find babel-jest, because of the “gitDir”-option and so can’t transform the import statement.

When i’m using jest without lint-staged it’s working like a charm.

lint-staged: 3.4.0 jest: 19.0.2 babel-jest: 19.0.0 husky: 0.13.3

I hope you’ve got an idea where the problem comes from. Thank you

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @DeFuex, in the test i recommend to change the button id to something different for example “fooBar”. After changing the test you have to add the change to git with git add . before you are running npm run precommit. This is necessary for lint-staged to see the edited files.