worker-testbed 1.0.5 → 1.0.7
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 +2 -2
- package/build/index.mjs +4 -4
- package/package.json +1 -1
- package/types.d.ts +3 -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
|
@@ -67,7 +67,7 @@ const test = async (testName, cb) => {
|
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
|
-
const run = async (__filename, cb = () => { }) => {
|
|
70
|
+
const run = functoolsKit.singleshot(async (__filename, cb = () => { }) => {
|
|
71
71
|
if (worker_threads.isMainThread) {
|
|
72
72
|
await workerFileSubject.next(url.fileURLToPath(__filename));
|
|
73
73
|
await finishSubject.filter(() => testCounter === 0).toPromise();
|
|
@@ -81,7 +81,7 @@ const run = async (__filename, cb = () => { }) => {
|
|
|
81
81
|
pass: (msg) => worker_threads.parentPort.postMessage({ status: "pass", msg }),
|
|
82
82
|
fail: (msg) => worker_threads.parentPort.postMessage({ status: "fail", msg }),
|
|
83
83
|
});
|
|
84
|
-
};
|
|
84
|
+
});
|
|
85
85
|
|
|
86
86
|
exports.run = run;
|
|
87
87
|
exports.test = test;
|
package/build/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isMainThread,
|
|
1
|
+
import { isMainThread, parentPort, workerData, Worker } from 'worker_threads';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import { BehaviorSubject, Subject, ToolRegistry, createAwaiter } from 'functools-kit';
|
|
3
|
+
import { BehaviorSubject, Subject, ToolRegistry, singleshot, createAwaiter } from 'functools-kit';
|
|
4
4
|
import tape from 'tape';
|
|
5
5
|
|
|
6
6
|
const workerFileSubject = new BehaviorSubject();
|
|
@@ -65,7 +65,7 @@ const test = async (testName, cb) => {
|
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
|
-
const run = async (__filename, cb = () => { }) => {
|
|
68
|
+
const run = singleshot(async (__filename, cb = () => { }) => {
|
|
69
69
|
if (isMainThread) {
|
|
70
70
|
await workerFileSubject.next(fileURLToPath(__filename));
|
|
71
71
|
await finishSubject.filter(() => testCounter === 0).toPromise();
|
|
@@ -79,6 +79,6 @@ const run = async (__filename, cb = () => { }) => {
|
|
|
79
79
|
pass: (msg) => parentPort.postMessage({ status: "pass", msg }),
|
|
80
80
|
fail: (msg) => parentPort.postMessage({ status: "fail", msg }),
|
|
81
81
|
});
|
|
82
|
-
};
|
|
82
|
+
});
|
|
83
83
|
|
|
84
84
|
export { run, test };
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import * as functools_kit from 'functools-kit';
|
|
2
|
+
|
|
1
3
|
interface ITest {
|
|
2
4
|
pass(msg?: string): void;
|
|
3
5
|
fail(msg?: string): void;
|
|
4
6
|
}
|
|
5
7
|
declare const test: (testName: string, cb: (t: ITest) => void) => Promise<void>;
|
|
6
|
-
declare const run: (__filename: string, cb?: () => void) => Promise<void
|
|
8
|
+
declare const run: ((__filename: string, cb?: () => void) => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
7
9
|
|
|
8
10
|
export { run, test };
|