Files
coder/site/e2e/setup/preflight.ts
T
ケイラ 5f4ff58f84 fix: use pre-built binary instead of go run in e2e tests (#16236)
Using `go run` inside of a test is fragile, because it means we have to
wait for `go` to compile the binary while also constrained on resources
by the fact that Playwright and coderd are already running. We should
instead compile a coder binary for the current platform before the tests
and use it directly.
2025-01-23 09:45:50 -07:00

46 lines
1.1 KiB
TypeScript

import { execSync } from "node:child_process";
import * as path from "node:path";
export default function () {
// If running terraform tests, verify the requirements exist in the
// environment.
//
// These execs will throw an error if the status code is non-zero.
// So if both these work, then we can launch terraform provisioners.
let hasTerraform = false;
let hasDocker = false;
try {
execSync("terraform --version");
hasTerraform = true;
} catch {
/* empty */
}
try {
execSync("docker --version");
hasDocker = true;
} catch {
/* empty */
}
if (!hasTerraform || !hasDocker) {
const msg = `Terraform provisioners require docker & terraform binaries to function. \n${
hasTerraform
? ""
: "\tThe `terraform` executable is not present in the runtime environment.\n"
}${
hasDocker
? ""
: "\tThe `docker` executable is not present in the runtime environment.\n"
}`;
throw new Error(msg);
}
if (!process.env.CI) {
console.info("==> make site/e2e/bin/coder");
execSync("make site/e2e/bin/coder", {
cwd: path.join(__dirname, "../../../"),
});
}
}