|
| 1 | +import * as assert from "assert/strict"; |
| 2 | +import * as fs from "fs"; |
| 3 | +import * as path from "node:path"; |
| 4 | +import { runInTempDir } from "./test_utils"; |
| 5 | +import { findProjectDir } from "../src/utils"; |
| 6 | + |
| 7 | +describe("findProjectDir", () => { |
| 8 | + it("should return npm if package-lock.json is found", async () => { |
| 9 | + await runInTempDir(async (tempDir) => { |
| 10 | + await fs.promises.writeFile( |
| 11 | + path.join(tempDir, "package-lock.json"), |
| 12 | + "{}", |
| 13 | + "utf-8", |
| 14 | + ); |
| 15 | + const result = await findProjectDir(tempDir); |
| 16 | + assert.strictEqual(result.pkgManagerName, "npm"); |
| 17 | + }); |
| 18 | + }); |
| 19 | + it("should return yarn if yarn.lock is found", async () => { |
| 20 | + await runInTempDir(async (tempDir) => { |
| 21 | + await fs.promises.writeFile(path.join(tempDir, "yarn.lock"), "", "utf-8"); |
| 22 | + const result = await findProjectDir(tempDir); |
| 23 | + assert.strictEqual(result.pkgManagerName, "yarn"); |
| 24 | + }); |
| 25 | + }); |
| 26 | + it("should return pnpm if pnpm-lock.yaml is found", async () => { |
| 27 | + await runInTempDir(async (tempDir) => { |
| 28 | + await fs.promises.writeFile( |
| 29 | + path.join(tempDir, "pnpm-lock.yaml"), |
| 30 | + "", |
| 31 | + "utf-8", |
| 32 | + ); |
| 33 | + const result = await findProjectDir(tempDir); |
| 34 | + assert.strictEqual(result.pkgManagerName, "pnpm"); |
| 35 | + }); |
| 36 | + }); |
| 37 | + it("should return bun if bun.lockb is found", async () => { |
| 38 | + await runInTempDir(async (tempDir) => { |
| 39 | + await fs.promises.writeFile(path.join(tempDir, "bun.lockb"), "", "utf-8"); |
| 40 | + const result = await findProjectDir(tempDir); |
| 41 | + assert.strictEqual(result.pkgManagerName, "bun"); |
| 42 | + }); |
| 43 | + }); |
| 44 | + it("should return bun if bun.lockb and yarn.lock are found", async () => { |
| 45 | + // bun allow to save bun.lockb and yarn.lock |
| 46 | + // https://bun.sh/docs/install/lockfile |
| 47 | + await runInTempDir(async (tempDir) => { |
| 48 | + await fs.promises.writeFile(path.join(tempDir, "bun.lockb"), "", "utf-8"); |
| 49 | + await fs.promises.writeFile(path.join(tempDir, "yarn.lock"), "", "utf-8"); |
| 50 | + const result = await findProjectDir(tempDir); |
| 51 | + assert.strictEqual(result.pkgManagerName, "bun"); |
| 52 | + }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments