From 67b67100bf46d3f101538bd3552ed63e5fbf654c Mon Sep 17 00:00:00 2001 From: Dmytry Victorovich Date: Mon, 28 Aug 2023 13:42:59 +0300 Subject: [PATCH] fix: Run `wasm` nodejs tests with no fails (#2387) --- .github/workflows/wasm.yml | 6 ++++-- crates/wasm/package.json | 3 ++- crates/wasm/test/node/index.test.ts | 18 +++++++++++++----- crates/wasm/test/shared.ts | 5 +++-- 4 files changed, 22 insertions(+), 10 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 diff --git a/crates/wasm/package.json b/crates/wasm/package.json index b01e36d27b1..3acf6d0c717 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": { @@ -28,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", 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..725e4fbd05e 100644 --- a/crates/wasm/test/shared.ts +++ b/crates/wasm/test/shared.ts @@ -2,12 +2,13 @@ import { initialiseResolver } from "@noir-lang/noir-source-resolver"; 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..."); - initialiseResolver((id: string) => { + initialiseResolver((id: String) => { console.log(`Resolving source ${id}`); const source = noir_source;