Skip to content

Commit e861472

Browse files
Get rid of dev-server dependency from test runner (#503)
1 parent 2fdf063 commit e861472

32 files changed

+718
-798
lines changed

.github/workflows/swift.yml

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
- name: Install dependencies for macOS
4848
run: brew bundle
4949

50+
- run: npm install && npx playwright install chromium
51+
5052
- name: Build the project
5153
run: swift build --build-tests
5254

@@ -89,6 +91,8 @@ jobs:
8991
sudo apt-get update && sudo apt-get install -y
9092
wabt binaryen
9193
94+
- run: npm install && npx playwright install chromium
95+
9296
- name: Install WebAssembly runtime
9397
uses: bytecodealliance/actions/wasmtime/setup@v1
9498

Package.swift

+46-46
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import PackageDescription
55

66
#if swift(<5.9.2)
7-
#warning("Swift 5.9.1 or earlier is not supported by carton")
7+
#warning("Swift 5.9.1 or earlier is not supported by carton")
88
#endif
99

1010
let package = Package(
@@ -33,7 +33,7 @@ let package = Package(
3333
.target(
3434
name: "CartonDriver",
3535
dependencies: [
36-
"SwiftToolchain",
36+
"SwiftToolchain"
3737
]
3838
),
3939
.executableTarget(
@@ -57,52 +57,52 @@ let package = Package(
5757
]
5858
),
5959
.plugin(
60-
name: "CartonBundlePlugin",
61-
capability: .command(
62-
intent: .custom(
63-
verb: "carton-bundle",
64-
description: "Produces an optimized app bundle for distribution."
65-
)
66-
),
67-
dependencies: ["carton-frontend-slim"],
68-
exclude: [
69-
"CartonCore/README.md",
70-
"CartonPluginShared/README.md"
71-
]
60+
name: "CartonBundlePlugin",
61+
capability: .command(
62+
intent: .custom(
63+
verb: "carton-bundle",
64+
description: "Produces an optimized app bundle for distribution."
65+
)
66+
),
67+
dependencies: ["carton-frontend-slim"],
68+
exclude: [
69+
"CartonCore/README.md",
70+
"CartonPluginShared/README.md",
71+
]
7272
),
7373
.plugin(
74-
name: "CartonTestPlugin",
75-
capability: .command(
76-
intent: .custom(
77-
verb: "carton-test",
78-
description: "Run the tests in a WASI environment."
79-
)
80-
),
81-
dependencies: ["carton-frontend"],
82-
exclude: [
83-
"CartonCore/README.md",
84-
"CartonPluginShared/README.md"
85-
]
74+
name: "CartonTestPlugin",
75+
capability: .command(
76+
intent: .custom(
77+
verb: "carton-test",
78+
description: "Run the tests in a WASI environment."
79+
)
80+
),
81+
dependencies: ["carton-frontend-slim"],
82+
exclude: [
83+
"CartonCore/README.md",
84+
"CartonPluginShared/README.md",
85+
]
8686
),
8787
.plugin(
88-
name: "CartonDevPlugin",
89-
capability: .command(
90-
intent: .custom(
91-
verb: "carton-dev",
92-
description: "Watch the current directory, host the app, rebuild on change."
93-
)
94-
),
95-
dependencies: ["carton-frontend"],
96-
exclude: [
97-
"CartonCore/README.md",
98-
"CartonPluginShared/README.md"
99-
]
88+
name: "CartonDevPlugin",
89+
capability: .command(
90+
intent: .custom(
91+
verb: "carton-dev",
92+
description: "Watch the current directory, host the app, rebuild on change."
93+
)
94+
),
95+
dependencies: ["carton-frontend"],
96+
exclude: [
97+
"CartonCore/README.md",
98+
"CartonPluginShared/README.md",
99+
]
100100
),
101101
.executableTarget(name: "carton-plugin-helper"),
102102
.target(
103103
name: "CartonFrontend",
104104
dependencies: [
105-
"CartonKit",
105+
"CartonKit"
106106
]
107107
),
108108
.target(
@@ -113,7 +113,6 @@ let package = Package(
113113
.product(name: "NIO", package: "swift-nio"),
114114
.product(name: "ArgumentParser", package: "swift-argument-parser"),
115115
"CartonHelpers",
116-
"WebDriver",
117116
"WasmTransformer",
118117
],
119118
exclude: ["Utilities/README.md"],
@@ -124,27 +123,27 @@ let package = Package(
124123
.target(
125124
name: "SwiftToolchain",
126125
dependencies: [
127-
"CartonCore",
126+
"CartonCore"
128127
],
129128
exclude: ["Utilities/README.md"]
130129
),
131130
.target(
132131
/** Shim target to import missing C headers in Darwin and Glibc modulemap. */
133132
name: "TSCclibc",
134133
cSettings: [
135-
.define("_GNU_SOURCE", .when(platforms: [.linux])),
134+
.define("_GNU_SOURCE", .when(platforms: [.linux]))
136135
]
137136
),
138137
.target(
139-
/** Cross-platform access to bare `libc` functionality. */
140-
name: "TSCLibc"
138+
/** Cross-platform access to bare `libc` functionality. */
139+
name: "TSCLibc"
141140
),
142141
.target(
143142
name: "CartonHelpers",
144143
dependencies: [
145144
"TSCclibc",
146145
"TSCLibc",
147-
"CartonCore"
146+
"CartonCore",
148147
],
149148
exclude: ["Basics/README.md"]
150149
),
@@ -156,7 +155,7 @@ let package = Package(
156155
name: "WebDriver",
157156
dependencies: [
158157
.product(name: "NIO", package: "swift-nio"),
159-
"CartonHelpers"
158+
"CartonHelpers",
160159
]
161160
),
162161
// This target is used only for release automation tasks and
@@ -165,6 +164,7 @@ let package = Package(
165164
name: "carton-release",
166165
dependencies: [
167166
.product(name: "ArgumentParser", package: "swift-argument-parser"),
167+
"CartonHelpers",
168168
"CartonCore",
169169
]
170170
),

Plugins/CartonTestPlugin/CartonTestPluginCommand.swift

+22-20
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ struct CartonTestPluginCommand: CommandPlugin {
3737

3838
func performCommand(context: PluginContext, arguments: [String]) async throws {
3939
try checkSwiftVersion()
40-
try checkHelpFlag(arguments, subcommand: "test", context: context)
40+
try checkHelpFlag(
41+
arguments, frontend: "carton-frontend-slim", subcommand: "test", context: context)
4142

4243
let productName = "\(context.package.displayName)PackageTests"
4344

@@ -71,25 +72,25 @@ struct CartonTestPluginCommand: CommandPlugin {
7172
let wasmFileName = "\(productName).wasm"
7273
testProductArtifactPath = buildDirectory.appending(subpath: wasmFileName).string
7374
#if compiler(>=5.10)
74-
var buildParameters = PackageManager.BuildParameters()
75-
options.environment.applyBuildParameters(&buildParameters)
76-
applyExtraBuildFlags(from: &extractor, parameters: &buildParameters)
75+
var buildParameters = PackageManager.BuildParameters()
76+
options.environment.applyBuildParameters(&buildParameters)
77+
applyExtraBuildFlags(from: &extractor, parameters: &buildParameters)
7778

78-
let build = try packageManager.build(.product(productName), parameters: buildParameters)
79-
guard build.succeeded else {
80-
throw Error("Failed to build test product: \(build.logText)")
81-
}
82-
guard FileManager.default.fileExists(atPath: testProductArtifactPath) else {
83-
throw Error("Product \(productName) did not produce \(buildDirectory)!?")
84-
}
79+
let build = try packageManager.build(.product(productName), parameters: buildParameters)
80+
guard build.succeeded else {
81+
throw Error("Failed to build test product: \(build.logText)")
82+
}
83+
guard FileManager.default.fileExists(atPath: testProductArtifactPath) else {
84+
throw Error("Product \(productName) did not produce \(buildDirectory)!?")
85+
}
8586
#else
86-
// NOTE: Old SwiftPM does not allow to build *only tests* from plugin, so we expect
87-
// the test product to be built already by external wrapper command.
88-
guard FileManager.default.fileExists(atPath: testProductArtifactPath) else {
89-
throw Error(
90-
"Failed to find \"\(wasmFileName)\" in \(buildDirectory). Please build \"\(productName)\" product first"
91-
)
92-
}
87+
// NOTE: Old SwiftPM does not allow to build *only tests* from plugin, so we expect
88+
// the test product to be built already by external wrapper command.
89+
guard FileManager.default.fileExists(atPath: testProductArtifactPath) else {
90+
throw Error(
91+
"Failed to find \"\(wasmFileName)\" in \(buildDirectory). Please build \"\(productName)\" product first"
92+
)
93+
}
9394
#endif
9495
}
9596

@@ -107,14 +108,15 @@ struct CartonTestPluginCommand: CommandPlugin {
107108
"test",
108109
"--prebuilt-test-bundle-path", testProductArtifactPath,
109110
"--environment", options.environment.rawValue,
110-
"--plugin-work-directory", context.pluginWorkDirectory.string
111+
"--plugin-work-directory", context.pluginWorkDirectory.string,
111112
]
112113
args += (options.pid.map { ["--pid", $0] } ?? [])
113114
args += resourcesPaths.flatMap {
114115
["--resources", $0.string]
115116
}
116117
args += extractor.remainingArguments
117-
let frontend = try makeCartonFrontendProcess(context: context, arguments: args)
118+
let frontend = try makeCartonFrontendProcess(
119+
context: context, frontend: "carton-frontend-slim", arguments: args)
118120
try frontend.checkRun(printsLoadingMessage: false, forwardExit: true)
119121
}
120122

Sources/CartonFrontend/CartonFrontendCommand.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public struct CartonFrontendCommand: AsyncParsableCommand {
2121
abstract: "📦 Watcher, bundler, and test runner for your SwiftWasm apps.",
2222
version: cartonVersion,
2323
subcommands: [
24-
CartonFrontendDevCommand.self,
25-
CartonFrontendTestCommand.self
24+
CartonFrontendDevCommand.self
2625
]
2726
)
2827

Sources/CartonFrontend/Commands/CartonFrontendDevCommand.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// limitations under the License.
1414

1515
import ArgumentParser
16-
import CartonHelpers
1716
import CartonCore
17+
import CartonHelpers
1818
import CartonKit
1919
import Foundation
2020

@@ -28,8 +28,10 @@ enum DevCommandError: Error & CustomStringConvertible {
2828

2929
var description: String {
3030
switch self {
31-
case .noBuildRequestOption: "--build-request option is necessary if you want to watch, but has not been specified."
32-
case .noBuildResponseOption: "--build-response option is necessary if you want to watch, but has not been specified."
31+
case .noBuildRequestOption:
32+
"--build-request option is necessary if you want to watch, but has not been specified."
33+
case .noBuildResponseOption:
34+
"--build-response option is necessary if you want to watch, but has not been specified."
3335
case .failedToOpenBuildRequestPipe: "failed to open build request pipe."
3436
case .failedToOpenBuildResponsePipe: "failed to open build response pipe."
3537
case .pluginConnectionClosed: "connection with the plugin has been closed."
@@ -50,9 +52,6 @@ struct CartonFrontendDevCommand: AsyncParsableCommand {
5052
@Flag(help: "When specified, build in the release mode.")
5153
var release = false
5254

53-
@Option(help: "Turn on runtime checks for various behavior.")
54-
private var sanitize: SanitizeVariant?
55-
5655
@Flag(name: .shortAndLong, help: "Don't clear terminal window after files change.")
5756
var verbose = false
5857

0 commit comments

Comments
 (0)