MCPcopy
hub / github.com/jestjs/jest / testJestWorker

Function testJestWorker

packages/jest-worker/__benchmarks__/test.js:83–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81}
82
83function testJestWorker() {
84 return new Promise(async resolve => {
85 const startTime = performance.now();
86 let count = 0;
87
88 async function countToFinish() {
89 if (++count === calls) {
90 const endTime = performance.now();
91
92 // Let all workers go down.
93 await farm.end();
94
95 resolve({
96 globalTime: endTime - startTime - 2000,
97 processingTime: endTime - startProcess,
98 });
99 }
100 }
101
102 const farm = new JestWorker(require.resolve('./workers/jest_worker'), {
103 exposedMethods: [method],
104 forkOptions: {execArgv: []},
105 numWorkers: threads,
106 });
107
108 farm.getStdout().pipe(process.stdout);
109 farm.getStderr().pipe(process.stderr);
110
111 // Let all workers come up.
112 await farm.start();
113
114 const startProcess = performance.now();
115
116 for (let i = 0; i < calls; i++) {
117 const promisified = farm[method]();
118
119 promisified.then(countToFinish);
120 }
121 });
122}
123
124function profile(x) {
125 console.profile(x);

Callers 1

mainFunction · 0.85

Calls 6

thenMethod · 0.80
nowMethod · 0.65
getStdoutMethod · 0.65
getStderrMethod · 0.65
startMethod · 0.65
resolveMethod · 0.45

Tested by

no test coverage detected