Skip to content

Commit 7e367fc

Browse files
rake format
1 parent d95aa40 commit 7e367fc

File tree

16 files changed

+154
-130
lines changed

16 files changed

+154
-130
lines changed

ext/js/lib/js.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ def await(promise)
8383
->(value) { current.transfer(value, :failure) }
8484
)
8585
if @loop == current
86-
raise ("JS::Object#await can be called only from RubyVM#evalAsync JS API\n" +
87-
"If you are using browser.script.iife.js, please ensure that you specify `data-eval=\"async\"` in your script tag\n" +
88-
"e.g. <script type=\"text/ruby\" data-eval=\"async\">puts :hello</script>\n" +
89-
"Or <script type=\"text/ruby\" data-eval=\"async\" src=\"path/to/script.rb\"></script>")
90-
86+
raise (
87+
"JS::Object#await can be called only from RubyVM#evalAsync JS API\n" +
88+
"If you are using browser.script.iife.js, please ensure that you specify `data-eval=\"async\"` in your script tag\n" +
89+
"e.g. <script type=\"text/ruby\" data-eval=\"async\">puts :hello</script>\n" +
90+
"Or <script type=\"text/ruby\" data-eval=\"async\" src=\"path/to/script.rb\"></script>"
91+
)
9192
end
9293
value, status = @loop.transfer
9394
raise JS::Error.new(value) if status == :failure

ext/js/lib/js/hash.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ class Hash
22
# Convert a hash to a JavaScript object
33
def to_js
44
new_object = JS.eval("return {}")
5-
self.each do |key, value|
6-
new_object[key] = value
7-
end
5+
self.each { |key, value| new_object[key] = value }
86
new_object
97
end
108
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
testEnvironment: "node",
3-
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/test-e2e/"]
3+
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/test-e2e/"],
44
};

packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ const runRubyScriptsInHtml = async (vm) => {
5151
const deriveEvalStyle = (tag: Element): "async" | "sync" => {
5252
const rawEvalStyle = tag.getAttribute("data-eval") || "sync";
5353
if (rawEvalStyle !== "async" && rawEvalStyle !== "sync") {
54-
console.warn(`data-eval attribute of script tag must be "async" or "sync". ${rawEvalStyle} is ignored and "sync" is used instead.`);
54+
console.warn(
55+
`data-eval attribute of script tag must be "async" or "sync". ${rawEvalStyle} is ignored and "sync" is used instead.`
56+
);
5557
return "sync";
5658
}
5759
return rawEvalStyle;
5860
};
5961

60-
const loadScriptAsync = async (tag: Element): Promise<{ scriptContent: string, evalStyle: "async" | "sync" } | null> => {
62+
const loadScriptAsync = async (
63+
tag: Element
64+
): Promise<{ scriptContent: string; evalStyle: "async" | "sync" } | null> => {
6165
const evalStyle = deriveEvalStyle(tag);
6266
// Inline comments can be written with the src attribute of the script tag.
6367
// The presence of the src attribute is checked before the presence of the inline.

packages/npm-packages/ruby-wasm-wasi/src/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export const DefaultRubyVM = async (
7676
// default Fiber stack size as well as main stack size allocated
7777
// by wasm-ld's --stack-size. The ideal solution is to reduce
7878
// stack consumption in setjmp.
79-
"RUBY_FIBER_MACHINE_STACK_SIZE": "16777216"
80-
}
79+
RUBY_FIBER_MACHINE_STACK_SIZE: "16777216",
80+
},
8181
});
8282
const vm = new RubyVM();
8383

packages/npm-packages/ruby-wasm-wasi/src/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const DefaultRubyVM = async (rubyModule: WebAssembly.Module) => {
88
// default Fiber stack size as well as main stack size allocated
99
// by wasm-ld's --stack-size. The ideal solution is to reduce
1010
// stack consumption in setjmp.
11-
"RUBY_FIBER_MACHINE_STACK_SIZE": "16777216"
12-
}
11+
RUBY_FIBER_MACHINE_STACK_SIZE: "16777216",
12+
},
1313
});
1414
const vm = new RubyVM();
1515
const imports = {
Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,60 @@
1-
import { test, expect, Page } from '@playwright/test';
2-
import path from "path"
3-
import { waitForRubyVM, setupDebugLog, setupProxy } from "../support"
4-
import { readFileSync } from 'fs';
5-
import http from 'http';
6-
import https from 'https';
1+
import { test, expect, Page } from "@playwright/test";
2+
import path from "path";
3+
import { waitForRubyVM, setupDebugLog, setupProxy } from "../support";
4+
import { readFileSync } from "fs";
5+
import http from "http";
6+
import https from "https";
77

88
test.beforeEach(async ({ context }) => {
99
setupDebugLog(context);
1010
if (process.env.RUBY_NPM_PACKAGE_ROOT) {
1111
setupProxy(context);
1212
} else {
1313
console.info("Testing against CDN deployed files");
14-
const packagePath = path.join(__dirname, "..", "..", "package.json")
15-
const packageInfo = JSON.parse(readFileSync(packagePath, "utf-8"))
16-
const version = packageInfo.version
17-
const url = `https://registry.npmjs.org/ruby-head-wasm-wasi/${version}`
18-
const response = await new Promise<http.IncomingMessage>((resolve, reject) => {
19-
https.get(url, resolve).on("error", reject)
20-
})
14+
const packagePath = path.join(__dirname, "..", "..", "package.json");
15+
const packageInfo = JSON.parse(readFileSync(packagePath, "utf-8"));
16+
const version = packageInfo.version;
17+
const url = `https://registry.npmjs.org/ruby-head-wasm-wasi/${version}`;
18+
const response = await new Promise<http.IncomingMessage>(
19+
(resolve, reject) => {
20+
https.get(url, resolve).on("error", reject);
21+
}
22+
);
2123
if (response.statusCode == 404) {
22-
console.log(`ruby-head-wasm-wasi@${version} is not published yet, so skipping CDN tests`);
24+
console.log(
25+
`ruby-head-wasm-wasi@${version} is not published yet, so skipping CDN tests`
26+
);
2327
test.skip();
2428
}
2529
}
26-
})
30+
});
2731

28-
test('hello.html is healthy', async ({ page }) => {
29-
const messages = []
30-
page.on("console", msg => messages.push(msg.text()))
31-
await page.goto('/hello.html');
32+
test("hello.html is healthy", async ({ page }) => {
33+
const messages = [];
34+
page.on("console", (msg) => messages.push(msg.text()));
35+
await page.goto("/hello.html");
3236

33-
await waitForRubyVM(page)
34-
expect(messages[messages.length - 1]).toEqual("Hello, world!\n")
37+
await waitForRubyVM(page);
38+
expect(messages[messages.length - 1]).toEqual("Hello, world!\n");
3539
});
3640

37-
test('lucky.html is healthy', async ({ page }) => {
38-
await page.goto('/lucky.html');
39-
await waitForRubyVM(page)
40-
await page.getByRole('button', { name: 'Draw Omikuji' }).click()
41-
const result = await page.locator("#result").textContent()
41+
test("lucky.html is healthy", async ({ page }) => {
42+
await page.goto("/lucky.html");
43+
await waitForRubyVM(page);
44+
await page.getByRole("button", { name: "Draw Omikuji" }).click();
45+
const result = await page.locator("#result").textContent();
4246

43-
expect(result).toMatch(/(Lucky|Unlucky)/)
47+
expect(result).toMatch(/(Lucky|Unlucky)/);
4448
});
4549

46-
test('script-src/index.html is healthy', async ({ page }) => {
47-
const messages = []
48-
page.on("console", msg => messages.push(msg.text()))
49-
await page.goto('/script-src/index.html');
50+
test("script-src/index.html is healthy", async ({ page }) => {
51+
const messages = [];
52+
page.on("console", (msg) => messages.push(msg.text()));
53+
await page.goto("/script-src/index.html");
5054

51-
await waitForRubyVM(page)
52-
const expected = "Hello, world!\n"
55+
await waitForRubyVM(page);
56+
const expected = "Hello, world!\n";
5357
while (messages[messages.length - 1] != expected) {
54-
await page.waitForEvent("console")
58+
await page.waitForEvent("console");
5559
}
5660
});
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { test, expect, Page } from '@playwright/test';
1+
import { test, expect, Page } from "@playwright/test";
22

3-
import { setupDebugLog, setupProxy, waitForRubyVM } from "../support"
3+
import { setupDebugLog, setupProxy, waitForRubyVM } from "../support";
44

55
if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
6-
test.skip('skip', () => {})
6+
test.skip("skip", () => {});
77
} else {
88
test.beforeEach(async ({ context }) => {
99
setupDebugLog(context);
1010
setupProxy(context);
11-
})
11+
});
1212

1313
const resolveBinding = async (page: Page, name: string) => {
1414
let checkResolved;
1515
const resolvedValue = new Promise((resolve) => {
1616
checkResolved = resolve;
17-
})
17+
});
1818
await page.exposeBinding(name, async (source, v) => {
1919
checkResolved(v);
2020
});
21-
return async () => await resolvedValue
22-
}
21+
return async () => await resolvedValue;
22+
};
2323

2424
test.describe('data-eval="async"', () => {
2525
test("JS::Object#await returns value", async ({ page }) => {
@@ -30,9 +30,9 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
3030
require "js"
3131
JS.global.checkResolved JS.global[:Promise].resolve(42).await
3232
</script>
33-
`)
33+
`);
3434
expect(await resolve()).toBe(42);
35-
})
35+
});
3636

3737
test("JS::Object#await throws error on default attr", async ({ page }) => {
3838
await page.setContent(`
@@ -41,10 +41,12 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
4141
require "js"
4242
JS.global[:Promise].resolve(42).await
4343
</script>
44-
`)
45-
const error = await page.waitForEvent("pageerror")
46-
expect(error.message).toMatch(/please ensure that you specify `data-eval="async"`/)
47-
})
44+
`);
45+
const error = await page.waitForEvent("pageerror");
46+
expect(error.message).toMatch(
47+
/please ensure that you specify `data-eval="async"`/
48+
);
49+
});
4850

4951
test("default stack size is enough to require 'json'", async ({ page }) => {
5052
const resolve = await resolveBinding(page, "checkResolved");
@@ -54,8 +56,8 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
5456
require 'json'
5557
JS.global.checkResolved "ok"
5658
</script>
57-
`)
59+
`);
5860
expect(await resolve()).toBe("ok");
59-
})
60-
})
61+
});
62+
});
6163
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { defineConfig } from '@playwright/test';
2-
import base from "./playwright.base.config"
1+
import { defineConfig } from "@playwright/test";
2+
import base from "./playwright.base.config";
33

44
export default defineConfig({
55
...base,
6-
testDir: 'examples',
6+
testDir: "examples",
77
use: {
8-
baseURL: 'http://127.0.0.1:8085',
8+
baseURL: "http://127.0.0.1:8085",
99
},
1010
webServer: {
11-
command: 'npm run serve:example',
12-
url: 'http://127.0.0.1:8085',
11+
command: "npm run serve:example",
12+
url: "http://127.0.0.1:8085",
1313
reuseExistingServer: !process.env.CI,
1414
},
1515
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { defineConfig } from '@playwright/test';
2-
import base from "./playwright.base.config"
1+
import { defineConfig } from "@playwright/test";
2+
import base from "./playwright.base.config";
33

44
export default defineConfig({
55
...base,
6-
testDir: 'integrations',
6+
testDir: "integrations",
77
});

0 commit comments

Comments
 (0)