diff --git a/compiler/wasm/package.json b/compiler/wasm/package.json index 4bc4ddc8288..446a189302b 100644 --- a/compiler/wasm/package.json +++ b/compiler/wasm/package.json @@ -20,8 +20,8 @@ }, "scripts": { "build": "bash ./build.sh", - "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha", - "test:node": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha", + "test": "yarn test:node && yarn test:browser", + "test:node": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' mocha", "test:browser": "web-test-runner", "clean": "chmod u+w web nodejs || true && rm -rf ./nodejs ./web ./target ./result", "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", diff --git a/compiler/wasm/test/browser/index.test.ts b/compiler/wasm/test/browser/index.test.ts index 662aae5a666..02263d9adfb 100644 --- a/compiler/wasm/test/browser/index.test.ts +++ b/compiler/wasm/test/browser/index.test.ts @@ -1,6 +1,7 @@ import { expect } from '@esm-bundle/chai'; -import initNoirWasm from '@noir-lang/noir_wasm'; -import { compileNoirSource, nargoArtifactPath, noirSourcePath } from '../shared'; +import initNoirWasm, { compile } from '@noir-lang/noir_wasm'; +import { initializeResolver } from '@noir-lang/source-resolver'; +import { nargoArtifactPath, noirSourcePath } from '../shared'; beforeEach(async () => { await initNoirWasm(); @@ -22,6 +23,35 @@ async function getPrecompiledSource(): Promise { return JSON.parse(compiledData); } +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export async function compileNoirSource(noir_source: string): Promise { + console.log('Compiling Noir source...'); + + initializeResolver((id: string) => { + console.log(`Resolving source ${id}`); + + const source = noir_source; + + if (typeof source === 'undefined') { + throw Error(`Could not resolve source for '${id}'`); + } else if (id !== '/main.nr') { + throw Error(`Unexpected id: '${id}'`); + } else { + return source; + } + }); + + try { + const compiled_noir = compile('main.nr'); + + console.log('Noir source compilation done.'); + + return compiled_noir; + } catch (e) { + console.log('Error while compiling:', e); + } +} + describe('noir wasm compilation', () => { it('matches nargos compilation', async () => { const source = await getSource(); diff --git a/compiler/wasm/test/index.d.ts b/compiler/wasm/test/index.d.ts deleted file mode 100644 index 2b4401d3bc8..00000000000 --- a/compiler/wasm/test/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module '@noir-lang/source-resolver'; diff --git a/compiler/wasm/test/node/index.test.ts b/compiler/wasm/test/node/index.test.ts index 3ecb1bfc4b4..78aed535df7 100644 --- a/compiler/wasm/test/node/index.test.ts +++ b/compiler/wasm/test/node/index.test.ts @@ -1,16 +1,13 @@ import { expect } from 'chai'; -import { compileNoirSource, nargoArtifactPath, noirSourcePath } from '../shared'; +import { nargoArtifactPath, noirSourcePath } from '../shared'; import { readFileSync } from 'node:fs'; import { join } from 'node:path'; +import { compile } from '@noir-lang/noir_wasm'; async function getFileContent(path: string): Promise { return readFileSync(join(__dirname, path)).toString(); } -async function getSource(): Promise { - return getFileContent(noirSourcePath); -} - // eslint-disable-next-line @typescript-eslint/no-explicit-any async function getPrecompiledSource(): Promise { const compiledData = await getFileContent(nargoArtifactPath); @@ -19,10 +16,7 @@ async function getPrecompiledSource(): Promise { describe('noir wasm compilation', () => { it('matches nargos compilation', async () => { - const source = await getSource(); - - const wasmCircuit = await compileNoirSource(source); - + const wasmCircuit = await compile(noirSourcePath); const cliCircuit = await getPrecompiledSource(); // We don't expect the hashes to match due to how `noir_wasm` handles dependencies diff --git a/compiler/wasm/test/shared.ts b/compiler/wasm/test/shared.ts index 91f420741cb..f726316cd74 100644 --- a/compiler/wasm/test/shared.ts +++ b/compiler/wasm/test/shared.ts @@ -1,34 +1,2 @@ -import { initializeResolver } from '@noir-lang/source-resolver'; -import { compile } from '@noir-lang/noir_wasm'; - export const noirSourcePath = '../../noir-script/src/main.nr'; export const nargoArtifactPath = '../../noir-script/target/noir_wasm_testing.json'; - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export async function compileNoirSource(noir_source: string): Promise { - console.log('Compiling Noir source...'); - - initializeResolver((id: string) => { - console.log(`Resolving source ${id}`); - - const source = noir_source; - - if (typeof source === 'undefined') { - throw Error(`Could not resolve source for '${id}'`); - } else if (id !== '/main.nr') { - throw Error(`Unexpected id: '${id}'`); - } else { - return source; - } - }); - - try { - const compiled_noir = compile('main.nr'); - - console.log('Noir source compilation done.'); - - return compiled_noir; - } catch (e) { - console.log('Error while compiling:', e); - } -}