Skip to content

Commit b43cbfc

Browse files
committed
Splict wasm tests into multiple functions and files; use strict mode; use knip
1 parent a183e72 commit b43cbfc

22 files changed

Lines changed: 2140 additions & 1659 deletions

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ test/config.ini
4545

4646
# wasm
4747
wasm-wrappers/pkg/
48-
wasm-wrappers/js-bindings-test/test.js
49-
wasm-wrappers/js-bindings-test/test.js.map
48+
wasm-wrappers/js-bindings-test/dist/
5049

5150
# 'mintlayer-data' will be mapped to home directories of docker containers, so everything
5251
# inside it will be generated by the containers.

.github/workflows/wasm.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
uses: actions/setup-node@v3
3636
with:
3737
node-version: ${{ matrix.node-version }}
38-
- name: Install TypeScript
39-
run: npm install typescript
38+
- name: Install TypeScript & Knip
39+
run: npm install typescript knip
4040
- name: Install wasm-pack
4141
run: cargo install wasm-pack
4242
- name: Build the wasm module
@@ -48,6 +48,9 @@ jobs:
4848
- name: Run the tests
4949
working-directory: ./wasm-wrappers
5050
run: node --enable-source-maps js-bindings-test/node-entry.js
51+
- name: Run Knip
52+
working-directory: ./wasm-wrappers/js-bindings-test
53+
run: npx knip
5154

5255
wasm_artifacts:
5356
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ test/config.ini
4343

4444
# wasm
4545
wasm-wrappers/pkg/
46-
wasm-wrappers/js-bindings-test/test.js
47-
wasm-wrappers/js-bindings-test/test.js.map
46+
wasm-wrappers/js-bindings-test/dist/
4847

4948
# 'mintlayer-data' will be mapped to home directories of docker containers, so everything
5049
# inside it will be generated by the containers.

build-tools/codecheck/codecheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
'.git',
3535
'build-tools/docker/example-mainnet/mintlayer-data',
3636
'build-tools/docker/example-mainnet-dns-server/mintlayer-data',
37-
'wasm-wrappers/pkg'
37+
'wasm-wrappers/pkg',
38+
'wasm-wrappers/js-bindings-test/dist',
3839
]
3940

4041

@@ -325,7 +326,6 @@ def check_files_end_with_newline():
325326
# list of files exempted from checks
326327
exempted_files = [
327328
'wasm-wrappers/doc/*',
328-
'wasm-wrappers/js-bindings-test/test.js',
329329
]
330330

331331
ok = True

wasm-wrappers/README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ In the wasm Cargo.toml directory, run:
3535
tsc --project js-bindings-test/tsconfig.json
3636
```
3737

38-
### Running the tests in a web browser
38+
### Run the tests in a web browser
3939

4040
To build the wasm package from the crate, run (in the wasm Cargo.toml directory):
4141

4242
```
4343
wasm-pack build --target web
4444
```
4545

46-
To test the wasm binary. First, install `http-server` web server (feel free to use any other web-server of your choosing):
46+
To test the wasm binary, first install `http-server` web server (feel free to use any other web-server of your choosing):
4747

4848
```
4949
cargo install http-server
5050
```
5151

52-
Then run the http server, and then choose the file `js-bindings-test/index.html`:
52+
Then run the http server:
5353

5454
```
5555
http-server --port 8080
@@ -61,22 +61,41 @@ If you're using a remote server, either tunnel to port 8080, or expose that port
6161
http-server --port 8080 --host 0.0.0.0
6262
```
6363

64-
The ported wasm functions are exported to the file `js-bindings-test/index.js` and used in the file `js-bindings-test/index.html` with a basic test/example in them using JavaScript. Use your browser's console to see the output.
64+
To run test tests, choose the file `js-bindings-test/index.html` in the browser. Use browser's console to see the output.
6565

66-
### Running the tests in Node.js
66+
### Run the tests in Node.js
6767

6868
To build the wasm package from the crate, run (in the wasm Cargo.toml directory):
6969

7070
```
7171
wasm-pack build --target nodejs
7272
```
7373

74-
Finally, to run the example, run:
74+
Finally, to run the tests, run:
7575

7676
```
7777
node --enable-source-maps js-bindings-test/node-entry.js
7878
```
7979

80+
### Run `knip`
81+
82+
We use `knip` to make sure that there are no unused exports in `js-bindings-test/tests` (which could
83+
mean that some of the tests are never run).
84+
85+
**Note: unused local definitions are caught by the TypeScript compiler itself, via the `noUnusedLocals` setting.**
86+
87+
To run `knip` locally, first install it:
88+
```
89+
npm install -g knip
90+
```
91+
92+
And then run (in the wasm Cargo.toml directory):
93+
```
94+
(cd js-bindings-test && npx knip)
95+
```
96+
97+
**Note: to explicitly exclude an export from `knip`'s report, annotate it with `/** @public */`.**
98+
8099
### Further documentation on wasm
81100

82101
- https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_wasm
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema.json",
3+
"entry": ["tests/main.ts"],
4+
"project": ["tests/**/*.ts"],
5+
"includeEntryExports": true,
6+
"ignoreExportsUsedInFile": true
7+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { run_test } from "./test.js";
1+
import { run_all_tests } from "./dist/main.js";
22

33
async function node_run() {
4-
await run_test();
4+
await run_all_tests();
55
}
66

77
node_run();
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "wasm-wrappers-example",
3-
"version": "0.1.0",
4-
"license": "MIT",
5-
"main": "index.js",
6-
"type": "module"
7-
}
2+
"name": "js-bindings-test",
3+
"version": "0.1.0",
4+
"license": "MIT",
5+
"main": "index.js",
6+
"type": "module"
7+
}

0 commit comments

Comments
 (0)