Skip to content

Commit c3594d0

Browse files
authored
Merge pull request #80 from TheBlueMatt/main
Fix TypeScript CI + Package Missing FIles
2 parents 9d652fa + 0b84bd2 commit c3594d0

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,20 @@ jobs:
7474
cd ts
7575
rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_debug.wasm ./liblightningjs.wasm
7676
python3 -m http.server &
77+
SERVER_PID=$!
7778
node test/browser.mjs
79+
kill $SERVER_PID
7880
- name: Build and Test TS Release Bindings for Web
7981
run: |
8082
export HOME=/root/ # Github actions is apparently broken
8183
export PATH=$(pwd)/$(echo node-*/bin):$PATH
8284
./genbindings.sh ./ldk-c-bindings/ wasm false true
8385
cd ts
8486
rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_release.wasm ./liblightningjs.wasm
87+
python3 -m http.server &
88+
SERVER_PID=$!
8589
node test/browser.mjs
90+
kill $SERVER_PID
8691
- name: Check latest TS files are in git
8792
run: |
8893
git diff --exit-code

ts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lightningdevkit",
3-
"version": "0.0.104.1alpha2",
3+
"version": "0.0.104.1alpha3",
44
"description": "Lightning Development Kit",
55
"main": "index.mjs",
66
"type": "module",
@@ -14,6 +14,7 @@
1414
"enums/*.d.mts",
1515
"bindings.mjs",
1616
"bindings.d.mts",
17+
"version.mjs",
1718
"liblightningjs.wasm",
1819
"tsconfig.json",
1920
"README.md",

ts/test/browser.mjs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@ import { chromium, firefox, webkit } from 'playwright';
22
import { strict as assert } from 'assert';
33

44
for (const browserType of [chromium, firefox]) { // We'd like to test webkit, but playwright doesn't support it on Debian (?!)
5-
const browser = await browserType.launch();
5+
var browser;
6+
if (browserType == chromium)
7+
browser = await browserType.launch(["--js-flags=\"--expose-gc\""]);
8+
else
9+
browser = await browserType.launch();
610
const context = await browser.newContext();
711
const page = await context.newPage();
8-
await page.goto('http://localhost:8000/test/index.html');
9-
const ret = await page.evaluate(() => {
10-
return test_runner('../liblightningjs.wasm');
12+
page.on('console', async msg => {
13+
const values = [];
14+
for (const arg of msg.args())
15+
values.push(await arg.jsonValue());
16+
console.log(...values);
1117
});
18+
await page.goto('http://localhost:8000/test/index.html');
19+
var ret;
20+
// On chromium we expose the GC and can run it manually, otherwise we really can't leak-check
21+
if (browserType == chromium) {
22+
ret = await page.evaluate(() => { return test_runner('../liblightningjs.wasm', true); });
23+
} else {
24+
ret = await page.evaluate(() => { return test_runner('../liblightningjs.wasm', false); });
25+
}
1226
assert(ret);
1327

1428
await browser.close();

ts/test/tests.mts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ tests.push(async () => {
197197
return true;
198198
});
199199

200-
export async function run_tests(wasm_path: string) {
200+
export async function run_tests(wasm_path: string, check_leaks: boolean = true) {
201201
await rawldk.initializeWasm(wasm_path);
202202

203203
var test_runs = [];
@@ -208,18 +208,23 @@ export async function run_tests(wasm_path: string) {
208208
console.log("test results: " + results);
209209
const result = results.every((v) => { return v === true });
210210
console.log("all tests passed: " + result);
211-
if (result !== true) { return result; }
211+
if (result !== true || !check_leaks) { return result; }
212212

213213
const allocs_finished = new Promise((resolve, reject) => {
214214
var loop_count = 0;
215215
const interval_id = setInterval(() => {
216216
const alloc_count = rawldk.getRemainingAllocationCount();
217217
if (loop_count % 20 == 0)
218218
console.log("Remaining LDK allocation count: " + alloc_count);
219+
220+
// chromium with --js-flags="--expose-gc" exposes a `window.gc()` which we call if we can
221+
// @ts-ignore window.gc is considered a type error in TS
222+
if (typeof window !== "undefined" && typeof window.gc !== "undefined") window.gc();
223+
219224
// Note that there are currently 9 leaks in the above tests. At least some are known - look for XXX in bindings.c
220-
if (alloc_count <= 10) { resolve(true); clearInterval(interval_id); }
225+
if (alloc_count <= 10) { clearInterval(interval_id); rawldk.debugPrintRemainingAllocs(); resolve(true); }
221226
loop_count += 1;
222-
if (loop_count > 30*2) { resolve(false); clearInterval(interval_id); rawldk.debugPrintRemainingAllocs(); }
227+
if (loop_count > 30*2) { clearInterval(interval_id); rawldk.debugPrintRemainingAllocs(); resolve(false); }
223228
}, 500);
224229
});
225230
return allocs_finished;

0 commit comments

Comments
 (0)