Skip to content

Commit 4c12c77

Browse files
Merge pull request #542 from ruby/katei/enable-p2-e2e
Enable E2E tests for `@ruby/head-wasm-wasip2` package
2 parents d00ee2d + cd68c62 commit 4c12c77

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

Diff for: package-lock.json

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/npm-packages/ruby-head-wasm-wasip2/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
"README.md"
3131
],
3232
"scripts": {
33-
"__comment": "FIXME: Enable test:e2e after https://github.com/bytecodealliance/jco/pull/499 is merged",
34-
"test": "npm run run-script -- test:unit && npm run run-script -- test:vitest -- --run",
35-
"run-script": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run",
33+
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run test:run",
3634
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
3735
"build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
3836
"build:static": "npm run build:static:files",
@@ -53,6 +51,6 @@
5351
"license": "MIT",
5452
"dependencies": {
5553
"@ruby/wasm-wasi": "^2.0.0",
56-
"@bytecodealliance/preview2-shim": "^0.16.5"
54+
"@bytecodealliance/preview2-shim": "^0.17.0"
5755
}
5856
}

Diff for: packages/npm-packages/ruby-wasm-wasi/example/require_relative/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
end
2222
end
2323

24+
# "bundle install --standalone" does not care about bundled gems, so we need
25+
# to activate them manually.
26+
Gem::Dependency.new("csv").to_spec.activate
27+
2428
# The above patch does not break the original require_relative
2529
require 'csv'
2630
csv = CSV.new "foo\nbar\n"

Diff for: packages/npm-packages/ruby-wasm-wasi/test-e2e/examples/examples.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ test.beforeEach(async ({ context, page }) => {
3636
});
3737

3838
test("hello.html is healthy", async ({ page }) => {
39-
const messages = [];
39+
const messages: string[] = [];
4040
page.on("console", (msg) => messages.push(msg.text()));
4141
await page.goto("/hello.html");
4242

4343
await waitForRubyVM(page);
44-
expect(messages[messages.length - 1]).toEqual("Hello, world!\n");
44+
while (!messages.some((msg) => /Hello, world\!/.test(msg))) {
45+
await page.waitForEvent("console");
46+
}
4547
});
4648

4749
test("lucky.html is healthy", async ({ page }) => {
@@ -54,13 +56,12 @@ test("lucky.html is healthy", async ({ page }) => {
5456
});
5557

5658
test("script-src/index.html is healthy", async ({ page }) => {
57-
const messages = [];
59+
const messages: string[] = [];
5860
page.on("console", (msg) => messages.push(msg.text()));
5961
await page.goto("/script-src/index.html");
6062

6163
await waitForRubyVM(page);
62-
const expected = "Hello, world!\n";
63-
while (messages[messages.length - 1] != expected) {
64+
while (!messages.some((msg) => /Hello, world\!/.test(msg))) {
6465
await page.waitForEvent("console");
6566
}
6667
});
@@ -79,8 +80,7 @@ if (process.env.RUBY_NPM_PACKAGE_ROOT) {
7980
await page.goto("/require_relative/index.html");
8081

8182
await waitForRubyVM(page);
82-
const expected = "Hello, world!\n";
83-
while (messages[messages.length - 1] != expected) {
83+
while (!messages.some((msg) => /Hello, world\!/.test(msg))) {
8484
await page.waitForEvent("console");
8585
}
8686
});

Diff for: packages/npm-packages/ruby-wasm-wasi/test-e2e/integrations/wasi-binding.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
1818

1919
test.describe('WASI browser binding', () => {
2020
test("Read/write on in-memory file system", async ({ page }) => {
21+
test.skip(
22+
process.env.ENABLE_COMPONENT_TESTS != undefined,
23+
"@bytecodealliance/preview2-shim does not allow writing to the file system"
24+
);
2125
const resolve = await resolveBinding(page, "checkResolved");
2226
await page.setContent(`
2327
<script src="https://cdn.jsdelivr.net/npm/@ruby/head-wasm-wasi@latest/dist/browser.script.iife.js"></script>

Diff for: packages/npm-packages/ruby-wasm-wasi/test-e2e/support.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const setupDebugLog = (context: BrowserContext) => {
1919

2020
export const setupProxy = (context: BrowserContext) => {
2121
const cdnPattern =
22-
/cdn.jsdelivr.net\/npm\/@ruby\/.+-wasm-wasi@.+\/dist\/(.+)/;
22+
/cdn.jsdelivr.net\/npm\/@ruby\/.+@.+\/dist\/(.+)/;
2323
context.route(cdnPattern, (route) => {
2424
const request = route.request();
2525
console.log(">> [MOCK]", request.method(), request.url());

0 commit comments

Comments
 (0)