Browse Source

test: add wasm32 target e2e test (#2989)

pull/3002/head
scc 1 year ago committed by GitHub
parent
commit
64b6d84330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .github/workflows/webassembly.yml
  2. 4
      .gitignore
  3. 2
      .prettierignore
  4. 25
      boa_wasm/e2e_test/boa_demo.spec.ts
  5. 71
      boa_wasm/e2e_test/playwright.config.ts
  6. 23
      boa_wasm/e2e_test/server.mjs
  7. 2
      index.html
  8. 56
      package-lock.json
  9. 3
      package.json
  10. 15
      webpack.config.js

5
.github/workflows/webassembly.yml

@ -50,4 +50,9 @@ jobs:
with:
node-version: "16"
- run: npm ci
- run: cd boa_wasm && wasm-pack --verbose build --out-name index --out-dir ./pkg
- run: npm run build
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright test
run: npm run e2e

4
.gitignore vendored

@ -32,3 +32,7 @@ chrome_profiler.json
# Yarn
.yarn
.yarnrc.yml
# e2e test
playwright-report
test-results

2
.prettierignore

@ -8,3 +8,5 @@ boa_wasm/pkg
dist
test262
tests/js/test.js
playwright-report
test-results

25
boa_wasm/e2e_test/boa_demo.spec.ts

@ -0,0 +1,25 @@
import { expect, test } from "@playwright/test";
test.beforeEach(async ({ page }) => {
page.on("console", (msg) => {
let msgText = "";
for (let i = 0; i < msg.args().length; ++i) {
msgText += `${msg.args()[i]}`;
}
// eslint-disable-next-line no-console
console.log(msgText);
});
});
test("boa demo", async ({ page }) => {
await page.goto("/", {
// wait until all content is loaded
waitUntil: "networkidle",
});
// wait for the code evaluate
await page.waitForTimeout(2000);
const output = page.getByTestId("output");
const result = await output.innerHTML();
console.log("eval result: ", result);
await expect(result.match("Hello, World")?.length).toEqual(1);
});

71
boa_wasm/e2e_test/playwright.config.ts

@ -0,0 +1,71 @@
import { defineConfig, devices } from "@playwright/test";
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./",
/* Maximum time one test can run for. */
timeout: 300 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
},
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
baseURL: "http://localhost:8081/",
},
webServer: {
command: "node ./server.mjs",
cwd: "./",
url: "http://localhost:8081",
timeout: 60 * 1000,
reuseExistingServer: !process.env.CI,
stdout: "pipe",
stderr: "pipe",
},
/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},
{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},
],
});

23
boa_wasm/e2e_test/server.mjs

@ -0,0 +1,23 @@
import { createServer } from "http";
import { readFile, readFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath, parse } from "url";
import { lookup } from "mime-types";
const __filename = fileURLToPath(import.meta.url);
createServer((req, res) => {
const __dirname = dirname(__filename);
const path = join(__dirname, "../../dist", parse(req.url, true).path);
readFile(path, (err, data) => {
if (err) {
res.writeHead(200, { "Content-Type": "text/html" });
res.end(readFileSync(join(__dirname, "../../dist/index.html")));
} else {
res.writeHead(200, { "Content-Type": lookup(path) });
res.end(data);
}
});
}).listen(8081, () => {
console.log("Server running at http://localhost:8081/");
});

2
index.html

@ -70,7 +70,7 @@
</header>
<div class="demo__repl">
<div class="textbox"></div>
<p class="output"></p>
<p data-testid="output" class="output"></p>
</div>
</div>
</body>

56
package-lock.json generated

@ -5,9 +5,11 @@
"packages": {
"": {
"dependencies": {
"mime-types": "^2.1.35",
"monaco-editor": "^0.38.0"
},
"devDependencies": {
"@playwright/test": "^1.34.3",
"@wasm-tool/wasm-pack-plugin": "^1.7.0",
"bootstrap": "^5.3.0",
"clean-webpack-plugin": "^4.0.0",
@ -132,6 +134,25 @@
"node": ">= 8"
}
},
"node_modules/@playwright/test": {
"version": "1.34.3",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.34.3.tgz",
"integrity": "sha512-zPLef6w9P6T/iT6XDYG3mvGOqOyb6eHaV9XtkunYs0+OzxBtrPAAaHotc0X+PJ00WPPnLfFBTl7mf45Mn8DBmw==",
"dev": true,
"dependencies": {
"@types/node": "*",
"playwright-core": "1.34.3"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=14"
},
"optionalDependencies": {
"fsevents": "2.3.2"
}
},
"node_modules/@popperjs/core": {
"version": "2.11.8",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
@ -2729,7 +2750,6 @@
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"dev": true,
"engines": {
"node": ">= 0.6"
}
@ -2738,7 +2758,6 @@
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dev": true,
"dependencies": {
"mime-db": "1.52.0"
},
@ -3188,6 +3207,18 @@
"node": ">=8"
}
},
"node_modules/playwright-core": {
"version": "1.34.3",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.34.3.tgz",
"integrity": "sha512-2pWd6G7OHKemc5x1r1rp8aQcpvDh7goMBZlJv6Co5vCNLVcQJdhxRL09SGaY6HcyHH9aT4tiynZabMofVasBYw==",
"dev": true,
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=14"
}
},
"node_modules/postcss": {
"version": "8.4.23",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.23.tgz",
@ -4771,6 +4802,17 @@
"fastq": "^1.6.0"
}
},
"@playwright/test": {
"version": "1.34.3",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.34.3.tgz",
"integrity": "sha512-zPLef6w9P6T/iT6XDYG3mvGOqOyb6eHaV9XtkunYs0+OzxBtrPAAaHotc0X+PJ00WPPnLfFBTl7mf45Mn8DBmw==",
"dev": true,
"requires": {
"@types/node": "*",
"fsevents": "2.3.2",
"playwright-core": "1.34.3"
}
},
"@popperjs/core": {
"version": "2.11.8",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
@ -6780,14 +6822,12 @@
"mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"dev": true
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
},
"mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dev": true,
"requires": {
"mime-db": "1.52.0"
}
@ -7119,6 +7159,12 @@
"find-up": "^4.0.0"
}
},
"playwright-core": {
"version": "1.34.3",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.34.3.tgz",
"integrity": "sha512-2pWd6G7OHKemc5x1r1rp8aQcpvDh7goMBZlJv6Co5vCNLVcQJdhxRL09SGaY6HcyHH9aT4tiynZabMofVasBYw==",
"dev": true
},
"postcss": {
"version": "8.4.23",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.23.tgz",

3
package.json

@ -2,9 +2,11 @@
"scripts": {
"build": "webpack",
"serve": "webpack-dev-server",
"e2e": "playwright test -c ./boa_wasm/e2e_test/playwright.config.ts",
"build:prod": "webpack --mode=production"
},
"devDependencies": {
"@playwright/test": "^1.34.3",
"@wasm-tool/wasm-pack-plugin": "^1.7.0",
"bootstrap": "^5.3.0",
"clean-webpack-plugin": "^4.0.0",
@ -21,6 +23,7 @@
"webpack-dev-server": "^4.15.0"
},
"dependencies": {
"mime-types": "^2.1.35",
"monaco-editor": "^0.38.0"
}
}

15
webpack.config.js

@ -45,11 +45,14 @@ module.exports = {
}),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({ template: "index.html" }),
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, "./boa_wasm/"),
outDir: path.resolve(__dirname, "./boa_wasm/pkg/"),
forceMode: "production",
}),
// WasmPackPlugin can not work in CI environment
!process.env.CI
? new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, "./boa_wasm/"),
outDir: path.resolve(__dirname, "./boa_wasm/pkg/"),
forceMode: "production",
})
: undefined,
new CopyWebpackPlugin({
patterns: [
{
@ -62,7 +65,7 @@ module.exports = {
},
],
}),
],
].filter(Boolean),
module: {
rules: [
{

Loading…
Cancel
Save