Skip to content

Commit

Permalink
chore: update to Deno 2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
irbull committed Oct 31, 2024
1 parent aaa1125 commit 2f41286
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/dynamic-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Deno.test({
assert(div, "div exists");
});

app.stop();
await app.stop();
},
});
44 changes: 29 additions & 15 deletions test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { fromFileUrl } from "https://deno.land/[email protected]/path/mod.ts";
import { assert } from "https://deno.land/[email protected]/testing/asserts.ts";
import { readableStreamFromReader } from "https://deno.land/[email protected]/streams/conversion.ts";
import { fromFileUrl } from "jsr:@std/[email protected]";
import { assert } from "jsr:@std/[email protected]";

const dir = new URL("./", import.meta.url);
const defaultURL = new URL("http://localhost:8085/");
Expand All @@ -12,18 +11,19 @@ export const defaultTestPermissions: Deno.PermissionOptions = {
env: true,
};

declare type ExitCallback = () => void;
declare type ExitCallback = () => Promise<void>;

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);
}
}

Expand All @@ -42,22 +42,36 @@ export async function startModFromSubprocess(
baseUrl: URL,
): Promise<ExitCallback> {
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) {
Expand Down

0 comments on commit 2f41286

Please sign in to comment.