-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jsr-core/cross-test
test: add tests for Node/Bun
- Loading branch information
Showing
12 changed files
with
209 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Test (Node) | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22.x | ||
- name: Install deps | ||
run: | | ||
npx jsr install | ||
- name: Test | ||
run: | | ||
npx --yes tsx --test *_test.ts | ||
timeout-minutes: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/npm | ||
deno.lock | ||
.coverage | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@jsr:registry=https://npm.jsr.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"@core/unknownutil": "npm:@jsr/core__unknownutil@^4.2.0", | ||
"@cross/test": "npm:@jsr/cross__test@^0.0.9", | ||
"@std/assert": "npm:@jsr/std__assert@^1.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { test } from "@cross/test"; | ||
import { assertThrows } from "@std/assert"; | ||
import { raise } from "./raise.ts"; | ||
|
||
Deno.test("raise", () => { | ||
test("raise", () => { | ||
assertThrows(() => raise(new Error("error")), Error, "error"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,57 @@ | ||
import { test } from "@cross/test"; | ||
import { assertEquals, assertRejects, assertThrows } from "@std/assert"; | ||
import { raise } from "./raise.ts"; | ||
import { tryOrElse } from "./try_or_else.ts"; | ||
|
||
Deno.test("tryOrElse", async (t) => { | ||
const err = new Error("error"); | ||
const resolve = Promise.resolve.bind(Promise); | ||
const reject = Promise.reject.bind(Promise); | ||
const err = new Error("error"); | ||
const resolve = Promise.resolve.bind(Promise); | ||
const reject = Promise.reject.bind(Promise); | ||
|
||
await t.step("sync", () => { | ||
type T = number; | ||
assertEquals(tryOrElse((): T => 1, () => 2), 1); | ||
assertEquals(tryOrElse((): T => raise(err), () => 2), 2); | ||
}); | ||
await test("tryOrElse (sync)", () => { | ||
type T = number; | ||
assertEquals(tryOrElse((): T => 1, () => 2), 1); | ||
assertEquals(tryOrElse((): T => raise(err), () => 2), 2); | ||
}); | ||
|
||
await t.step("sync (error)", () => { | ||
type T = number; | ||
assertThrows( | ||
() => tryOrElse((): T => raise(err), () => raise(err)), | ||
Error, | ||
"error", | ||
); | ||
}); | ||
await test("tryOrElse with Error (sync)", () => { | ||
type T = number; | ||
assertThrows( | ||
() => tryOrElse((): T => raise(err), () => raise(err)), | ||
Error, | ||
"error", | ||
); | ||
}); | ||
|
||
await t.step("async", async () => { | ||
type T = Promise<number>; | ||
assertEquals(await tryOrElse((): T => resolve(1), () => 2), 1); | ||
assertEquals(await tryOrElse((): T => resolve(1), () => resolve(2)), 1); | ||
assertEquals(await tryOrElse((): T => reject(err), () => 2), 2); | ||
assertEquals(await tryOrElse((): T => reject(err), () => resolve(2)), 2); | ||
assertEquals(await tryOrElse((): T => raise(err), () => 2), 2); | ||
assertEquals(await tryOrElse((): T => raise(err), () => resolve(2)), 2); | ||
}); | ||
await test("tryOrElse (async)", async () => { | ||
type T = Promise<number>; | ||
assertEquals(await tryOrElse((): T => resolve(1), () => 2), 1); | ||
assertEquals(await tryOrElse((): T => resolve(1), () => resolve(2)), 1); | ||
assertEquals(await tryOrElse((): T => reject(err), () => 2), 2); | ||
assertEquals(await tryOrElse((): T => reject(err), () => resolve(2)), 2); | ||
assertEquals(await tryOrElse((): T => raise(err), () => 2), 2); | ||
assertEquals(await tryOrElse((): T => raise(err), () => resolve(2)), 2); | ||
}); | ||
|
||
await t.step("async (error)", async () => { | ||
type T = Promise<number>; | ||
await assertRejects( | ||
() => tryOrElse((): T => reject(err), () => reject(err)), | ||
Error, | ||
"error", | ||
); | ||
await assertRejects( | ||
() => tryOrElse((): T => reject(err), () => raise(err)), | ||
Error, | ||
"error", | ||
); | ||
await assertRejects( | ||
() => tryOrElse((): T => raise(err), () => reject(err)), | ||
Error, | ||
"error", | ||
); | ||
assertThrows( | ||
() => tryOrElse((): T => raise(err), () => raise(err)), | ||
Error, | ||
"error", | ||
); | ||
}); | ||
await test("tryOrElse with Error (async)", async () => { | ||
type T = Promise<number>; | ||
await assertRejects( | ||
() => tryOrElse((): T => reject(err), () => reject(err)), | ||
Error, | ||
"error", | ||
); | ||
await assertRejects( | ||
() => tryOrElse((): T => reject(err), () => raise(err)), | ||
Error, | ||
"error", | ||
); | ||
await assertRejects( | ||
() => tryOrElse((): T => raise(err), () => reject(err)), | ||
Error, | ||
"error", | ||
); | ||
assertThrows( | ||
() => tryOrElse((): T => raise(err), () => raise(err)), | ||
Error, | ||
"error", | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
import { test } from "@cross/test"; | ||
import { assertEquals } from "@std/assert"; | ||
import { raise } from "./raise.ts"; | ||
import { tryOr } from "./try_or.ts"; | ||
|
||
Deno.test("tryOr", async (t) => { | ||
const err = new Error("error"); | ||
const resolve = Promise.resolve.bind(Promise); | ||
const reject = Promise.reject.bind(Promise); | ||
const err = new Error("error"); | ||
const resolve = Promise.resolve.bind(Promise); | ||
const reject = Promise.reject.bind(Promise); | ||
|
||
await t.step("sync", () => { | ||
type T = number; | ||
assertEquals(tryOr((): T => 1, 2), 1); | ||
assertEquals(tryOr((): T => raise(err), 2), 2); | ||
}); | ||
await test("tryOr (sync)", () => { | ||
type T = number; | ||
assertEquals(tryOr((): T => 1, 2), 1); | ||
assertEquals(tryOr((): T => raise(err), 2), 2); | ||
}); | ||
|
||
await t.step("async", async () => { | ||
type T = Promise<number>; | ||
assertEquals(await tryOr((): T => resolve(1), 2), 1); | ||
assertEquals(await tryOr((): T => resolve(1), resolve(2)), 1); | ||
assertEquals(await tryOr((): T => reject(err), 2), 2); | ||
assertEquals(await tryOr((): T => reject(err), resolve(2)), 2); | ||
assertEquals(await tryOr((): T => raise(err), 2), 2); | ||
assertEquals(await tryOr((): T => raise(err), resolve(2)), 2); | ||
}); | ||
await test("tryOr (async)", async () => { | ||
type T = Promise<number>; | ||
assertEquals(await tryOr((): T => resolve(1), 2), 1); | ||
assertEquals(await tryOr((): T => resolve(1), resolve(2)), 1); | ||
assertEquals(await tryOr((): T => reject(err), 2), 2); | ||
assertEquals(await tryOr((): T => reject(err), resolve(2)), 2); | ||
assertEquals(await tryOr((): T => raise(err), 2), 2); | ||
assertEquals(await tryOr((): T => raise(err), resolve(2)), 2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { test } from "@cross/test"; | ||
import { assertThrows } from "@std/assert"; | ||
import { unimplemented, UnimplementedError } from "./unimplemented.ts"; | ||
|
||
test("unimplemented", () => { | ||
assertThrows(() => unimplemented(), UnimplementedError); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { test } from "@cross/test"; | ||
import { assertThrows } from "@std/assert"; | ||
import { unreachable, UnreachableError } from "./unreachable.ts"; | ||
|
||
test("unreachable", () => { | ||
assertThrows(() => unreachable(), UnreachableError); | ||
}); |