lino-levan / astral

A high-level puppeteer/playwright-like library for Deno
https://jsr.io/@astral/astral
MIT License
176 stars 7 forks source link

Cannot get Astral to work with `deno test` #46

Closed cowboyd closed 7 months ago

cowboyd commented 7 months ago

Hi there. This seems like a great project.

I'm trying to integrate it into a test suite, but deno test complains that there are operations leaking....

When I run the following code: https://gist.github.com/cowboyd/c5735b5f80caf2e745dd93ee78cc48b7

import { describe, it } from "https://deno.land/std@0.206.0/testing/bdd.ts"
import { launch } from "https://deno.land/x/astral@0.3.1/mod.ts";

describe("browser", () => {
  it("launches, sleeps, and closes", async () => {
    let browser = await launch();
    await new Promise((resolve) => setTimeout(resolve, 2000));
    browser.close();
  });
});

I consistently see the following:

$ deno test -A browser.test.ts
Check browser.test.ts
running 1 test from browser.test.ts
browser ...
  launches, sleeps, and closes ... FAILED (2s)
browser ... FAILED (due to 1 failed step) (2s)

 ERRORS

browser ... launches, sleeps, and closes => https://deno.land/std@0.206.0/testing/_test_suite.ts:323:15
error: Leaking async ops:
  - 1 async operation to receive the next message on a WebSocket was started in this test, but never completed. This is often caused by not closing a `WebSocket` or `WebSocketStream`.
  - 1 async operation to op_spawn_wait was started in this test, but never completed.
To get more details where ops were leaked, run again with --trace-ops flag.

Should browser.close() be an async operation that waits until everything has been cleaned up?

cowboyd commented 7 months ago

browser.close() totally is async 🤦🏻

I think I might have gotten thrown off by some lag in deno lsp

lino-levan commented 7 months ago

Sorry for the trouble!