worker-testbed 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +8 -2
- package/build/index.mjs +8 -2
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/build/index.cjs
CHANGED
|
@@ -29,9 +29,10 @@ const test = async (testName, cb) => {
|
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
const workerFile = await waitForFile();
|
|
32
|
+
testCounter += 1;
|
|
32
33
|
tape(testName, async (test) => {
|
|
33
34
|
const [awaiter, { resolve }] = functoolsKit.createAwaiter();
|
|
34
|
-
|
|
35
|
+
let isFinished = false;
|
|
35
36
|
const worker = new worker_threads.Worker(workerFile, {
|
|
36
37
|
workerData: { testName },
|
|
37
38
|
});
|
|
@@ -42,6 +43,8 @@ const test = async (testName, cb) => {
|
|
|
42
43
|
else if (status === "fail") {
|
|
43
44
|
test.fail(msg);
|
|
44
45
|
}
|
|
46
|
+
isFinished = true;
|
|
47
|
+
worker.terminate();
|
|
45
48
|
resolve();
|
|
46
49
|
});
|
|
47
50
|
worker.on("error", (err) => {
|
|
@@ -49,6 +52,9 @@ const test = async (testName, cb) => {
|
|
|
49
52
|
resolve();
|
|
50
53
|
});
|
|
51
54
|
worker.on("exit", (code) => {
|
|
55
|
+
if (isFinished) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
52
58
|
if (code !== 0) {
|
|
53
59
|
test.fail(`Worker stopped with exit code ${code}`);
|
|
54
60
|
resolve();
|
|
@@ -61,7 +67,7 @@ const test = async (testName, cb) => {
|
|
|
61
67
|
}
|
|
62
68
|
});
|
|
63
69
|
};
|
|
64
|
-
const run = async (__filename, cb) => {
|
|
70
|
+
const run = async (__filename, cb = () => { }) => {
|
|
65
71
|
if (worker_threads.isMainThread) {
|
|
66
72
|
await workerFileSubject.next(url.fileURLToPath(__filename));
|
|
67
73
|
await finishSubject.filter(() => testCounter === 0).toPromise();
|
package/build/index.mjs
CHANGED
|
@@ -27,9 +27,10 @@ const test = async (testName, cb) => {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
const workerFile = await waitForFile();
|
|
30
|
+
testCounter += 1;
|
|
30
31
|
tape(testName, async (test) => {
|
|
31
32
|
const [awaiter, { resolve }] = createAwaiter();
|
|
32
|
-
|
|
33
|
+
let isFinished = false;
|
|
33
34
|
const worker = new Worker(workerFile, {
|
|
34
35
|
workerData: { testName },
|
|
35
36
|
});
|
|
@@ -40,6 +41,8 @@ const test = async (testName, cb) => {
|
|
|
40
41
|
else if (status === "fail") {
|
|
41
42
|
test.fail(msg);
|
|
42
43
|
}
|
|
44
|
+
isFinished = true;
|
|
45
|
+
worker.terminate();
|
|
43
46
|
resolve();
|
|
44
47
|
});
|
|
45
48
|
worker.on("error", (err) => {
|
|
@@ -47,6 +50,9 @@ const test = async (testName, cb) => {
|
|
|
47
50
|
resolve();
|
|
48
51
|
});
|
|
49
52
|
worker.on("exit", (code) => {
|
|
53
|
+
if (isFinished) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
50
56
|
if (code !== 0) {
|
|
51
57
|
test.fail(`Worker stopped with exit code ${code}`);
|
|
52
58
|
resolve();
|
|
@@ -59,7 +65,7 @@ const test = async (testName, cb) => {
|
|
|
59
65
|
}
|
|
60
66
|
});
|
|
61
67
|
};
|
|
62
|
-
const run = async (__filename, cb) => {
|
|
68
|
+
const run = async (__filename, cb = () => { }) => {
|
|
63
69
|
if (isMainThread) {
|
|
64
70
|
await workerFileSubject.next(fileURLToPath(__filename));
|
|
65
71
|
await finishSubject.filter(() => testCounter === 0).toPromise();
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ interface ITest {
|
|
|
3
3
|
fail(msg?: string): void;
|
|
4
4
|
}
|
|
5
5
|
declare const test: (testName: string, cb: (t: ITest) => void) => Promise<void>;
|
|
6
|
-
declare const run: (__filename: string, cb
|
|
6
|
+
declare const run: (__filename: string, cb?: () => void) => Promise<void>;
|
|
7
7
|
|
|
8
8
|
export { run, test };
|