Jest sees test suites but silently ignores the tests

Viewed 111

The question refers to Jest testing in a Nuxt/Vue v2 project. The unit tests ran as expected, either passing or not passing. After some changes Jest stopped running the tests I had (neither passing nor failing).

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 0 of 10 total
Tests:       0 total
Snapshots:   0 total
Time:        3.454 s, estimated 10 s
Ran all test suites.

I removed some code that I didn’t need, I stashed the changes and tried again, but none of test suits were running. I checked-out to the project version, where the tests previously ran as expected. Still nothing.

I can even make an empty test suite and the runner won’t raise ‘your test suite must contain at least one test’ exception. This involves the tests in both tests/unit directory and in other folders.

I’m usually pretty methodical with regard to my commits, but maybe I messed something up. I cannot exclude a possibility that I mixed something in the dependency tree, e.g. by not adding some crucial dependency to package.json (I removed node_modules and installed it from scratch at some point). Maybe there is a dependency mismatch, which didn’t occur before…

What could be the issue? How to troubleshoot such case? I used Mocha/Chai before so I’m new to Jest.

Here are my settings:

jest.config.js

module.exports = {
  moduleNameMapper: {
    "^@/(.*)$": "<rootDir>/$1",
    "^~/(.*)$": "<rootDir>/$1",
    "^vue$": "vue/dist/vue.common.js",
  },
  moduleFileExtensions: ["ts", "js", "vue", "json"],
  transform: {
    "^.+\\.ts$": "ts-jest",
    "^.+\\.js$": "babel-jest",
    ".*\\.(vue)$": "vue-jest",
  },
  collectCoverage: true,
  collectCoverageFrom: [
    "<rootDir>/some-dir/**/*.(js|ts)",
  ],
  testEnvironment: "jsdom",
  testMatch: ["**/*.spec.(js|jsx|ts|tsx)", "**/*.test.(js|jsx|ts|tsx)"],
  runner: "groups",
};

package.json

  "scripts": {
    …
    "test:unit": "jest"
  },
  "dependencies": {
    …
    "core-js": "^2.6.12",
    "nuxt": "^2.15.8",
    "path-to-regexp": "^6.2.1",
    "vue": "^2.6.14",
    "vue-server-renderer": "^2.6.14",
    "vue-template-compiler": "^2.6.14",
    "webpack": "^4.46.0"
  },
  "devDependencies": {
    …
    "@nuxt/types": "^2.15.8",
    "@nuxt/typescript-build": "^2.1.0",
    "@nuxtjs/device": "^2.1.0",
    "@vue/test-utils": "^1.3.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^27.4.4",
    "jest": "^27.4.4",
    "jest-runner-groups": "^2.2.0",
    "ts-jest": "^27.1.1",
    "vue-jest": "^3.0.4"
  }
}
1 Answers

I bumped core-js to v3 and now it works. I suppose that I installed previously v2 by mistake (it used to be nuxt default), then updated it to v3 but forgetting --save flag, hence braking the versioning.

I’m leaving this question in case it helps someone.

Related