|
1 | 1 | import { existsSync } from "fs";
|
2 |
| -import { detectPackageManager } from "helpers/packageManagers"; |
| 2 | +import { |
| 3 | + detectPackageManager, |
| 4 | + detectPmMismatch, |
| 5 | +} from "helpers/packageManagers"; |
3 | 6 | import { beforeEach, describe, expect, test, vi } from "vitest";
|
4 | 7 | import whichPMRuns from "which-pm-runs";
|
5 | 8 | import { mockPackageManager } from "./mocks";
|
| 9 | +import type { C3Context } from "types"; |
6 | 10 |
|
7 | 11 | vi.mock("fs");
|
8 | 12 | vi.mock("which-pm-runs");
|
@@ -71,4 +75,66 @@ describe("Package Managers", () => {
|
71 | 75 | expect(pm.dlx).toEqual(["yarn"]);
|
72 | 76 | });
|
73 | 77 | });
|
| 78 | + |
| 79 | + describe("detectPmMismatch", async () => { |
| 80 | + describe("pnpm", () => { |
| 81 | + beforeEach(() => { |
| 82 | + mockPackageManager("pnpm"); |
| 83 | + }); |
| 84 | + |
| 85 | + test.each([ |
| 86 | + ["yarn.lock", true], |
| 87 | + ["pnpm-lock.yaml", false], |
| 88 | + ["bun.lock", true], |
| 89 | + ["bun.lockb", true], |
| 90 | + ])("with %s", (file, isMismatch) => { |
| 91 | + vi.mocked(existsSync).mockImplementationOnce( |
| 92 | + (path) => !!(path as string).includes(file), |
| 93 | + ); |
| 94 | + expect(detectPmMismatch({ project: { path: "" } } as C3Context)).toBe( |
| 95 | + isMismatch, |
| 96 | + ); |
| 97 | + }); |
| 98 | + }); |
| 99 | + |
| 100 | + describe("yarn", () => { |
| 101 | + beforeEach(() => { |
| 102 | + mockPackageManager("yarn"); |
| 103 | + }); |
| 104 | + |
| 105 | + test.each([ |
| 106 | + ["yarn.lock", false], |
| 107 | + ["pnpm-lock.yaml", true], |
| 108 | + ["bun.lock", true], |
| 109 | + ["bun.lockb", true], |
| 110 | + ])("with %s", (file, isMismatch) => { |
| 111 | + vi.mocked(existsSync).mockImplementationOnce( |
| 112 | + (path) => !!(path as string).includes(file), |
| 113 | + ); |
| 114 | + expect(detectPmMismatch({ project: { path: "" } } as C3Context)).toBe( |
| 115 | + isMismatch, |
| 116 | + ); |
| 117 | + }); |
| 118 | + }); |
| 119 | + |
| 120 | + describe("bun", () => { |
| 121 | + beforeEach(() => { |
| 122 | + mockPackageManager("bun"); |
| 123 | + }); |
| 124 | + |
| 125 | + test.each([ |
| 126 | + ["yarn.lock", true], |
| 127 | + ["pnpm-lock.yaml", true], |
| 128 | + ["bun.lock", false], |
| 129 | + ["bun.lockb", false], |
| 130 | + ])("with %s", (file, isMismatch) => { |
| 131 | + vi.mocked(existsSync).mockImplementationOnce( |
| 132 | + (path) => !!(path as string).includes(file), |
| 133 | + ); |
| 134 | + expect(detectPmMismatch({ project: { path: "" } } as C3Context)).toBe( |
| 135 | + isMismatch, |
| 136 | + ); |
| 137 | + }); |
| 138 | + }); |
| 139 | + }); |
74 | 140 | });
|
0 commit comments