Skip to content

Commit 2d9eaab

Browse files
committed
chore: add node related files
1 parent 8ee58cf commit 2d9eaab

File tree

8 files changed

+103
-3
lines changed

8 files changed

+103
-3
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Type check
2727
run: deno task check
2828

29-
test:
29+
test-deno:
3030
runs-on: ubuntu-latest
3131
steps:
3232
- uses: actions/checkout@v4
@@ -45,6 +45,21 @@ jobs:
4545
files: ./coverage.lcov
4646
token: ${{ secrets.CODECOV_TOKEN }}
4747

48+
test-node:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: actions/setup-node@v1
53+
with:
54+
version: 22.x
55+
- name: Install deps
56+
run: |
57+
npx jsr install
58+
- name: Test
59+
run: |
60+
npx --yes tsx --test *_test.ts
61+
timeout-minutes: 5
62+
4863
jsr-publish:
4964
runs-on: ubuntu-latest
5065
steps:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/node_modules
12
/.tools
23
/.deno

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@jsr:registry=https://npm.jsr.io

_testutil.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Using `deadline` in `@std/[email protected]` cause the following error:
2+
// 'Promise resolution is still pending but the event loop has already resolved'
3+
// So we need to implement `deadline` by ourselves.
4+
export async function deadline<T>(
5+
promise: Promise<T>,
6+
timeout: number,
7+
): Promise<T> {
8+
const waiter = Promise.withResolvers<never>();
9+
const timer = setTimeout(
10+
() => waiter.reject(new DOMException("Signal timed out.")),
11+
timeout,
12+
);
13+
return await Promise.race([
14+
waiter.promise,
15+
promise.finally(() => clearTimeout(timer)),
16+
]);
17+
}

barrier_test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { test } from "@cross/test";
22
import { assertEquals, assertRejects, assertThrows } from "@std/assert";
3-
import { deadline, delay } from "@std/async";
3+
import { delay } from "@std/async";
44
import { Barrier } from "./barrier.ts";
5+
import { deadline } from "./_testutil.ts";
56

67
test(
78
"Barrier 'wait' waits until the number of waiters reached the size specified to the barrier",

package-lock.json

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "module",
3+
"dependencies": {
4+
"@core/iterutil": "npm:@jsr/core__iterutil@^0.6.0-pre.0",
5+
"@cross/test": "npm:@jsr/cross__test",
6+
"@std/assert": "npm:@jsr/std__assert",
7+
"@std/async": "npm:@jsr/std__async@^1.0.3"
8+
}
9+
}

wait_group_test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { test } from "@cross/test";
22
import { assertEquals, assertRejects, assertThrows } from "@std/assert";
3-
import { deadline, delay } from "@std/async";
3+
import { delay } from "@std/async";
44
import { WaitGroup } from "./wait_group.ts";
5+
import { deadline } from "./_testutil.ts";
56

67
test(
78
"WaitGroup Ensure WaitGroup synchronizes multiple workers",

0 commit comments

Comments
 (0)