Skip to content

Commit e972f00

Browse files
authored
Merge pull request #1019 from IntersectMBO/webpack-test
Add webpack NPM package test to CI
2 parents c363a32 + 3339f6d commit e972f00

File tree

7 files changed

+147
-18
lines changed

7 files changed

+147
-18
lines changed

.github/workflows/haskell-wasm.yml

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,39 @@ jobs:
148148
$(wasm32-wasi-ghc --print-libdir)/post-link.mjs -i "$(env -u CABAL_CONFIG wasm32-wasi-cabal list-bin exe:cardano-wasm | tail -n1)" -o cardano-wasm/lib-wrapper/cardano-wasm.js
149149
cp cardano-wasm/lib-wrapper/* cardano-wasm/examples/basic/
150150
151+
- name: Build grpc bridge
152+
run: |
153+
nix build .#proto-js-bundle
154+
155+
- name: Prepare NPM package
156+
run: |
157+
cp cardano-wasm/lib-wrapper/* cardano-wasm/npm-wrapper/src/
158+
rm cardano-wasm/npm-wrapper/src/cardano-api.js
159+
cp result/cardano_node_grpc_web_pb.js cardano-wasm/npm-wrapper/src/
160+
cp -r result/node cardano-wasm/npm-wrapper/src/
161+
cd cardano-wasm/npm-wrapper
162+
npm install
163+
npm run build
164+
npm test
165+
npm pack
166+
167+
- name: Prepare webpack test
168+
run: |
169+
cp cardano-wasm/npm-wrapper/*.tgz cardano-wasm/npm-test/webpack/
170+
cd cardano-wasm/npm-test/webpack
171+
npm install ./*.tgz
172+
npx webpack serve --port 8081 &
173+
cd ../../..
174+
151175
- uses: rrbutani/use-nix-shell-action@v1
152176
with:
153177
devShell: .#playwright
154178

155-
- name: Run playwright test in example
179+
- name: Run playwright test in example and webpack test
156180
run: |
157181
httpserver -h localhost -a 127.0.0.1 -p 8080 cardano-wasm/examples/basic &
158182
playwright test cardano-wasm/js-test/basic-test.spec.ts
183+
playwright test cardano-wasm/npm-test/webpack-test.spec.ts
159184
160185
# - name: Run tests
161186
# env:
@@ -181,30 +206,14 @@ jobs:
181206
# with:
182207
# limit-access-to-actor: true
183208

184-
- name: Build grpc bridge
185-
run: |
186-
nix build .#proto-js-bundle
187-
188-
- name: Prepare NPM package
189-
run: |
190-
cp cardano-wasm/lib-wrapper/* cardano-wasm/npm-wrapper/src/
191-
rm cardano-wasm/npm-wrapper/src/cardano-api.js
192-
cp result/cardano_node_grpc_web_pb.js cardano-wasm/npm-wrapper/src/
193-
cp -r result/node cardano-wasm/npm-wrapper/src/
194-
cd cardano-wasm/npm-wrapper
195-
npm install
196-
npm run build
197-
npm test
198-
npm pack
199-
200209
- name: Prepare wasm library
201210
run: |
202211
cp result/cardano_node_grpc_web_pb.js cardano-wasm/lib-wrapper/
203212
204213
- name: Test NPM package with node.js
205214
run: |
206215
export TMPDIR=$(mktemp -d)
207-
cp cardano-wasm/node.test.js $TMPDIR/
216+
cp cardano-wasm/npm-test/node.test.js $TMPDIR/
208217
cp cardano-wasm/npm-wrapper/*.tgz $TMPDIR/
209218
cd $TMPDIR
210219
npm install ./*.tgz
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('test output matches', async ({ page }) => {
4+
const consolePromise = page.waitForEvent('console', {
5+
predicate: (msg) => msg.text().includes('> "New Transaction Body Created:"')
6+
});
7+
8+
await page.goto('http://localhost:8081');
9+
10+
await consolePromise;
11+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Getting Started</title>
6+
</head>
7+
<body>
8+
</body>
9+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "wtest",
3+
"version": "1.0.0",
4+
"entry": "./src/index.js",
5+
"private": true,
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"description": "",
13+
"devDependencies": {
14+
"webpack": "^5.102.0",
15+
"webpack-cli": "^6.0.1",
16+
"webpack-dev-server": "^5.2.2"
17+
},
18+
"dependencies": {
19+
"copy-webpack-plugin": "^13.0.1",
20+
"html-webpack-plugin": "^5.6.4"
21+
}
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function log(out) {
2+
var output = "";
3+
if (typeof (out) == "object") {
4+
output += "> [object] {\n";
5+
for (let [key, val] of Object.entries(out)) {
6+
let text = val.toString();
7+
if (typeof (val) == "function") {
8+
text = text.split("{")[0];
9+
}
10+
output += "     " + key + ": " + text + "\n";
11+
}
12+
output += "  }\n";
13+
} else if (typeof (out) == "bigint") {
14+
output += "> " + out.toString() + "n\n";
15+
} else {
16+
output += "> " + JSON.stringify(out) + "\n";
17+
}
18+
console.log(output);
19+
}
20+
21+
(async () => {
22+
const cardanoModule = await import('cardano-wasm');
23+
const api = await cardanoModule.default();
24+
25+
log("Cardano API initialised:");
26+
log(cardanoModule);
27+
28+
29+
log("Cardano API instance created:");
30+
log(api);
31+
32+
const tx = await api.tx.newTx();
33+
log("New Transaction Body Created:", tx);
34+
})();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const HtmlWebpackPlugin = require('html-webpack-plugin');
2+
const CopyWebpackPlugin = require('copy-webpack-plugin');
3+
const path = require('path');
4+
5+
module.exports = {
6+
entry: './src/index.js',
7+
8+
target: ['web', 'es2020'],
9+
10+
output: {
11+
filename: 'main.js',
12+
path: path.resolve(__dirname, 'dist'),
13+
publicPath: '',
14+
},
15+
16+
experiments: {
17+
asyncWebAssembly: true,
18+
},
19+
devtool: 'source-map',
20+
plugins: [
21+
new HtmlWebpackPlugin({ template: './index.html' }),
22+
new CopyWebpackPlugin({
23+
patterns: [
24+
{
25+
from: 'node_modules/cardano-wasm/dist/cardano-wasm.js',
26+
to: 'cardano-wasm.js',
27+
},
28+
],
29+
}),
30+
],
31+
32+
33+
module: {
34+
rules: [
35+
{
36+
test: /\.wasm$/,
37+
type: 'asset/resource',
38+
},
39+
],
40+
},
41+
42+
mode: 'development',
43+
};
44+

0 commit comments

Comments
 (0)