Skip to content

Commit f62733d

Browse files
authored
Merge pull request #1016 from IntersectMBO/npm-node-test
Add CI test for NPM package using node.js
2 parents e113b2e + 5d6414e commit f62733d

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

.github/workflows/haskell-wasm.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ jobs:
201201
run: |
202202
cp result/cardano_node_grpc_web_pb.js cardano-wasm/lib-wrapper/
203203
204+
- name: Test NPM package with node.js
205+
run: |
206+
export TMPDIR=$(mktemp -d)
207+
cp cardano-wasm/node.test.js $TMPDIR/
208+
cp cardano-wasm/npm-wrapper/*.tgz $TMPDIR/
209+
cd $TMPDIR
210+
npm install ./*.tgz
211+
node node.test.js
212+
cd -
213+
204214
- name: Upload built wasm library
205215
uses: actions/upload-artifact@v4
206216
with:

cardano-wasm/node.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Test snippet from NPM's package README.md
2+
3+
(async () => {
4+
try {
5+
// 1. Dynamically import the package.
6+
const cardanoModule = await import('cardano-wasm');
7+
8+
// 2. The module's default export is an async function that initializes the WASM instance.
9+
// Await this to get the usable API object.
10+
const api = await cardanoModule.default();
11+
console.log("Cardano API loaded successfully!");
12+
13+
// 3. Now you can use the API to perform Cardano operations.
14+
// For example, let's create a new transaction body.
15+
const tx = await api.tx.newTx();
16+
console.log("New Transaction Body Created:", tx);
17+
18+
// You can now build upon the 'tx' object to add inputs, outputs, etc.
19+
20+
console.log("Test Passed.");
21+
process.exit(0);
22+
23+
} catch (error) {
24+
console.error("Failed to load or use the Cardano API:", error);
25+
26+
console.log("Test Failed.");
27+
process.exit(1);
28+
}
29+
})();

0 commit comments

Comments
 (0)