worker-testbed 1.0.4 → 1.0.6
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/README.md +2 -2
- package/build/index.cjs +6 -0
- package/build/index.mjs +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# worker-testbed
|
|
2
2
|
|
|
3
3
|
> The AI-ready testbed which use Worker Threads to create isolated vm context
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ A worker-threads based test framework using `Node.js`, `tape`, and `functools-ki
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
9
|
```tsx
|
|
10
|
-
import { run, test } from '
|
|
10
|
+
import { run, test } from 'worker-testbed';
|
|
11
11
|
|
|
12
12
|
test("Will pass after three seconds", (t) => {
|
|
13
13
|
globalThis.test = {};
|
package/build/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ const test = async (testName, cb) => {
|
|
|
32
32
|
testCounter += 1;
|
|
33
33
|
tape(testName, async (test) => {
|
|
34
34
|
const [awaiter, { resolve }] = functoolsKit.createAwaiter();
|
|
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();
|
package/build/index.mjs
CHANGED
|
@@ -30,6 +30,7 @@ const test = async (testName, cb) => {
|
|
|
30
30
|
testCounter += 1;
|
|
31
31
|
tape(testName, async (test) => {
|
|
32
32
|
const [awaiter, { resolve }] = createAwaiter();
|
|
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();
|