From 2f412869d72b085c937283ac41645979aeae0bd9 Mon Sep 17 00:00:00 2001 From: Ian Bull Date: Thu, 31 Oct 2024 13:12:39 -0700 Subject: [PATCH] chore: update to Deno 2 This is a work in progress, I just want to test the CI. This change-set also updates the formatting of several files as the rules have changed with Deno 2. --- .github/workflows/ci.yml | 6 ++--- test/dynamic-import.test.ts | 2 +- test/helpers.ts | 44 ++++++++++++++++++++++++------------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c68551..51ce0e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,10 +14,10 @@ jobs: - name: Clone repository uses: actions/checkout@v3 - - name: Setup Deno 1.x - uses: denoland/setup-deno@v1 + - name: Setup Deno 2.x + uses: denoland/setup-deno@v2 with: - deno-version: v1.x + deno-version: v2.x - name: Setup Node 18 uses: actions/setup-node@v3 diff --git a/test/dynamic-import.test.ts b/test/dynamic-import.test.ts index 7c612f7..90150fb 100644 --- a/test/dynamic-import.test.ts +++ b/test/dynamic-import.test.ts @@ -24,6 +24,6 @@ Deno.test({ assert(div, "div exists"); }); - app.stop(); + await app.stop(); }, }); diff --git a/test/helpers.ts b/test/helpers.ts index 7b5157e..a0b97d3 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -1,6 +1,5 @@ -import { fromFileUrl } from "https://deno.land/std@0.110.0/path/mod.ts"; -import { assert } from "https://deno.land/std@0.158.0/testing/asserts.ts"; -import { readableStreamFromReader } from "https://deno.land/std@0.142.0/streams/conversion.ts"; +import { fromFileUrl } from "jsr:@std/path@1.0"; +import { assert } from "jsr:@std/assert@1.0"; const dir = new URL("./", import.meta.url); const defaultURL = new URL("http://localhost:8085/"); @@ -12,18 +11,19 @@ export const defaultTestPermissions: Deno.PermissionOptions = { env: true, }; -declare type ExitCallback = () => void; +declare type ExitCallback = () => Promise; export async function runBuild(fixturePath: string) { - const proc = Deno.run({ - cmd: ["node_modules/.bin/astro", "build", "--silent"], + const command = new Deno.Command("node_modules/.bin/astro", { + args: ["build", "--silent"], cwd: fromFileUrl(new URL(fixturePath, dir)), }); + const process = command.spawn(); try { - const status = await proc.status(); + const status = await process.status; assert(status.success); } finally { - proc.close(); + safeKill(process); } } @@ -42,22 +42,36 @@ export async function startModFromSubprocess( baseUrl: URL, ): Promise { const entryUrl = new URL("./dist/server/entry.mjs", baseUrl); - const proc = Deno.run({ - cmd: ["deno", "run", "--allow-env", "--allow-net", fromFileUrl(entryUrl)], + const command = new Deno.Command("deno", { + args: ["run", "--allow-env", "--allow-net", fromFileUrl(entryUrl)], cwd: fromFileUrl(baseUrl), stderr: "piped", }); - - const stderr = readableStreamFromReader(proc.stderr); + const process = command.spawn(); + const reader = process.stderr.getReader(); const dec = new TextDecoder(); - for await (const bytes of stderr) { - const msg = dec.decode(bytes); + + while (true) { + const { value } = await reader.read(); + const msg = dec.decode(value); if (msg.includes(`Server running`)) { break; } } + await reader.cancel(); + + return async () => { + safeKill(process); + await process.status; + }; +} - return () => proc.close(); +function safeKill(process: Deno.ChildProcess) { + try { + process.kill("SIGKILL"); + } catch { + // ignore + } } export async function runBuildAndStartApp(fixturePath: string) {