question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Jest config inherits previous one in projects array

See original GitHub issue

šŸ› Bug Report

We have a monorepo. Jest config in root:

"projects": [
    "<rootDir>/projectA/jest.js",
    "<rootDir>/projectB/jest.js"
]

projectA/jest.js:

const common = require('ourToolsPackage');

module.exports = Object.assign(common, {
    "setupTestFrameworkScriptFile": "<rootDir>/setup-jest.ts",
    "transform": {
        ".ts": "<rootDir>/../node_modules/ts-jest/preprocessor.js"
    },
    "globals": {
        "ts-jest": {
            "tsConfigFile": "./tsconfig.json"
        }
    },
    "moduleFileExtensions": ["ts", "js"],
    "modulePathIgnorePatterns": ["dist"],
    "roots": ["src/"]
});

projectB/jest.js:

const common = require('ourToolsPackage');

module.exports = Object.assign(common, {
    rootDir: '.',
    preset: "./node_modules/jest-preset-angular/jest-preset.json",
    "setupTestFrameworkScriptFile": "<rootDir>/setup-jest.ts",
    "globals": {
        "ts-jest": {
            "tsConfigFile": "src/tsconfig.spec.json"
        },
        "__TRANSFORM_HTML__": true
    },
    "moduleFileExtensions": ["ts", "js", "html", "json"],
    "modulePathIgnorePatterns": ["dist"]
});

ourToolsPackage:

module.exports = {
    collectCoverage: true,
    coverageReporters: ["text-summary", "lcov"],
    coverageDirectory: "coverage",
    reporters: ["default", "jest-junit"],
    testMatch: [
        "**/__tests__/**/+(*.)+(spec|test).+(ts|js)"
    ]
};

I run jest --verbose --debug in root of monorepo and config is:

{
  "configs": [
    {
      ...
      "globals": {
        "ts-jest": {
          "tsConfigFile": "./tsconfig.json"
        }
      },
      ...
      "name": "f450223cded2e13301d633b3bf280357",
      ...
      "rootDir": ".../projectA",
      "roots": [
        ".../projectA/src"
      ],
      "runner": "jest-runner",
      "setupTestFrameworkScriptFile": ".../projectA/setup-jest.ts",
      ...
      "testMatch": [
        "**/__tests__/**/+(*.)+(spec|test).+(ts|js)"
      ],
      ...
      "transform": [
        [
          ".ts",
          ".../node_modules/ts-jest/preprocessor.js"
        ]
      ],
      ...
    },
    {
      ...
      "globals": {
        "ts-jest": {
          "tsConfigFile": "src/tsconfig.spec.json"
        },
        "__TRANSFORM_HTML__": true
      },
      ...
      "name": "126a5d5b6fdd2817d38a004c77305b9a",
      ...
      "rootDir": ".../projectB",
      "roots": [
        ".../projectB/src"
      ],
      "runner": "jest-runner",
      "setupFiles": [],
      "setupTestFrameworkScriptFile": ".../projectB/setup-jest.ts",
      ...
      "testMatch": [
        "**/__tests__/**/+(*.)+(spec|test).+(ts|js)"
      ],
      ...
      "transform": [
        [
          ".ts",
          ".../node_modules/ts-jest/preprocessor.js"
        ],
        [
          "^.+\\.(ts|js|html)$",
          ".../projectB/node_modules/jest-preset-angular/preprocessor.js"
        ]
      ],
      ...
    }
  ],
  "globalConfig": {
    ...
    "projects": [
      ".../projectA/jest.js",
      ".../projectB/jest.js"
    ],
    "rootDir": "...",
    "runTestsByPath": false,
    ...
  },
  "version": "22.4.4"
}

As you can see, in projectBā€™s transform field, we have by config itself only one ā€œtransformā€ (it is set by jest-preset-angular). But if I run it from monorepo root, another (from projectA) transform field is added. Same thing for roots.

To Reproduce

I think you need just specify projects field in config as array of paths to jest configs in monorepo. And have differences in transform and roots fields (I didnā€™t check other fields)

Expected behavior

Each config must be isolated; Order of entries in projects should not change behavior

Link to repl or repo (highly encouraged)

If it will be extremely necessary, Iā€™ll spend time on it.

Run npx envinfo --preset jest

npx: installed 1 in 2.286s

  System:
    OS: macOS High Sierra 10.13.4
    CPU: x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
  Binaries:
    Node: 8.9.1 - ~/.nvm/versions/node/v8.9.1/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 5.5.1 - ~/.nvm/versions/node/v8.9.1/bin/npm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:8

github_iconTop GitHub Comments

3reactions
SimenBcommented, Oct 31, 2018

You can see what is considered global config and whatā€™s considered project config here: https://github.com/facebook/jest/blob/master/types/Config.js

This is very confusing, and somewhat inconsistent. Would love to fix it at some point. S great first step would be to explicitly error out if global config is provided as project config, but that would just treat the symptom, not the underlying issue

0reactions
github-actions[bot]commented, Apr 29, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
Make sure it is installed in your project. The configuration also can be stored in a JSON file as a plain object: jest.config.json....
Read more >
What happens if more than one Jest configuration is used ...
I inherited multiple projects with both a "jest" object in package.json and "jest.config.js" file, each with their specific configuration.
Read more >
Inheritance and the prototype chain - JavaScript | MDN
When it comes to inheritance, JavaScript only has one construct: objects. Each object has a private property which holds a link to anotherĀ ......
Read more >
A guide through The Wild Wild West of setting up a mono repo ...
In this part, I will explain step by step how to setup Lerna, Yarn Workspaces and Typescript in a mono repo. In the...
Read more >
Overriding an Array Configuration Object - Level Up Coding
NET Core project, the result of the final configuration data ... Development.json file because that file is the last one to be loaded....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found