diff --git a/.github/workflows/build-revive-wasm.yml b/.github/workflows/build-revive-wasm.yml index 1567676..c0db734 100644 --- a/.github/workflows/build-revive-wasm.yml +++ b/.github/workflows/build-revive-wasm.yml @@ -106,6 +106,7 @@ jobs: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser iex (new-object net.webclient).downloadstring('https://get.scoop.sh') scoop install bun@${{ env.BUN_VERSION }} + scoop install wget Join-Path (Resolve-Path ~).Path "scoop\shims" >> $Env:GITHUB_PATH - name: Install Bun on macOS and Linux @@ -114,13 +115,16 @@ jobs: curl -fsSL https://bun.sh/install | bash -s bun-v${{ env.BUN_VERSION }} echo "$HOME/.bun/bin" >> $GITHUB_PATH - - name: Confirm Installations + - name: Install packages + run: npm install + + - name: Run Playwright tests run: | - node --version - bun --version + cd js + npx playwright install --with-deps + npx playwright test - name: Test revive run: | echo "Running tests for ${{ matrix.os }}" - npm install npm run test:wasm diff --git a/.gitignore b/.gitignore index 87ea520..dc2bedc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,7 @@ package-lock.json /*.html /build soljson.js +test-results +playwright-report +.cache emsdk diff --git a/js/e2e/web.test.js b/js/e2e/web.test.js new file mode 100644 index 0000000..c74f2d1 --- /dev/null +++ b/js/e2e/web.test.js @@ -0,0 +1,63 @@ +const { test, expect } = require('@playwright/test'); + +const validCompilerInput = { + language: 'Solidity', + sources: { + 'MyContract.sol': { + content: ` + // SPDX-License-Identifier: UNLICENSED + pragma solidity ^0.8.0; + contract MyContract { + function greet() public pure returns (string memory) { + return "Hello"; + } + } + `, + }, + }, + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + outputSelection: { + '*': { + '*': ['abi', 'evm.bytecode'], + }, + }, + }, +}; + +async function runWorker(page, input) { + return await page.evaluate((input) => { + return new Promise((resolve, reject) => { + const worker = new Worker('worker.js'); // Path to your worker.js file + worker.postMessage(JSON.stringify(input)); + + worker.onmessage = (event) => { + resolve(event.data.output); + worker.terminate(); // Clean up the worker + }; + + worker.onerror = (error) => { + reject(error.message || error); // Provide error message for clarity + worker.terminate(); // Clean up the worker + }; + }); + }, input); // Pass the input as an argument to the function +} + +test('Test browser', async ({ page }) => { + await page.goto("http://127.0.0.1:8080"); + await page.setContent(""); + + const result = await runWorker(page, validCompilerInput); + + expect(typeof result).toBe('string'); + let output = JSON.parse(result); + expect(output).toHaveProperty('contracts'); + expect(output.contracts['MyContract.sol']).toHaveProperty('MyContract'); + expect(output.contracts['MyContract.sol'].MyContract).toHaveProperty('abi'); + expect(output.contracts['MyContract.sol'].MyContract).toHaveProperty('evm'); + expect(output.contracts['MyContract.sol'].MyContract.evm).toHaveProperty('bytecode'); +}); diff --git a/js/examples/web/index.html b/js/examples/web/index.html index 3123a26..959a24d 100644 --- a/js/examples/web/index.html +++ b/js/examples/web/index.html @@ -1,35 +1,51 @@ -
- -