Skip to content

Commit b06a79b

Browse files
BridgeJS: Allow executing TS2SwiftVitestTests on Xcode
1 parent 9eaefa6 commit b06a79b

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Plugins/BridgeJS/Sources/TS2Swift/TS2Swift.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import BridgeJSCore
2020
import BridgeJSSkeleton
2121
#endif
2222

23+
#if os(Windows)
24+
let PATH_SEPARATOR: Character = ";"
25+
#else
26+
let PATH_SEPARATOR: Character = ":"
27+
#endif
28+
2329
internal func which(
2430
_ executable: String,
2531
environment: [String: String] = ProcessInfo.processInfo.environment
@@ -39,13 +45,8 @@ internal func which(
3945
}
4046
}
4147
}
42-
let pathSeparator: Character
43-
#if os(Windows)
44-
pathSeparator = ";"
45-
#else
46-
pathSeparator = ":"
47-
#endif
48-
let paths = environment["PATH"]?.split(separator: pathSeparator) ?? []
48+
49+
let paths = environment["PATH"]?.split(separator: PATH_SEPARATOR) ?? []
4950
for path in paths {
5051
let url = URL(fileURLWithPath: String(path)).appendingPathComponent(executable)
5152
if checkCandidate(url) {

Plugins/BridgeJS/Tests/BridgeJSToolTests/TS2SwiftVitestTests.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import Testing
3+
@testable import TS2Swift
34

45
/// Runs the TS2Swift JavaScript test suite (Vitest) so that `swift test --package-path ./Plugins/BridgeJS`
56
/// validates both the TypeScript ts2swift output and the Swift codegen. For fast iteration on ts2swift,
@@ -17,8 +18,16 @@ import Testing
1718
.appendingPathComponent("TS2Swift")
1819
.appendingPathComponent("JavaScript")
1920
let process = Process()
20-
process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
21-
var arguments = ["npm", "run", "test"]
21+
guard let npmExecutable = which("npm"), let nodeExecutable = which("node") else {
22+
Issue.record("No \"npm\" command found in your system")
23+
return
24+
}
25+
process.executableURL = npmExecutable
26+
var environment = ProcessInfo.processInfo.environment
27+
environment["PATH"] =
28+
"\(nodeExecutable.deletingLastPathComponent().path)\(PATH_SEPARATOR) \(environment["PATH"] ?? "")"
29+
process.environment = environment
30+
var arguments = ["run", "test"]
2231
if ProcessInfo.processInfo.environment["UPDATE_SNAPSHOTS"] != nil {
2332
arguments.append(contentsOf: ["--", "--update"])
2433
}

0 commit comments

Comments
 (0)