From 1a655e260c7ffbf0b1ba33305ae49984cea24fa1 Mon Sep 17 00:00:00 2001 From: Hexagon Date: Sun, 6 Oct 2024 23:49:30 +0200 Subject: [PATCH] Add long running test. Utilize cross-org standard workflow for ci.. --- .github/workflows/bun.yml | 30 ------------------------------ .github/workflows/deno.yml | 32 -------------------------------- .github/workflows/node.yml | 23 ----------------------- .github/workflows/test.yml | 23 +++++++++++++++++++++++ mod.test.ts | 14 +++++++++++--- shims/bun.ts | 2 +- shims/node.ts | 2 +- 7 files changed, 36 insertions(+), 90 deletions(-) delete mode 100644 .github/workflows/bun.yml delete mode 100644 .github/workflows/deno.yml delete mode 100644 .github/workflows/node.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/bun.yml b/.github/workflows/bun.yml deleted file mode 100644 index 0dec2a8..0000000 --- a/.github/workflows/bun.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Bun CI - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - test: - runs-on: ubuntu-latest - - strategy: - matrix: - bun-version: ["v1.x"] - - steps: - - name: Git Checkout - uses: actions/checkout@v3 - - name: Use Bun Version ${{ matrix.bun-version }} - uses: antongolub/action-setup-bun@v1.12.8 - with: - bun-version: ${{ matrix.bun-version }} - bun-repo: 'oven-sh/bun' - - name: Install Dependencies - run: bun x jsr add @cross/runtime @std/assert @std/async - - name: Install Sinon - run: bun add sinon - - name: Test Bun Module - run: bun test \ No newline at end of file diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml deleted file mode 100644 index f6ae40c..0000000 --- a/.github/workflows/deno.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Deno CI - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - name: Setup repo - uses: actions/checkout@v4 - - - name: Setup Deno - uses: denoland/setup-deno@v1 - with: - deno-version: v1.x - - - name: Verify formatting - run: deno fmt --check - - - name: Run linter - run: deno lint - - - name: Check types - run: deno check mod.ts - - - name: Run tests - run: deno test \ No newline at end of file diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml deleted file mode 100644 index ce2d791..0000000 --- a/.github/workflows/node.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Node.js CI - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.x, 21.x] - - steps: - - uses: actions/checkout@v3 - - run: npx jsr add @cross/runtime @std/assert @std/async - - run: npm i sinon - - run: "echo '{ \"type\": \"module\" }' > package.json" # Needed for tsx to work - - run: npx --yes tsx --test *.test.ts \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fdfd9d6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +on: + push: + branches: [main, dev] + pull_request: + branches: [main, dev] + +jobs: + deno_ci: + uses: cross-org/workflows/.github/workflows/deno-ci.yml@main + with: + entrypoint: mod.ts + lint_docs: false + bun_ci: + uses: cross-org/workflows/.github/workflows/bun-ci.yml@main + with: + jsr_dependencies: "@std/assert @std/async @cross/runtime" + npm_dependencies: "sinon" + node_ci: + uses: cross-org/workflows/.github/workflows/node-ci.yml@main + with: + test_target: "*.test.ts" + jsr_dependencies: "@std/assert @std/async @cross/runtime" + npm_dependencies: "sinon" \ No newline at end of file diff --git a/mod.test.ts b/mod.test.ts index 7b5ad5b..406fe39 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -1,5 +1,6 @@ import { test } from "./mod.ts"; import { assertEquals, assertNotEquals } from "@std/assert"; +import { delay } from "@std/async"; // Simple test test("Multiplication", () => { @@ -11,16 +12,23 @@ test("Multiplication with timeout", () => { assertEquals(5 * 4, 20); }, { timeout: 1000 }); -// Test with done callback (useful for async operations) -test("Async test", (_context, done) => { +// Failing async test with done callback +test("Long async test", (_context, done) => { setTimeout(() => { assertNotEquals(5, 4); done(); // Signal test completion }, 500); }, { waitForCallback: true }); +// Test with done callback (useful for async operations) +test("Async test", (_context, done) => { + setTimeout(() => { + assertNotEquals(5, 4); + done(); // Signal test completion + }, 4500); +}, { waitForCallback: true, timeout: 5500 }); + // Test async -import { delay } from "@std/async"; test("async hello world", async () => { const x = 1 + 2; diff --git a/shims/bun.ts b/shims/bun.ts index a78ad9d..aa218cf 100644 --- a/shims/bun.ts +++ b/shims/bun.ts @@ -5,7 +5,7 @@ export async function wrappedTest( testFn: TestSubject, options: WrappedTestOptions, ) { - const { test } = await import("bun:test"); + const { test } = await import("test"); return await test(name, async () => { // Adapt the context here let testFnPromise = undefined; diff --git a/shims/node.ts b/shims/node.ts index bb273f7..0cd8959 100644 --- a/shims/node.ts +++ b/shims/node.ts @@ -1,4 +1,4 @@ -import { test } from "node:test"; // For type safety +import { test } from "test"; // For type safety import type { WrappedTestOptions } from "../mod.ts"; // Shared options import type { TestSubject } from "../mod.ts";