Skip to content

Commit

Permalink
fix node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
leordev committed Oct 13, 2023
1 parent 530fc8f commit d0ce1c5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: pnpm install

- name: 🧪 Run Web5 tests
run: pnpm -r --workspace-concurrency 1 --no-bail test:node
run: pnpm -r --workspace-concurrency 1 --no-bail test:web5

test-dwn:
strategy:
Expand Down
4 changes: 2 additions & 2 deletions tests/node-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"type": "commonjs",
"name": "node-cjs",
"scripts": {
"test": "npm run test:node && npm run test:dwn",
"test:node": "node web5-test.js",
"test": "npm run test:web5 && npm run test:dwn",
"test:web5": "node web5-test.js",
"test:dwn": "node dwn-sdk-test.js"
}
}
4 changes: 2 additions & 2 deletions tests/node-cjs/web5-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Web5 } = require('@web5/api');
const checkWeb5 = require('../util/web5-test.js');
const { Web5 } = require("@web5/api");
const checkWeb5 = require("../util/web5-test.js");

checkWeb5(Web5).then(() => process.exit());
4 changes: 2 additions & 2 deletions tests/node-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "node-esm",
"type": "module",
"scripts": {
"test": "npm run test:node && npm run test:dwn",
"test:node": "node web5-test.js",
"test": "npm run test:web5 && npm run test:dwn",
"test:web5": "node web5-test.js",
"test:dwn": "node dwn-sdk-test.js"
}
}
2 changes: 2 additions & 0 deletions tests/util/dwn-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require("./webcrypto-polyfill.js");

const checkDwn = async (
Dwn,
DataStream,
Expand Down
2 changes: 2 additions & 0 deletions tests/util/web5-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require("./webcrypto-polyfill.js");

function checkResult(result) {
if (!result.didUpdate) {
throw new Error("Record did not update!");
Expand Down
12 changes: 12 additions & 0 deletions tests/util/webcrypto-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** According to Web5 readme we need to inject webcrypto in node versions <= 18 */
const isNode = typeof process !== "undefined" && process.versions != null;
if (isNode) {
const majorVersion = parseInt(
process.version.slice(1).split(".")[0].replace("v", "")
);
if (majorVersion <= 18) {
console.info(">>> Injecting webcrypto polyfill");
const { webcrypto } = require("node:crypto");
if (!globalThis.crypto) globalThis.crypto = webcrypto;
}
}

0 comments on commit d0ce1c5

Please sign in to comment.