2026-05-05 14:46:18 +02:00
|
|
|
import { execFileSync } from "node:child_process";
|
|
|
|
|
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
|
|
|
import { tmpdir } from "node:os";
|
|
|
|
|
import { join } from "node:path";
|
2026-03-18 00:40:06 -06:00
|
|
|
|
2026-05-05 16:31:53 +02:00
|
|
|
// Skip in non-TTY environments — init enters the interactive setup flow.
|
|
|
|
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
|
|
|
console.log(" SKIP test-init (no TTY)");
|
2026-05-05 14:31:16 +02:00
|
|
|
process.exit(0);
|
2026-03-18 09:44:42 -06:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 18:33:47 +02:00
|
|
|
const tmpDir = mkdtempSync(join(tmpdir(), "sf-smoke-init-"));
|
2026-03-18 00:40:06 -06:00
|
|
|
|
|
|
|
|
try {
|
2026-05-05 16:31:53 +02:00
|
|
|
const defaultBinary = process.execPath;
|
|
|
|
|
const defaultArgs = [
|
|
|
|
|
join(import.meta.dirname, "..", "..", "dist", "loader.js"),
|
|
|
|
|
];
|
|
|
|
|
const binary = process.env.SF_SMOKE_BINARY || defaultBinary;
|
|
|
|
|
const args = process.env.SF_SMOKE_BINARY
|
|
|
|
|
? ["init"]
|
|
|
|
|
: [...defaultArgs, "init"];
|
2026-03-18 00:40:06 -06:00
|
|
|
|
2026-05-05 14:31:16 +02:00
|
|
|
execFileSync(binary, args, {
|
|
|
|
|
encoding: "utf8",
|
|
|
|
|
timeout: 30_000,
|
|
|
|
|
cwd: tmpDir,
|
|
|
|
|
env: { ...process.env, SF_NON_INTERACTIVE: "1" },
|
|
|
|
|
});
|
2026-03-18 00:40:06 -06:00
|
|
|
|
2026-05-05 14:31:16 +02:00
|
|
|
const sfDir = join(tmpDir, ".sf");
|
|
|
|
|
if (!existsSync(sfDir)) {
|
|
|
|
|
console.error(`.sf directory not created in ${tmpDir}`);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
2026-03-18 00:40:06 -06:00
|
|
|
} finally {
|
2026-05-05 14:31:16 +02:00
|
|
|
rmSync(tmpDir, { recursive: true, force: true });
|
2026-03-18 00:40:06 -06:00
|
|
|
}
|