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 'setupFiles' with <rootDir> breaks libs/apps tests

See original GitHub issue

Prerequisites

  • I am running the latest version
  • I checked the documentation (nx.dev) and found no answer
  • I checked to make sure that this issue has not already been filed
  • I’m reporting the issue to the correct repository (not related to React, Angular or any dependency)

Expected Behavior

Properly resolve rootDir when setupFiles are being used for jest config

Current Behavior

Let’s say my root jest.config.js is using setupFiles for various reasons like

const rootConfig = {
  rootDir: '.',
  setupFiles: ['<rootDir>/test/jest/global.js']
}

now if we wanna run test for particular package which uses root as a preset, setupFiles are not found as jest sets root dir to that particular directory from where are those test executed (so instead of having root ../.. - workspace root, it’s ./libs/my-lib

Failure Information (for bugs)

● Validation Error:

  Module <rootDir>/test/jest/global.js in the setupFiles option was not found.
         <rootDir> is: /Users/hotell/Projects/devel/workspace/tools

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
wilsonparsoncommented, Mar 10, 2020

Just discovered Nx’s Jest builder options: https://nx.dev/web/api/jest/builders/jest#jest

Adding the setupFile property to the project angular.json seems like the best solution for our use case:

"test": {
  "builder": "@nrwl/jest:jest",
  "options": {
    "jestConfig": "libs/components-library/payment-calculator/jest.config.js",
    "tsConfig": "libs/components-library/payment-calculator/tsconfig.spec.json",
    "setupFile": "jest.setup.angular.ts"
 }
}

We’re still stuck with referencing the setup file in each individual project, but at least it’s all in one file (angular.json) instead of spread across all of our project-level Jest configs.

2reactions
vsavkincommented, May 29, 2020

Sorry. The issue was marked by mistake. I removed the label.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
Indicates whether the coverage information should be collected while executing the test. Because this retrofits all executed files with coverage ...
Read more >
Top 5 jest-config Code Examples - Snyk
Learn more about how to use jest-config, based on jest-config code examples created from the most popular ways it is used in public...
Read more >
Jest globalSetup option not working - Stack Overflow
I'm trying to make a function called loadFixtures available to all Jest tests. I have the following line ...
Read more >
Setting up Jest + React-Testing-Library - DEV Community ‍ ‍
The setupFiles is executed before the test framework is installed in the environment. For our case, it is especially important, because it will ......
Read more >
2021年05月_weixin_39942191的博客_CSDN博客
jest 'setupFiles' with <rootDir> breaks libs/apps tests. 2021-01-12. docs: is there any way how to copy files when building libs/apps via glob. 2021-01-12 ......
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