Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ jobs:
- name: Type check project
run: deno task check:types

- name: Disable AppArmor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is worth trying.

if: ${{ matrix.os == 'ubuntu-latest' }}
run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns

- name: Run tests
run: deno task test

Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@std/semver": "jsr:@std/semver@1",
"@std/streams": "jsr:@std/streams@1",

"@astral/astral": "jsr:@astral/astral@^0.5.2",
"@astral/astral": "jsr:@astral/astral@^0.5.3",
"@marvinh-test/fresh-island": "jsr:@marvinh-test/fresh-island@^0.0.1",
"linkedom": "npm:linkedom@^0.16.11",
"@std/async": "jsr:@std/async@1",
Expand Down
8 changes: 4 additions & 4 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 21 additions & 29 deletions tests/test_utils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { App, getIslandRegistry, setBuildCache } from "../src/app.ts";
import { launch, type Page } from "@astral/astral";
import * as colors from "@std/fmt/colors";
import { type Document, DOMParser, HTMLElement } from "linkedom";
import { DOMParser, HTMLElement } from "linkedom";
import { Builder } from "../src/dev/builder.ts";
import { TextLineStream } from "@std/streams/text-line-stream";
import * as path from "@std/path";
Expand All @@ -28,6 +28,23 @@ import { NodeProcess } from "./fixtures_islands/NodeProcess.tsx";
import { FreshAttrs } from "./fixtures_islands/FreshAttrs.tsx";
import { OptOutPartialLink } from "./fixtures_islands/OptOutPartialLink.tsx";

/**
* If on Linux, disable `AppArmor` before running tests:
* ```sh
* echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns
* ```
*
* @see {@link https://github.com/lino-levan/astral#no-usable-sandbox-with-user-namespace-cloning-enabled}
*/
const browser = await launch({
args: ["--window-size=1280,720"],
headless: true,
});

addEventListener("unload", async () => {
await browser.close();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lino-levan, when I use await using, tests hang.


export function getIsland(pathname: string) {
return path.join(
import.meta.dirname!,
Expand Down Expand Up @@ -79,44 +96,22 @@ export async function withBrowserApp(
fn: (page: Page, address: string) => void | Promise<void>,
) {
const aborter = new AbortController();
const server = Deno.serve({
await using server = Deno.serve({
hostname: "localhost",
port: 0,
signal: aborter.signal,
}, await app.handler());

const browser = await launch({
args: [
"--window-size=1280,720",
...((Deno.env.get("CI") && Deno.build.os === "linux")
? ["--no-sandbox"]
: []),
],
headless: true,
});

const page = await browser.newPage();
try {
await using page = await browser.newPage();
await fn(page, `http://localhost:${server.addr.port}`);
} finally {
await page.close();
await browser.close();
aborter.abort();
await server?.finished;
}
}

export async function withBrowser(fn: (page: Page) => void | Promise<void>) {
const browser = await launch({
args: [
"--window-size=1280,7201",
...((Deno.env.get("CI") && Deno.build.os === "linux")
? ["--no-sandbox"]
: []),
],
headless: true,
});
const page = await browser.newPage();
await using page = await browser.newPage();
try {
await fn(page);
} catch (err) {
Expand All @@ -126,9 +121,6 @@ export async function withBrowser(fn: (page: Page) => void | Promise<void>) {
// deno-lint-ignore no-console
console.log(html);
throw err;
} finally {
await page.close();
await browser.close();
}
}

Expand Down
Loading