Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the output of wasm in dev subcommand test #473

Merged
merged 4 commits into from
May 28, 2024

Conversation

omochi
Copy link
Contributor

@omochi omochi commented May 25, 2024

dev serverのテストではコンテンツの配送はテストされていたが、
それをブラウザ開いたらちゃんと動くかどうかは全くテストされていなかった。

dev serverがwasmから受け取った出力をコンソールに出すので、
frontendを起動するテスト側で出力を監視する。

Linux では xdg-open となってるけど CI はうまくいくんだろうか?

#474 の成果を使って、
WebDriverを利用してテストする

do {
try openInSystemBrowser(url: localURL)
} catch {
terminal.write("open browser failed: \(error)", inColor: .red)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

従来通り、起動しなくても処理は続ける

@@ -105,8 +117,8 @@ public actor Server {

private var serverChannel: (any Channel)!

/// Local URL of this server, `https://128.0.0.1:8080/` by default.
private let localURL: String
/// Local URL of this server, `https://127.0.0.1:8080/` by default.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localhostは127です

/// Local URL of this server, `https://128.0.0.1:8080/` by default.
private let localURL: String
/// Local URL of this server, `https://127.0.0.1:8080/` by default.
private let localURL: URL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

早めにURL型にします

/// - Returns: true if launching command returns successfully.
@discardableResult
public func openInSystemBrowser(url: String) -> Bool {
public func openInSystemBrowser(url: URL) throws {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stringを受け取ってBoolを返していましたが、
URLを受け取って失敗したら例外を投げるようにします。

引数については型を活用します。
エラーについてですが、例外の方が情報が多いです。

おそらく元々の実装はブラウザオープンに失敗しても動作を止めないことを想定していますが、
それは関数呼び出し側の都合で、必要ならcatchすれば良いです。

@@ -27,7 +27,7 @@ final class WebDriverClientTests: XCTestCase {
let client = try await WebDriverClient.newSession(
endpoint: checkRemoteURL(), httpClient: .shared
)
try await client.goto(url: "https://example.com")
try await client.goto(url: URL(string: "https://github.com/swiftwasm/carton")!)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一応自分たちが管理してるURLの方が良いと思います。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example.com is managed by ICANN. It should be more reliable than GitHub IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、OKです。戻します。

@@ -84,6 +102,16 @@ final class FrontendDevServerTests: XCTestCase {
let expected = try String(contentsOf: resourcesDir.appending(component: name).asURL)
XCTAssertEqual(styleCss, expected)
}

try openInSystemBrowser(url: host)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think open families work on CI. We should use WebDriver or something like headless solutions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね。
$ carton test で使われている実装を再利用するようにコードを組んでみます。

@omochi omochi changed the title frontend devのテストでwasmの出力をチェックする [WIP] frontend devのテストでwasmの出力をチェックする May 26, 2024
@omochi omochi changed the title [WIP] frontend devのテストでwasmの出力をチェックする frontend devのテストでwasmの出力をチェックする May 28, 2024
@omochi omochi marked this pull request as ready for review May 28, 2024 12:49
@kateinoigakukun kateinoigakukun changed the title frontend devのテストでwasmの出力をチェックする Check the output of wasm in dev subcommand test May 28, 2024
@kateinoigakukun kateinoigakukun merged commit 305c204 into swiftwasm:main May 28, 2024
4 checks passed
@omochi omochi deleted the test-dev-wasm-run branch May 28, 2024 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants