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.

Nx 13.10 breaks `jest-runner-groups`

See original GitHub issue

Preface

For those unaware, jest-runner-groups allows you to “annotate” a test file with a group name, e.g.

/**
 * @group foo
 */

This allows you to only run certain tests

Current Behavior

When using jest-runner-groups:

  • nx affected:test --group=foo runs tests that have not been annotated with the group foo
  • nx affected:test --group=-foo runs tests that have been annotated with the group foo
  • If I manually run Jest in one of the apps/libs, then the --group flag works as expected

Expected Behavior

When using jest-runner-groups:

  • nx affected:test --group=foo should only run tests that have been annotated with the group foo
  • nx affected:test --group=-foo should only run tests that have not been annotated with the group foo

Steps to Reproduce

  1. Use jest-runner-groups in a repo using Nx 13.9.7, and see that test filtering works as expected
  2. Update Nx to 13.10.2, and see that all tests are run, regardless of what --group flag is passed

Failure Logs

n/a

Environment

Node : 16.14.1
OS   : win32 x64
npm  : 8.5.0

nx : 13.10.2
@nrwl/angular : Not Found
@nrwl/cypress : Not Found
@nrwl/detox : Not Found
@nrwl/devkit : 13.10.2
@nrwl/eslint-plugin-nx : 13.10.2
@nrwl/express : Not Found
@nrwl/jest : 13.10.2
@nrwl/js : 13.10.2
@nrwl/linter : 13.10.2
@nrwl/nest : 13.10.2
@nrwl/next : Not Found
@nrwl/node : 13.10.2
@nrwl/nx-cloud : 13.3.1
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/workspace : 13.10.2
typescript : 4.3.5
rxjs : 7.5.5

At a guess, I’d say that the --group flag isn’t actually being passed to Jest, even though Nx says that it is running the command with that flag

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
npworkcommented, May 2, 2022

Issue is still present @Ezard your fix is working, one minor change (if you need to run tests from WebStorm/IntelliJ Idea)

It passes extra arguments, so it’s safer to do something like this


const GroupRunner = require('jest-runner-groups')

class NxGroupRunner extends GroupRunner {
  runTests(tests, watcher, onStart, onResult, onFailure, options) {
    try {
      const config = JSON.parse(process.argv[2])
      if (config?.overrides?.group) {
         process.argv.push(...config.overrides.group.map((g) => `--group=${g}`))
      }
    } catch (e) {}
    return super.runTests(tests, watcher, onStart, onResult, onFailure, options)
  }
}

module.exports = NxGroupRunner

Also to use multiple args (like --group=a --group=b) make sure to use solution (above) with (process.argv.push(...config.overrides.group.map((g) => `--group=${g}`)))

1reaction
Ezardcommented, May 2, 2022

@npwork I’ve integrated your suggestions into v1.1.0 of jest-runner-groups-nx (with a bit of tweaking since, from testing, your solution worked for multiple groups but not single groups)

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is new in Nx 13.10?
Build and run Nx Plugins locally in your Nx workspace · Nx core which provides the fundamental features such as the dependency graph...
Read more >
Nx 13 Migration failure: update-tasks-runner - Stack Overflow
Failed to run 13-10-0-update-tasks-runner from @nrwl/workspace. This workspace is NOT up to date! Cannot read property 'default' of undefined.
Read more >
Migrating an Angular CLI project to Nx
This command will install the correct version of Nx based on your Angular version. This will enable you to use the Nx CLI...
Read more >
nx - npm
Nx is a next generation build system with first class monorepo support and powerful integrations. Getting Started. Creating an Nx Workspace.
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