Skip to content

Commit 6c782c7

Browse files
committed
Some cleanup
1 parent 61761e8 commit 6c782c7

File tree

8 files changed

+40
-73
lines changed

8 files changed

+40
-73
lines changed

Untitled-1

Lines changed: 0 additions & 12 deletions
This file was deleted.

a.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/index.js

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
require('babel-polyfill');
2-
const throat = require('throat');
3-
const pify = require('pify');
4-
const workerFarm = require('worker-farm');
5-
const path = require('path');
6-
7-
const runPath = path.resolve(__dirname, 'run.js');
1+
const Worker = require('jest-worker');
82

93
class CancelRun extends Error {
104
constructor(message) {
@@ -13,53 +7,36 @@ class CancelRun extends Error {
137
}
148
}
159

16-
const createRunner = (fn, { extraOptions } = {}) => {
10+
const createRunner = runPath => {
1711
class BaseTestRunner {
1812
constructor(globalConfig) {
1913
this._globalConfig = globalConfig;
2014
}
2115

2216
// eslint-disable-next-line
2317
async runTests(tests, watcher, onStart, onResult, onFailure, options) {
24-
const farm = workerFarm(
25-
{
26-
autoStart: true,
27-
maxConcurrentCallsPerWorker: 1,
28-
maxConcurrentWorkers: this._globalConfig.maxWorkers,
29-
maxRetries: 2, // Allow for a couple of transient errors.
30-
},
31-
runPath,
32-
);
33-
34-
const mutex = throat(this._globalConfig.maxWorkers);
35-
const worker = pify(farm);
36-
37-
const runTestInWorker = test =>
38-
mutex(async () => {
39-
if (watcher.isInterrupted()) {
40-
throw new CancelRun();
41-
}
42-
await onStart(test);
43-
const baseOptions = {
44-
config: test.context.config,
45-
globalConfig: this._globalConfig,
46-
testPath: test.path,
47-
rawModuleMap: watcher.isWatchMode()
48-
? test.context.moduleMap.getRawModuleMap()
49-
: null,
50-
options,
51-
};
18+
const worker = new Worker(runPath, {
19+
exposedMethods: ['default'],
20+
numWorkers: this._globalConfig.maxWorkers,
21+
});
5222

53-
if (extraOptions) {
54-
return Object.assign(
55-
{},
56-
baseOptions,
57-
extraOptions(baseOptions, tests),
58-
);
59-
}
23+
const runTestInWorker = async test => {
24+
if (watcher.isInterrupted()) {
25+
throw new CancelRun();
26+
}
27+
await onStart(test);
28+
const baseOptions = {
29+
config: test.context.config,
30+
globalConfig: this._globalConfig,
31+
testPath: test.path,
32+
rawModuleMap: watcher.isWatchMode()
33+
? test.context.moduleMap.getRawModuleMap()
34+
: null,
35+
options,
36+
};
6037

61-
return worker(baseOptions);
62-
});
38+
return worker.default(baseOptions);
39+
};
6340

6441
const onError = async (err, test) => {
6542
await onFailure(test, err);
@@ -89,7 +66,7 @@ const createRunner = (fn, { extraOptions } = {}) => {
8966
),
9067
);
9168

92-
const cleanup = () => workerFarm.end(farm);
69+
const cleanup = () => worker.end();
9370

9471
return Promise.race([runAllTests, onInterrupt]).then(cleanup, cleanup);
9572
}

lib/run.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/utils.js

Whitespace-only changes.

message.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"license": "MIT",
88
"repository": "https://github.com/rogeliog/create-jest-runner.git",
99
"homepage": "https://github.com/rogeliog/create-jest-runner",
10-
"files": ["build/"],
10+
"files": [
11+
"build/"
12+
],
1113
"scripts": {
1214
"test": "jest",
1315
"lint": "eslint .",
@@ -20,6 +22,7 @@
2022
"babel-plugin-istanbul": "4.1.4",
2123
"babel-polyfill": "^6.26.0",
2224
"babel-register": "6.26.0",
25+
"jest-worker": "21.3.0-beta.2",
2326
"lodash": "4.17.4",
2427
"minimatch": "3.0.4",
2528
"mocha": "3.5.0",

yarn.lock

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,12 @@ jest-validate@^21.0.2:
21302130
leven "^2.1.0"
21312131
pretty-format "^21.0.2"
21322132

2133+
2134+
version "21.3.0-beta.2"
2135+
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-21.3.0-beta.2.tgz#05eba2afe4bffffdba6fb0a49016b628382b8234"
2136+
dependencies:
2137+
merge-stream "^1.0.1"
2138+
21332139
jest@^21.0.2:
21342140
version "21.0.2"
21352141
resolved "https://registry.yarnpkg.com/jest/-/jest-21.0.2.tgz#a5c9bdc9d4322ae672fe8cb3eaf25c268c5f04b2"
@@ -2369,6 +2375,12 @@ mem@^1.1.0:
23692375
dependencies:
23702376
mimic-fn "^1.0.0"
23712377

2378+
merge-stream@^1.0.1:
2379+
version "1.0.1"
2380+
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1"
2381+
dependencies:
2382+
readable-stream "^2.0.1"
2383+
23722384
merge@^1.1.3:
23732385
version "1.2.0"
23742386
resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.0.tgz#7531e39d4949c281a66b8c5a6e0265e8b05894da"
@@ -2811,7 +2823,7 @@ read-pkg@^2.0.0:
28112823
normalize-package-data "^2.3.2"
28122824
path-type "^2.0.0"
28132825

2814-
readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.2:
2826+
readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.2:
28152827
version "2.3.3"
28162828
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c"
28172829
dependencies:

0 commit comments

Comments
 (0)