1
0
mirror of synced 2026-02-03 09:01:02 -05:00
Files
blitz/packages/codemod/tests/codemod.unit.test.ts
github-actions[bot] 4494662d6d Version Packages (#4353)
* Version Packages

* make the version 2.1.0

* Update integration-tests/no-suspense/package.json

* pnpm lock fix

* use latest pnpm version

* Revert "use latest pnpm version"

This reverts commit 5fab234a4a.

* Revert "pnpm lock fix"

This reverts commit 690a467cf7.

* Revert "make the version 2.1.0"

This reverts commit 922e95156f.

* make the version 2.1.0

* pnpm lock fix

* fix

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Siddharth Suresh <siddh.suresh@gmail.com>
2024-08-14 19:27:52 +05:30

91 lines
2.3 KiB
TypeScript

import {describe, it, expect, vi, afterAll} from "vitest"
import {replaceBlitzPkgsVersions} from "../src/utils"
describe("replaceBlitzPkgsVersions", () => {
afterAll(() => {
vi.clearAllMocks()
})
vi.mock("@blitzjs/generator", async () => {
return {
fetchDistTags: vi.fn((pkg: string) => {
if (pkg === "blitz") {
return {alpha: "1.0.0", beta: "2.0.0", danger: "2.1.0"}
}
if (pkg === "zod") {
return {latest: "1.2.3"}
}
}),
}
})
const pkgJson = {
dependencies: {},
}
it("correctly updates versions with the alpha tag", async () => {
expect(await replaceBlitzPkgsVersions(pkgJson, "alpha")).toEqual({
dependencies: {
blitz: "1.0.0",
"@blitzjs/rpc": "1.0.0",
"@blitzjs/auth": "1.0.0",
"@blitzjs/next": "1.0.0",
next: "12.2.0",
zod: "1.2.3",
},
})
})
it("correctly updates versions with the beta tag", async () => {
expect(await replaceBlitzPkgsVersions(pkgJson, "beta")).toEqual({
dependencies: {
blitz: "2.0.0",
"@blitzjs/rpc": "2.0.0",
"@blitzjs/auth": "2.0.0",
"@blitzjs/next": "2.0.0",
next: "12.2.0",
zod: "1.2.3",
},
})
})
it("correctly updates versions with the danger tag", async () => {
expect(await replaceBlitzPkgsVersions(pkgJson, "danger")).toEqual({
dependencies: {
blitz: "2.1.0",
"@blitzjs/rpc": "2.1.0",
"@blitzjs/auth": "2.1.0",
"@blitzjs/next": "2.1.0",
next: "12.2.0",
zod: "1.2.3",
},
})
})
it("sets version as a provided tag if it wasn't found with fetchDistTag function", async () => {
expect(await replaceBlitzPkgsVersions(pkgJson, "custom")).toEqual({
dependencies: {
blitz: "custom",
"@blitzjs/rpc": "custom",
"@blitzjs/auth": "custom",
"@blitzjs/next": "custom",
next: "12.2.0",
zod: "1.2.3",
},
})
})
it("handles package.json without dependecies key", async () => {
expect(await replaceBlitzPkgsVersions({}, "custom")).toEqual({
dependencies: {
blitz: "custom",
"@blitzjs/rpc": "custom",
"@blitzjs/auth": "custom",
"@blitzjs/next": "custom",
next: "12.2.0",
zod: "1.2.3",
},
})
})
})