Skip to content

Commit

Permalink
Enable E2E tests for @ruby/head-wasm-wasip2 package
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Oct 20, 2024
1 parent d00ee2d commit cd68c62
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
10 changes: 8 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions packages/npm-packages/ruby-head-wasm-wasip2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
"README.md"
],
"scripts": {
"__comment": "FIXME: Enable test:e2e after https://github.com/bytecodealliance/jco/pull/499 is merged",
"test": "npm run run-script -- test:unit && npm run run-script -- test:vitest -- --run",
"run-script": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run",
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run test:run",
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
"build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
"build:static": "npm run build:static:files",
Expand All @@ -53,6 +51,6 @@
"license": "MIT",
"dependencies": {
"@ruby/wasm-wasi": "^2.0.0",
"@bytecodealliance/preview2-shim": "^0.16.5"
"@bytecodealliance/preview2-shim": "^0.17.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
end
end

# "bundle install --standalone" does not care about bundled gems, so we need
# to activate them manually.
Gem::Dependency.new("csv").to_spec.activate

# The above patch does not break the original require_relative
require 'csv'
csv = CSV.new "foo\nbar\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ test.beforeEach(async ({ context, page }) => {
});

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

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

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

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

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

await waitForRubyVM(page);
const expected = "Hello, world!\n";
while (messages[messages.length - 1] != expected) {
while (!messages.some((msg) => /Hello, world\!/.test(msg))) {
await page.waitForEvent("console");
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {

test.describe('WASI browser binding', () => {
test("Read/write on in-memory file system", async ({ page }) => {
test.skip(
process.env.ENABLE_COMPONENT_TESTS != undefined,
"@bytecodealliance/preview2-shim does not allow writing to the file system"
);
const resolve = await resolveBinding(page, "checkResolved");
await page.setContent(`
<script src="https://cdn.jsdelivr.net/npm/@ruby/head-wasm-wasi@latest/dist/browser.script.iife.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion packages/npm-packages/ruby-wasm-wasi/test-e2e/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const setupDebugLog = (context: BrowserContext) => {

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

0 comments on commit cd68c62

Please sign in to comment.