53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import { spawnSync } from "node:child_process";
|
|
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
if (process.platform !== "darwin")
|
|
{
|
|
console.error("test:wkwebview requires macOS, Xcode, and an active GUI session.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const testDir = dirname(fileURLToPath(import.meta.url));
|
|
const projectRoot = resolve(testDir, "..");
|
|
const temporaryRoot = mkdtempSync(join(tmpdir(), "cjk-autospace-wkwebview-"));
|
|
const moduleCache = join(temporaryRoot, "ModuleCache");
|
|
const binary = join(temporaryRoot, "wkwebview-e2e");
|
|
mkdirSync(moduleCache);
|
|
|
|
function run(command, args)
|
|
{
|
|
const result = spawnSync(command, args, {
|
|
cwd: projectRoot,
|
|
encoding: "utf8",
|
|
stdio: "inherit",
|
|
});
|
|
if (result.error) { throw result.error; }
|
|
if (result.status !== 0) { process.exitCode = result.status ?? 1; }
|
|
return result.status === 0;
|
|
}
|
|
|
|
try
|
|
{
|
|
const compiled = run("xcrun", [
|
|
"swiftc",
|
|
"-parse-as-library",
|
|
"-swift-version", "5",
|
|
"-module-cache-path", moduleCache,
|
|
"-framework", "AppKit",
|
|
"-framework", "WebKit",
|
|
join(testDir, "wkwebview-e2e.swift"),
|
|
"-o", binary,
|
|
]);
|
|
if (compiled)
|
|
{
|
|
run(binary, [ join(projectRoot, "demo/e2e.html"), projectRoot ]);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
rmSync(temporaryRoot, { recursive: true, force: true });
|
|
}
|