Skip to content

Commit

Permalink
Try this
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 17, 2021
1 parent a3347d3 commit ac23359
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion test/jest-light-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"jest-each": "^27.3.1",
"jest-mock": "^27.3.0",
"jest-snapshot": "^27.3.1",
"piscina": "^3.1.0"
"piscina": "^3.1.0",
"supports-color": "^9.0.2"
}
}
13 changes: 9 additions & 4 deletions test/jest-light-runner/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Piscina } from "piscina";
import { MessageChannel } from "worker_threads";
import os from "os";

import supportsColor from "supports-color";

import chalk from "chalk";
import tty from "tty";

Expand All @@ -18,11 +20,14 @@ console.log(
const piscina = new Piscina({
filename: new URL("./worker-runner.js", import.meta.url).href,
maxThreads: os.cpus().length / 2,
env: process.env,
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,
},
});

const isTTY = process.stdout.isTTY;

export default class LightRunner {
/**
* @param {Array<Test>} tests
Expand All @@ -39,7 +44,7 @@ export default class LightRunner {
mc.port2.unref();

return piscina
.run({ test, port: mc.port1, isTTY }, { transferList: [mc.port1] })
.run({ test, port: mc.port1 }, { transferList: [mc.port1] })
.then(
result => onResult(test, result),
error => onFailure(test, error)
Expand Down
6 changes: 1 addition & 5 deletions test/jest-light-runner/src/worker-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ import "./global-setup.js";
};
}

export default async function ({ test, port, isTTY }) {
export default async function ({ test, port }) {
port.postMessage("start");

// worker_threads always report isTTY as false;
// inherit it from the main thread
process.stdout.isTTY = isTTY;

const stats = { passes: 0, failures: 0, pending: 0 };
const results = [];
const { tests, hasFocusedTests } = await loadTests(test.path);
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ __metadata:
jest-mock: ^27.3.0
jest-snapshot: ^27.3.1
piscina: ^3.1.0
supports-color: ^9.0.2
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -9272,6 +9273,13 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"has-flag@npm:^5.0.0":
version: 5.0.1
resolution: "has-flag@npm:5.0.1"
checksum: e0a151db8e43b528258c4269c23224c691b42c1f5168f6d88b61c3f9398ef16d44226a78a0596642da55851cf306a8afe57d6936d4d69a24b66fd10de1373da8
languageName: node
linkType: hard

"has-symbols@npm:^1.0.1, has-symbols@npm:^1.0.2":
version: 1.0.2
resolution: "has-symbols@npm:1.0.2"
Expand Down Expand Up @@ -14553,6 +14561,15 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"supports-color@npm:^9.0.2":
version: 9.0.2
resolution: "supports-color@npm:9.0.2"
dependencies:
has-flag: ^5.0.0
checksum: 690c21f61945a1ebab61fbc9dc861672b1d9678359ce75312b8b7ecb873f37f2ed2df56daa4ef4265300bea2e51f8285831ffb0a190ac46aaeed1d5b44fd51fe
languageName: node
linkType: hard

"supports-hyperlinks@npm:^2.0.0":
version: 2.1.0
resolution: "supports-hyperlinks@npm:2.1.0"
Expand Down

0 comments on commit ac23359

Please sign in to comment.