Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion tests/package-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ function readPackageManifest(): PackageManifest {
return JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as PackageManifest;
}

function assertPatchedEsbuildLockEntries(lock: PackageLock): void {
const esbuildEntries = Object.entries(lock.packages ?? {}).filter(([packagePath]) =>
packagePath.endsWith("node_modules/esbuild")
);

expect(esbuildEntries).not.toHaveLength(0);
for (const [packagePath, packageEntry] of esbuildEntries) {
expect(packageEntry["version"], `${packagePath} must resolve to the patched esbuild release`).toBe("0.28.1");
}
}

async function prepareLockedConsumer(directory: string, tarballPath: string): Promise<void> {
const manifest = readPackageManifest();
if (!manifest.name) throw new Error("Package manifest is missing a name.");
Expand Down Expand Up @@ -482,7 +493,18 @@ describe("package metadata contract", () => {
const lock = JSON.parse(readFileSync(new URL("../package-lock.json", import.meta.url), "utf8")) as PackageLock;

expect(manifest.overrides?.esbuild).toBe("0.28.1");
expect(lock.packages?.["node_modules/esbuild"]?.["version"]).toBe("0.28.1");
assertPatchedEsbuildLockEntries(lock);
});

it("rejects stale nested esbuild lock entries", () => {
const lock: PackageLock = {
packages: {
"node_modules/esbuild": { version: "0.28.1" },
"node_modules/vite/node_modules/esbuild": { version: "0.27.0" }
}
};

expect(() => assertPatchedEsbuildLockEntries(lock)).toThrow(/node_modules\/vite\/node_modules\/esbuild/);
});
});

Expand Down