Buckets:
| // Copyright (c) 2026 the Zuke contributors | |
| // SPDX-License-Identifier: MIT | |
| /** | |
| * Integration coverage for `zuke setup`: drive the real `@zuke/cli` `main()` | |
| * against a real temporary directory (the production {@link defaultHost}, only | |
| * its logging captured) and assert the files that land on disk are a scaffold | |
| * whose advertised next step — `./zuke <target>` — can actually run. | |
| * | |
| * The regressions this pins. First: a scaffold has no `deno.lock` yet, and | |
| * `deno run --frozen` against a missing lockfile fails ("The lockfile is out of | |
| * date") instead of writing one, so an unconditional `--frozen` in the launcher | |
| * or the `deno.json` task breaks every project on its very first run. Second: | |
| * the build file and the `deno.json` beside it have to agree, so the `lint` | |
| * task setup writes passes on the file setup wrote — see | |
| * `tests/e2e/setup_lint_e2e.ts`, which runs the real linter over a scaffold. | |
| * | |
| * @module | |
| */ | |
| import { assertEquals } from "../../packages/core/tests/_assert.ts"; | |
| import { main } from "../../packages/cli/mod.ts"; | |
| import { defaultHost, type SetupHost } from "../../packages/cli/src/setup.ts"; | |
| /** Scaffold into a fresh temp directory and return its files plus the log. */ | |
| async function scaffold(): Promise<{ | |
| read: (name: string) => Promise<string>; | |
| log: string; | |
| code: number; | |
| }> { | |
| const dir = await Deno.makeTempDir({ prefix: "zuke-setup-" }); | |
| const lines: string[] = []; | |
| const host: SetupHost = { | |
| ...defaultHost, | |
| log: (message: string) => void lines.push(message), | |
| }; | |
| try { | |
| const code = await main( | |
| ["setup", "--yes", "--name", "Foo", "--dir", dir], | |
| host, | |
| ); | |
| const files = new Map<string, string>(); | |
| for await (const entry of Deno.readDir(dir)) { | |
| if (entry.isFile) { | |
| files.set(entry.name, await Deno.readTextFile(`${dir}/${entry.name}`)); | |
| } | |
| } | |
| return { | |
| read: (name: string) => { | |
| const text = files.get(name); | |
| if (text === undefined) throw new Error(`setup did not write ${name}`); | |
| return Promise.resolve(text); | |
| }, | |
| log: lines.join("\n"), | |
| code, | |
| }; | |
| } finally { | |
| await Deno.remove(dir, { recursive: true }); | |
| } | |
| } | |
| Deno.test("zuke setup scaffolds a project whose first run has no lockfile to freeze", async () => { | |
| const { read, log, code } = await scaffold(); | |
| assertEquals(code, 0); | |
| assertEquals(log.includes("Next: zuke"), true); | |
| // The bash launcher — the entry point setup tells the user to run — only | |
| // asks for --frozen when there is a lockfile to verify. | |
| const bash = await read("zuke"); | |
| assertEquals(bash.includes("if [ -f deno.lock ]; then"), true); | |
| assertEquals(bash.split("run -A --frozen").length - 1, 1); | |
| assertEquals(bash.split(`run -A zuke.ts "$@"`).length - 1, 1); | |
| // The PowerShell launcher agrees. | |
| const pwsh = await read("zuke.ps1"); | |
| assertEquals(pwsh.includes(`Test-Path (Join-Path $dir "deno.lock")`), true); | |
| assertEquals(pwsh.split(`$denoArgs += "--frozen"`).length - 1, 1); | |
| assertEquals(pwsh.includes(`@("run", "-A")`), true); | |
| // `deno task`'s shell has no conditionals, so the task cannot bootstrap a | |
| // lockfile — it must not demand one either. | |
| const denoJson: unknown = JSON.parse(await read("deno.json")); | |
| const tasks = | |
| denoJson !== null && typeof denoJson === "object" && "tasks" in denoJson | |
| ? denoJson.tasks | |
| : undefined; | |
| const zukeTask = | |
| tasks !== null && typeof tasks === "object" && "zuke" in tasks | |
| ? tasks.zuke | |
| : undefined; | |
| assertEquals(zukeTask, "deno run -A zuke.ts"); | |
| // The starter build imports by bare specifier and deno.json resolves it, so | |
| // `deno lint` — the lint task setup writes — passes on the scaffold's own | |
| // first file. An inline `jsr:` specifier trips Deno's default | |
| // `no-import-prefix` rule, which applies because setup configures no | |
| // lint.rules. | |
| const build = await read("zuke.ts"); | |
| assertEquals(build.includes('from "@zuke/core";'), true); | |
| assertEquals(/from "(jsr|npm|https):/.test(build), false); | |
| // The pin lives in the import map instead, so the lock the first run writes | |
| // is still meaningful for every run after it. | |
| const imports = | |
| denoJson !== null && typeof denoJson === "object" && "imports" in denoJson | |
| ? denoJson.imports | |
| : undefined; | |
| const core = | |
| imports !== null && typeof imports === "object" && "@zuke/core" in imports | |
| ? imports["@zuke/core"] | |
| : undefined; | |
| assertEquals(core, "jsr:@zuke/core@^1"); | |
| }); | |
| Deno.test("integration: setup exits 1 on a symlinked scaffold name, leaving it alone", async () => { | |
| if (Deno.build.os === "windows") return; // Deno.symlink needs privileges. | |
| const dir = await Deno.makeTempDir({ prefix: "zuke-setup-link-" }); | |
| const outside = await Deno.makeTempDir({ prefix: "zuke-setup-victim-" }); | |
| const victim = `${outside}/gitconfig`; | |
| try { | |
| await Deno.writeTextFile(victim, "[user]\n\tname = victim\n"); | |
| // What a hostile repository ships: a scaffold name that is really a link | |
| // pointing at one of the developer's own files. | |
| await Deno.symlink(victim, `${dir}/.gitignore`); | |
| const lines: string[] = []; | |
| const host: SetupHost = { | |
| ...defaultHost, | |
| log: (message: string) => void lines.push(message), | |
| }; | |
| const code = await main( | |
| ["setup", "--yes", "--name", "Foo", "--dir", dir], | |
| host, | |
| ); | |
| assertEquals(code, 1); | |
| // The developer's file is untouched, and the scaffold wrote nothing at all. | |
| assertEquals(await Deno.readTextFile(victim), "[user]\n\tname = victim\n"); | |
| const written: string[] = []; | |
| for await (const entry of Deno.readDir(dir)) written.push(entry.name); | |
| assertEquals(written, [".gitignore"]); // only the link the test planted | |
| } finally { | |
| await Deno.remove(dir, { recursive: true }); | |
| await Deno.remove(outside, { recursive: true }); | |
| } | |
| }); | |
| /** Run `zuke setup` in `dir` through the real main(), capturing its log. */ | |
| async function setupIn( | |
| dir: string, | |
| extra: string[] = [], | |
| ): Promise<{ code: number; log: string }> { | |
| const lines: string[] = []; | |
| const host: SetupHost = { | |
| ...defaultHost, | |
| log: (message: string) => void lines.push(message), | |
| }; | |
| const code = await main( | |
| ["setup", "--yes", "--name", "Foo", "--dir", dir, ...extra], | |
| host, | |
| ); | |
| return { code, log: lines.join("\n") }; | |
| } | |
| Deno.test("integration: setup exits 1 rather than claim success over a JSONC deno.json", async () => { | |
| // deno.json is JSONC — Deno accepts `//` comments that JSON.parse rejects. | |
| // The scaffolded build resolves @zuke/core through this file, so a skip here | |
| // leaves a build that cannot start; saying "Next: zuke" over that is worse | |
| // than saying plainly what is left to do. The file keeps its comments. | |
| const dir = await Deno.makeTempDir({ prefix: "zuke-setup-jsonc-" }); | |
| const jsonc = '{\n // cfg\n "tasks": { "dev": "echo hi" }\n}\n'; | |
| try { | |
| await Deno.writeTextFile(`${dir}/deno.json`, jsonc); | |
| const { code, log } = await setupIn(dir); | |
| assertEquals(code, 1); | |
| assertEquals(await Deno.readTextFile(`${dir}/deno.json`), jsonc); | |
| assertEquals(log.includes("Next: zuke"), false); | |
| assertEquals(log.includes("Incomplete —"), true); | |
| assertEquals(log.includes('"@zuke/core": "jsr:@zuke/core@^1"'), true); | |
| } finally { | |
| await Deno.remove(dir, { recursive: true }); | |
| } | |
| }); | |
| Deno.test("integration: setup keeps a delegated importMap working", async () => { | |
| // Deno ignores `importMap` as soon as `imports` appears beside it, so writing | |
| // one would silently disable the project's whole module resolution. Prove the | |
| // pre-existing project still resolves after setup has run over it. | |
| const dir = await Deno.makeTempDir({ prefix: "zuke-setup-import-map-" }); | |
| try { | |
| await Deno.writeTextFile( | |
| `${dir}/deno.json`, | |
| `${JSON.stringify({ importMap: "./import_map.json" }, null, 2)}\n`, | |
| ); | |
| await Deno.writeTextFile( | |
| `${dir}/import_map.json`, | |
| `${JSON.stringify({ imports: { "lib/": "./lib/" } }, null, 2)}\n`, | |
| ); | |
| await Deno.mkdir(`${dir}/lib`); | |
| await Deno.writeTextFile(`${dir}/lib/a.ts`, "export const x = 1;\n"); | |
| const { code, log } = await setupIn(dir); | |
| assertEquals(code, 1); | |
| assertEquals(log.includes("./import_map.json"), true); | |
| // The delegation is intact: no `imports` block was written beside it. | |
| const parsed: unknown = JSON.parse( | |
| await Deno.readTextFile(`${dir}/deno.json`), | |
| ); | |
| assertEquals( | |
| parsed !== null && typeof parsed === "object" && "imports" in parsed, | |
| false, | |
| ); | |
| assertEquals( | |
| parsed !== null && typeof parsed === "object" && "importMap" in parsed | |
| ? parsed.importMap | |
| : undefined, | |
| "./import_map.json", | |
| ); | |
| } finally { | |
| await Deno.remove(dir, { recursive: true }); | |
| } | |
| }); | |
Xet Storage Details
- Size:
- 8.84 kB
- Xet hash:
- e7a013075f756e5f757acaa97bbfc3d4a9cc401b787f55c9ac2f0e4e554de8a7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.