Skip to content

jest-worker computeWorkerKey option not always grouping #5956

@kassens

Description

@kassens

The cache for making workers of jest-worker sticky to a worker using computeWorkerKey seems to only be set in the callback (code). In this example, even though computeWorkerKey is a function returning a constant, multiple workers are created.

This seems unintended?

const Worker = require('jest-worker').default;

async function main() {
  const myWorker = new Worker(require.resolve('./worker'), {
    computeWorkerKey: (method, ...args) => 'constant',
  });

  const workItems = new Set(['foo', 'bar', 'baz']);

  for (const workItem of workItems) {
    console.log('start', workItem);
    myWorker.transform('/tmp/foo.js').then(res => {
      console.log('done', workItem);
    })
  }

  myWorker.end();
}

main().then(undefined, err => {
  console.log(err);
});

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions