worker-testbed 1.0.0 → 1.0.2
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 +31 -30
- package/build/index.mjs +31 -30
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/build/index.cjs
CHANGED
|
@@ -21,41 +21,42 @@ class TestWrapper {
|
|
|
21
21
|
this.cb = cb;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
const test = (testName, cb) => {
|
|
25
|
-
if (worker_threads.isMainThread) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
const test = async (testName, cb) => {
|
|
25
|
+
if (!worker_threads.isMainThread) {
|
|
26
|
+
testRegistry = testRegistry.register(testName, new TestWrapper(testName, cb));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const workerFile = await waitForFile();
|
|
30
|
+
tape(testName, async (test) => {
|
|
31
|
+
const [awaiter, { resolve }] = functoolsKit.createAwaiter();
|
|
32
|
+
const worker = new worker_threads.Worker(workerFile, {
|
|
33
|
+
workerData: { testName },
|
|
34
|
+
});
|
|
35
|
+
worker.once("message", ({ status, msg }) => {
|
|
36
|
+
if (status === "pass") {
|
|
37
|
+
test.pass(msg);
|
|
38
|
+
}
|
|
39
|
+
else if (status === "fail") {
|
|
40
|
+
test.fail(msg);
|
|
41
|
+
}
|
|
42
|
+
resolve();
|
|
43
|
+
});
|
|
44
|
+
worker.on("error", (err) => {
|
|
45
|
+
test.fail(`Worker error: ${err.message}`);
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
worker.on("exit", (code) => {
|
|
49
|
+
if (code !== 0) {
|
|
50
|
+
test.fail(`Worker stopped with exit code ${code}`);
|
|
43
51
|
resolve();
|
|
44
|
-
}
|
|
45
|
-
worker.on("exit", (code) => {
|
|
46
|
-
if (code !== 0) {
|
|
47
|
-
test.fail(`Worker stopped with exit code ${code}`);
|
|
48
|
-
resolve();
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return await awaiter;
|
|
52
|
+
}
|
|
52
53
|
});
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
return await awaiter;
|
|
55
|
+
});
|
|
55
56
|
};
|
|
56
57
|
const run = async (__filename) => {
|
|
57
58
|
if (worker_threads.isMainThread) {
|
|
58
|
-
workerFileSubject.next(url.fileURLToPath(__filename));
|
|
59
|
+
await workerFileSubject.next(url.fileURLToPath(__filename));
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
61
62
|
if (!worker_threads.parentPort) {
|
package/build/index.mjs
CHANGED
|
@@ -19,41 +19,42 @@ class TestWrapper {
|
|
|
19
19
|
this.cb = cb;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
const test = (testName, cb) => {
|
|
23
|
-
if (isMainThread) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const test = async (testName, cb) => {
|
|
23
|
+
if (!isMainThread) {
|
|
24
|
+
testRegistry = testRegistry.register(testName, new TestWrapper(testName, cb));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const workerFile = await waitForFile();
|
|
28
|
+
tape(testName, async (test) => {
|
|
29
|
+
const [awaiter, { resolve }] = createAwaiter();
|
|
30
|
+
const worker = new Worker(workerFile, {
|
|
31
|
+
workerData: { testName },
|
|
32
|
+
});
|
|
33
|
+
worker.once("message", ({ status, msg }) => {
|
|
34
|
+
if (status === "pass") {
|
|
35
|
+
test.pass(msg);
|
|
36
|
+
}
|
|
37
|
+
else if (status === "fail") {
|
|
38
|
+
test.fail(msg);
|
|
39
|
+
}
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
worker.on("error", (err) => {
|
|
43
|
+
test.fail(`Worker error: ${err.message}`);
|
|
44
|
+
resolve();
|
|
45
|
+
});
|
|
46
|
+
worker.on("exit", (code) => {
|
|
47
|
+
if (code !== 0) {
|
|
48
|
+
test.fail(`Worker stopped with exit code ${code}`);
|
|
41
49
|
resolve();
|
|
42
|
-
}
|
|
43
|
-
worker.on("exit", (code) => {
|
|
44
|
-
if (code !== 0) {
|
|
45
|
-
test.fail(`Worker stopped with exit code ${code}`);
|
|
46
|
-
resolve();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return await awaiter;
|
|
50
|
+
}
|
|
50
51
|
});
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
return await awaiter;
|
|
53
|
+
});
|
|
53
54
|
};
|
|
54
55
|
const run = async (__filename) => {
|
|
55
56
|
if (isMainThread) {
|
|
56
|
-
workerFileSubject.next(fileURLToPath(__filename));
|
|
57
|
+
await workerFileSubject.next(fileURLToPath(__filename));
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
60
|
if (!parentPort) {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ interface ITest {
|
|
|
2
2
|
pass(msg?: string): void;
|
|
3
3
|
fail(msg?: string): void;
|
|
4
4
|
}
|
|
5
|
-
declare const test: (testName: string, cb: (t: ITest) => void) => void
|
|
5
|
+
declare const test: (testName: string, cb: (t: ITest) => void) => Promise<void>;
|
|
6
6
|
declare const run: (__filename: string) => Promise<void>;
|
|
7
7
|
|
|
8
8
|
export { run, test };
|