Merge pull request #80 from TheBlueMatt/main
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Mon, 17 Jan 2022 21:42:15 +0000 (21:42 +0000)
committerGitHub <noreply@github.com>
Mon, 17 Jan 2022 21:42:15 +0000 (21:42 +0000)
Fix TypeScript CI + Package Missing FIles

.github/workflows/build.yml
ts/package.json
ts/test/browser.mjs
ts/test/tests.mts

index a7cd7bbd2c5a2e2fd98220b3c89532280c0101e8..74b9bc5b907f4db9bd98fcee1f1243f75bf62709 100644 (file)
@@ -74,7 +74,9 @@ jobs:
           cd ts
           rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_debug.wasm ./liblightningjs.wasm
           python3 -m http.server &
+          SERVER_PID=$!
           node test/browser.mjs
+          kill $SERVER_PID
       - name: Build and Test TS Release Bindings for Web
         run: |
           export HOME=/root/ # Github actions is apparently broken
@@ -82,7 +84,10 @@ jobs:
           ./genbindings.sh ./ldk-c-bindings/ wasm false true
           cd ts
           rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_release.wasm ./liblightningjs.wasm
+          python3 -m http.server &
+          SERVER_PID=$!
           node test/browser.mjs
+          kill $SERVER_PID
       - name: Check latest TS files are in git
         run: |
           git diff --exit-code
index 48d3a67cd53c2b571ab657d2822486756386d5ad..ea51b312b8e87896bb673b31cf9469538603cf50 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "lightningdevkit",
-  "version": "0.0.104.1alpha2",
+  "version": "0.0.104.1alpha3",
   "description": "Lightning Development Kit",
   "main": "index.mjs",
   "type": "module",
@@ -14,6 +14,7 @@
     "enums/*.d.mts",
     "bindings.mjs",
     "bindings.d.mts",
+    "version.mjs",
     "liblightningjs.wasm",
     "tsconfig.json",
     "README.md",
index 03b5141415f860e53d4cdc9b31c1bfbdf0e1e086..5f65191a3bb7df5d221a9d21bdd1eb5d31281620 100644 (file)
@@ -2,13 +2,27 @@ 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 => {
+               const values = [];
+               for (const arg of msg.args())
+                       values.push(await arg.jsonValue());
+               console.log(...values);
        });
+       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();
index 751d7ddf98094c3a5f40fcadf36b79e5f14bc5c2..4299f3b83636f756618a33500fe285a0f13d96c2 100644 (file)
@@ -197,7 +197,7 @@ tests.push(async () => {
        return true;
 });
 
-export async function run_tests(wasm_path: string) {
+export async function run_tests(wasm_path: string, check_leaks: boolean = true) {
        await rawldk.initializeWasm(wasm_path);
 
        var test_runs = [];
@@ -208,7 +208,7 @@ export async function run_tests(wasm_path: string) {
        console.log("test results: " + results);
        const result = results.every((v) => { return v === true });
        console.log("all tests passed: " + result);
-       if (result !== true) { return result; }
+       if (result !== true || !check_leaks) { return result; }
 
        const allocs_finished = new Promise((resolve, reject) => {
                var loop_count = 0;
@@ -216,10 +216,15 @@ export async function run_tests(wasm_path: string) {
                        const alloc_count = rawldk.getRemainingAllocationCount();
                        if (loop_count % 20 == 0)
                                console.log("Remaining LDK allocation count: " + alloc_count);
+
+                       // chromium with --js-flags="--expose-gc" exposes a `window.gc()` which we call if we can
+                       // @ts-ignore window.gc is considered a type error in TS
+                       if (typeof window !== "undefined" && typeof window.gc !== "undefined") window.gc();
+
                        // Note that there are currently 9 leaks in the above tests. At least some are known - look for XXX in bindings.c
-                       if (alloc_count <= 10) { resolve(true); clearInterval(interval_id); }
+                       if (alloc_count <= 10) { clearInterval(interval_id); rawldk.debugPrintRemainingAllocs(); resolve(true); }
                        loop_count += 1;
-                       if (loop_count > 30*2) { resolve(false); clearInterval(interval_id); rawldk.debugPrintRemainingAllocs(); }
+                       if (loop_count > 30*2) { clearInterval(interval_id); rawldk.debugPrintRemainingAllocs(); resolve(false); }
                }, 500);
        });
        return allocs_finished;