From 688bc981c3eda78793435450d021d7db671eca5e Mon Sep 17 00:00:00 2001 From: dmvict Date: Mon, 21 Aug 2023 17:07:39 +0300 Subject: [PATCH 1/5] fix: Run `mocha` nodejs tests with no fails --- crates/wasm/test/node/index.test.ts | 18 +++++++++++++----- crates/wasm/test/shared.ts | 8 ++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/wasm/test/node/index.test.ts b/crates/wasm/test/node/index.test.ts index 9710023b29e..f823db35944 100644 --- a/crates/wasm/test/node/index.test.ts +++ b/crates/wasm/test/node/index.test.ts @@ -1,13 +1,18 @@ -import { expect } from "@esm-bundle/chai"; -import { compileNoirSource, nargoArtifactPath, noirSourcePath } from "../shared"; +import { expect } from "chai"; +import { + compileNoirSource, + nargoArtifactPath, + noirSourcePath, +} from "../shared"; import { readFileSync } from "node:fs"; +import { join } from "node:path"; async function getFileContent(path: string): Promise { - return readFileSync(path).toString() + return readFileSync(join(__dirname, path)).toString(); } async function getSource(): Promise { - return getFileContent(noirSourcePath) + return getFileContent(noirSourcePath); } async function getPrecompiledSource(): Promise { @@ -27,7 +32,10 @@ describe("noir wasm compilation", () => { console.log("cli", cliCircuitBase64); - console.log("Compilation is a match? ", wasmCircuitBase64 === cliCircuitBase64); + console.log( + "Compilation is a match? ", + wasmCircuitBase64 === cliCircuitBase64, + ); expect(wasmCircuitBase64).to.equal(cliCircuitBase64); }).timeout(10e3); diff --git a/crates/wasm/test/shared.ts b/crates/wasm/test/shared.ts index ee9c57d24f6..7108efb551c 100644 --- a/crates/wasm/test/shared.ts +++ b/crates/wasm/test/shared.ts @@ -1,8 +1,12 @@ -import { initialiseResolver } from "@noir-lang/noir-source-resolver"; +// it's the trick to provide mocha testing. The module `@noir-lang/noir-source-resolver` has no typings to resolve +// import { initialiseResolver } from "@noir-lang/noir-source-resolver"; +const initialiseResolver = + require("@noir-lang/noir-source-resolver").initialiseResolver; import { compile } from "../result/"; export const noirSourcePath = "../../noir-script/src/main.nr"; -export const nargoArtifactPath = "../../noir-script/target/noir_wasm_testing.json"; +export const nargoArtifactPath = + "../../noir-script/target/noir_wasm_testing.json"; export async function compileNoirSource(noir_source: string): Promise { console.log("Compiling Noir source..."); From c0ef41cd760b26fc63d0f7d974e6042f9775cd65 Mon Sep 17 00:00:00 2001 From: dmvict Date: Tue, 22 Aug 2023 14:37:58 +0300 Subject: [PATCH 2/5] feat: Add command `test:node` to `package.json` of crate `wasm` --- crates/wasm/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/wasm/package.json b/crates/wasm/package.json index b01e36d27b1..b441f274666 100644 --- a/crates/wasm/package.json +++ b/crates/wasm/package.json @@ -21,6 +21,7 @@ }, "scripts": { "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha", + "test:node": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha", "test:browser": "web-test-runner" }, "peerDependencies": { From d5919a49f1f75020645ed274e9493b0e52409122 Mon Sep 17 00:00:00 2001 From: dmvict Date: Tue, 22 Aug 2023 16:19:42 +0300 Subject: [PATCH 3/5] fix: Update file `shared.ts` to use new version of module `noir-source-resolver`, update type declaration --- crates/wasm/test/shared.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/wasm/test/shared.ts b/crates/wasm/test/shared.ts index 7108efb551c..725e4fbd05e 100644 --- a/crates/wasm/test/shared.ts +++ b/crates/wasm/test/shared.ts @@ -1,7 +1,4 @@ -// it's the trick to provide mocha testing. The module `@noir-lang/noir-source-resolver` has no typings to resolve -// import { initialiseResolver } from "@noir-lang/noir-source-resolver"; -const initialiseResolver = - require("@noir-lang/noir-source-resolver").initialiseResolver; +import { initialiseResolver } from "@noir-lang/noir-source-resolver"; import { compile } from "../result/"; export const noirSourcePath = "../../noir-script/src/main.nr"; @@ -11,7 +8,7 @@ export const nargoArtifactPath = export async function compileNoirSource(noir_source: string): Promise { console.log("Compiling Noir source..."); - initialiseResolver((id: string) => { + initialiseResolver((id: String) => { console.log(`Resolving source ${id}`); const source = noir_source; From e45b7fef47db691177ef0edef4d9a67da296bbf9 Mon Sep 17 00:00:00 2001 From: dmvict Date: Thu, 24 Aug 2023 17:48:46 +0300 Subject: [PATCH 4/5] chore: Update version of dependency in `package.json` of crate `wasm` --- crates/wasm/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasm/package.json b/crates/wasm/package.json index b441f274666..3acf6d0c717 100644 --- a/crates/wasm/package.json +++ b/crates/wasm/package.json @@ -29,7 +29,7 @@ }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", - "@noir-lang/noir-source-resolver": "^1.1.3", + "@noir-lang/noir-source-resolver": "^1.1.4", "@web/dev-server-esbuild": "^0.3.6", "@web/test-runner": "^0.15.3", "@web/test-runner-playwright": "^0.10.0", From 2cc5db5b04c661ed5fa95bacee9f893947ba3290 Mon Sep 17 00:00:00 2001 From: dmvict Date: Fri, 25 Aug 2023 14:13:25 +0300 Subject: [PATCH 5/5] feat: Update workflow `wasm`, add command to test node target --- .github/workflows/wasm.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index f052e9eb071..ecf2fab06ba 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -84,7 +84,7 @@ jobs: - uses: actions/cache/save@v3 # Don't create cache entries for the merge queue. - if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} + if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} with: path: ${{ env.CACHED_PATHS }} key: ${{ steps.cache.outputs.cache-primary-key }} @@ -199,4 +199,6 @@ jobs: - name: Run tests working-directory: ./crates/wasm - run: yarn test:browser + run: | + yarn test:browser + yarn test:node