Lint-staged + vitest - running related tests as precommit hook takes too much time

241 views Asked by At

My configuration in package.json looks like this. I have two projects (one in app directory, another in backoffice directory)

  "scripts": {
    "start": "cd app && yarn start",
    "test": "cd app && vitest related --run --passWithNoTests",
    "prepare": "husky install",
    "test-backoffice": "cd backoffice && vitest related --run --passWithNoTests"
  },
  "lint-staged": {
    "*.(js|jsx|ts|tsx)": [
      "yarn test",
      "yarn test-backoffice",
    ]
  },

If I remove related from test commands it goes very quickly but doesn't execute proper tests (ex. change in fullname.ts doesn't trigger execution of tests inside fullname.test.ts).

But with related it takes too much time, and it doesn't sum up correctly. Here is what I can see in the console. Notice that duration is much higher than sum of all parts.

Duration  19.14s (transform 496ms, setup 121ms, collect 787ms, tests 11ms, environment 224ms, prepare 49ms)
0

There are 0 answers