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.

Generating react library causes tests to fail after upgrading to 10.3.0

See original GitHub issue

Current Behavior

Generate a data-access library under an existing directory completes successfully. After this running jest tests errors out on any of the libs with

(oldOptions[key] || []).map is not a function

Expected Behavior

The tests should run successfully.

Steps to Reproduce

Write some lib tests that pass for all libs

yarn nx run-many --target=test --all

Create a new library by running this command:

nx generate @nrwl/react:library --name=data-access --directory=ui/main --no-component --tags='scope:ui-main, type:data-access'

Run tests again

Failure Logs

(oldOptions[key] || []).map is not a function

Environment

  nx : 10.3.0
  @nrwl/angular : Not Found
  @nrwl/cli : 10.3.0
  @nrwl/cypress : 10.3.0
  @nrwl/eslint-plugin-nx : 10.3.0
  @nrwl/express : 10.3.0
  @nrwl/jest : 10.3.0
  @nrwl/linter : 10.3.0
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : 10.3.0
  @nrwl/react : 10.3.0
  @nrwl/schematics : Not Found
  @nrwl/tao : 10.3.0
  @nrwl/web : 10.3.0
  @nrwl/workspace : 10.3.0
  typescript : 4.0.3

Downgrading back to 10.2.1 fixes the problem.

One difference i noticed is in the lib’s jest.config.js

module.exports = {
  ...
  preset: "../../../../jest.config.js", // <-- this value is ../../../../jest.preset.js in 10.3.0
  ...
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
tmakolacommented, Oct 10, 2020

I experience the same issue after upgrading to 10.3.0. In my case, it was after adding a new node library which seems to me not at all to be related to React but libraries in general. nx g @nrwl/node:library now-version.

What I noticed is the jest.config.js in the root folder had an additional property added to it that seemed to lock Jest to a specific project. Therefore only the newly added project was testable.

Removing the file, allowed all tests from all projects to function again.

module.exports = {
    ...
    passWithNoTests: true,
    projects: '<rootDir>/libs/now-version' // <--- newly added property. should be removed
};
6reactions
ZackDeRosecommented, Apr 14, 2021

Hi all - going back to my reproduction if you trace back through the commits, you can see that while I create a migrations.json file, I entered the command incorrectly as:

nx migrate --run-migrations

Whereas prior versions (pre 11.4) required a target migrations.json file (so like so: nx migrate --run-migrations=migrations.json).

As such, these migrations were generated, but not ran. We’ve added more clarity around this in current versions - the cli prompts with nx migrate --run-migrations=migrations.json and we also now default to migrations.json if no explicit path is provided.

To others having issues with this in their workspaces after migrating, you can rerun this migration specifically by creating a migrations.json with the contents:

{
  "migrations": [
    {
      "version": "10.3.0-beta.1",
      "description": "Adds all jest projects into the root jest config",
      "factory": "./src/migrations/update-10-3-0/update-projects-property",
      "package": "@nrwl/jest",
      "name": "update-projects-property"
    }
  ]
}

And then run nx migrate --run-migrations=migrations.json to correct your workspaces going forward.

Also note that the projects property on your root jest.config.json exists to enable tooling with VsCode (and other IDEs) that allows your IDE to target and these tests correctly (see below). Removing the projects property from your root jest.config.json - or removing this file entirely - will allow your tests to be run via the nx CLI, but running jest tests via your IDE may break.

Screen Shot 2021-04-14 at 1 06 35 PM

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Utilities - React
ReactTestUtils makes it easy to test React components in the testing framework of your choice. At Facebook we use Jest for painless JavaScript...
Read more >
Migration Guide | Cypress Documentation
Migrating to Cypress 12.0 This guide details the changes and how to change your code to migrate to Cypress version 12.0.
Read more >
React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. ... When testing, code that causes React state updates should be wrapped into act(...): act(()...
Read more >
react-native-device-info - npm
v6 to v7 upgrade. Your iOS Podfile will need to move to an iOS 10 minimum. v7 of this module no longer supports...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
... Bug:96449 - "New: fusd A library and kernel module to create userpsace char ... Bug:225283 - "sys-devel/automake-1.10.1 fails tests when active JVM...
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