[TS] Fix CI when we log while the browser is shutting down
[ldk-java] / ts / test / browser.mjs
index 03b5141415f860e53d4cdc9b31c1bfbdf0e1e086..e4e6112cbc88c065b162d38245b7508e17493d97 100644 (file)
@@ -2,13 +2,29 @@ import { chromium, firefox, webkit } from 'playwright';
 import { strict as assert } from 'assert';
 
 for (const browserType of [chromium, firefox]) { // We'd like to test webkit, but playwright doesn't support it on Debian (?!)
-       const browser = await browserType.launch();
+       var browser;
+       if (browserType == chromium)
+               browser = await browserType.launch(["--js-flags=\"--expose-gc\""]);
+       else
+               browser = await browserType.launch();
        const context = await browser.newContext();
        const page = await context.newPage();
-       await page.goto('http://localhost:8000/test/index.html');
-       const ret = await page.evaluate(() => {
-               return test_runner('../liblightningjs.wasm');
+       page.on('console', async msg => {
+               try {
+                       const values = [];
+                       for (const arg of msg.args())
+                               values.push(await arg.jsonValue());
+                       console.log(...values);
+               } catch (_) { /* sometimes this gets hit if we're logging while the browser shuts down */ }
        });
+       await page.goto('http://localhost:8000/test/index.html');
+       var ret;
+       // On chromium we expose the GC and can run it manually, otherwise we really can't leak-check
+       if (browserType == chromium) {
+               ret = await page.evaluate(() => { return test_runner('../liblightningjs.wasm', true); });
+       } else {
+               ret = await page.evaluate(() => { return test_runner('../liblightningjs.wasm', false); });
+       }
        assert(ret);
 
        await browser.close();