Files
bun.sh/test/cli/init/init.test.ts
2023-11-13 22:25:13 -08:00

38 lines
1.2 KiB
TypeScript

import fs from "fs";
import path from "path";
import os from "os";
import { bunExe, bunEnv } from "harness";
test("bun init works", () => {
const temp = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "bun-init-X")));
Bun.spawnSync({
cmd: [bunExe(), "init", "-y"],
cwd: temp,
stdio: ["ignore", "inherit", "inherit"],
env: bunEnv,
});
const pkg = JSON.parse(fs.readFileSync(path.join(temp, "package.json"), "utf8"));
expect(pkg).toEqual({
"name": path.basename(temp).toLowerCase(),
"module": "index.ts",
"type": "module",
"devDependencies": {
"bun-types": "latest",
},
"peerDependencies": {
"typescript": "^5.0.0",
},
});
const readme = fs.readFileSync(path.join(temp, "README.md"), "utf8");
expect(readme).toStartWith("# " + path.basename(temp).toLowerCase() + "\n");
expect(readme).toInclude("v" + Bun.version.replaceAll("-debug", ""));
expect(readme).toInclude("index.ts");
expect(fs.existsSync(path.join(temp, "index.ts"))).toBe(true);
expect(fs.existsSync(path.join(temp, ".gitignore"))).toBe(true);
expect(fs.existsSync(path.join(temp, "node_modules"))).toBe(true);
expect(fs.existsSync(path.join(temp, "tsconfig.json"))).toBe(true);
}, 30_000);