Skip to content

Commit

Permalink
fix: Run wasm nodejs tests with no fails (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmvict authored Aug 28, 2023
1 parent b1ccd71 commit 67b6710
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -199,4 +199,6 @@ jobs:
- name: Run tests
working-directory: ./crates/wasm
run: yarn test:browser
run: |
yarn test:browser
yarn test:node
3 changes: 2 additions & 1 deletion crates/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
},
"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": {
"@noir-lang/noir-source-resolver": "^1.1.3"
},
"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",
Expand Down
18 changes: 13 additions & 5 deletions crates/wasm/test/node/index.test.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
return readFileSync(path).toString()
return readFileSync(join(__dirname, path)).toString();
}

async function getSource(): Promise<string> {
return getFileContent(noirSourcePath)
return getFileContent(noirSourcePath);
}

async function getPrecompiledSource(): Promise<string> {
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions crates/wasm/test/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
console.log("Compiling Noir source...");

initialiseResolver((id: string) => {
initialiseResolver((id: String) => {
console.log(`Resolving source ${id}`);

const source = noir_source;
Expand Down

0 comments on commit 67b6710

Please sign in to comment.