Skip to content

Commit

Permalink
Respect --maxWorkers (nicolo-ribaudo#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo authored Apr 6, 2022
1 parent 65b7725 commit d32ad05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ The lists below are not comprehensive: feel free to [start a discussion](https:/
- Jest globals: `expect`, `test`, `it`, `describe`, `beforeAll`, `afterAll`, `beforeEach`, `afterEach`
- Jest function mocks: `jest.fn`, `jest.spyOn`
- Inline and external snapshots
- `--testNamePattern`/`-t`, to only run some specific tests
- Jest config options: `setupFiles`, `snapshotSerializers`
- Jest cli options: `--testNamePattern`/`-t`, `--maxWorkers`
- Jest config options: `setupFiles`, `snapshotSerializers`, `maxWorkers`

### Unsupported Jest features

Expand Down
26 changes: 13 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Piscina } from "piscina";
import supportsColor from "supports-color";
import { MessageChannel } from "worker_threads";
import os from "os";

/** @typedef {import("@jest/test-result").Test} Test */

const piscina = new Piscina({
filename: new URL("./worker-runner.js", import.meta.url).href,
maxThreads: os.cpus().length / 2,
env: {
// Workers don't have a tty; we whant them to inherit
// the color support level from the main thread.
FORCE_COLOR: supportsColor.stdout.level,
...process.env,
},
});

export default class LightRunner {
#config;
#piscina;

constructor(config) {
this.#config = config;

this.#piscina = new Piscina({
filename: new URL("./worker-runner.js", import.meta.url).href,
maxThreads: this.#config.maxWorkers,
env: {
// Workers don't have a tty; we whant them to inherit
// the color support level from the main thread.
FORCE_COLOR: supportsColor.stdout.level,
...process.env,
},
});
}

/**
Expand All @@ -39,7 +39,7 @@ export default class LightRunner {
mc.port2.onmessage = () => onStart(test);
mc.port2.unref();

return piscina
return this.#piscina
.run(
{ test, updateSnapshot, testNamePattern, port: mc.port1 },
{ transferList: [mc.port1] }
Expand Down

0 comments on commit d32ad05

Please sign in to comment.