Skip to content

concurrent.each executes iterations serially instead of concurrently #5458

@jgoux

Description

@jgoux

Describe the bug

It seems that describe.concurrent.each is implemented as a shortcut for setting { concurrency: true } in each describe block so the tests within it are run in concurrently.

However, this is not how it works in Jest according to this PR: jestjs/jest#9326

describe.concurrent.each should not alter the describe block options but execute each describe block concurrently.

Here are my expectations:

const cases = [1, 2, 3];

// full concurrency, both the describe blocks and the tests within them are run concurrently
describe.concurrent.each(cases)(
  `case: %i`,
  { concurrent: true },
  (num) => {
    test("foo", {});
    test("bar", {});
  }
);

// only the describe blocks are executed concurrently, the tests within them are executed serially
describe.concurrent.each(cases)(
  `case: %i`,
  (num) => {
    test("foo", {});
    test("bar", {});
  }
);

// the describe blocks are executed serially, the tests within them are executed concurrently
describe.each(cases)(
  `case: %i`,
  { concurrent: true },
  (num) => {
    test("foo", {});
    test("bar", {});
  }
);

Reproduction

I was not able to install vitest correctly in StackBlitz:

❯ npm install
npm ERR! Failed to fetch dependencies:
npm ERR! - yocto-queue@1.0.0
npm ERR! - queue-microtask@1.2.3

npm ERR! A complete log of this run can be found in: /home/.npm/_logs/2024-03-29T17_44_21_075Z-debug-0.log

But here is the link illustrating the issue: https://stackblitz.com/edit/vitest-dev-vitest-fwwzec?file=test%2Fbasic.test.ts

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 88.14 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - /nix/store/xjgg53kjjhwcx4p3dmywjmqjbv82xhyn-nodejs-20.11.1/bin/node
    npm: 10.2.4 - /nix/store/xjgg53kjjhwcx4p3dmywjmqjbv82xhyn-nodejs-20.11.1/bin/npm
    pnpm: 8.15.5 - /nix/store/ih6qr7ga6i467b91kf52lkb6qhiib4s8-corepack-enable/bin/pnpm
  Browsers:
    Chrome: 123.0.6312.87
    Safari: 17.4.1
  npmPackages:
    vitest: 1.4.0 => 1.4.0

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-to-be-discussedEnhancement under consideration (priority)

    Type

    No type

    Projects

    Status

    Has plan

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions