Skip to content

Commit

Permalink
Merge pull request #359 from MHekert/tests/getPackageVersion
Browse files Browse the repository at this point in the history
added getPackageVersion tests
  • Loading branch information
orta committed Sep 28, 2022
2 parents 639b9c8 + 4861e88 commit 745757d
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/getPackageVersion.test.ts
@@ -0,0 +1,87 @@
import { getPackageVersion } from "./getPackageVersion"

describe("getPackageVersion", () => {
beforeEach(() => {
jest.resetModules()
})

const packagePath = "../package.json"

it("should return version without change when already valid", () => {
const packageJSON = {
version: "1.2.3",
}
jest.mock(packagePath, () => {
return packageJSON
})

const expected = "1.2.3"

expect(getPackageVersion(packagePath)).toEqual(expected)
})

it("should return version with prefix", () => {
const packageJSON = {
version: "v1.2.3",
}
jest.mock(packagePath, () => {
return packageJSON
})

const expected = "v1.2.3"

expect(getPackageVersion(packagePath)).toEqual(expected)
})

it("should return invalid version without change", () => {
const packageJSON = {
version: "a.b.c",
}
jest.mock(packagePath, () => {
return packageJSON
})

const expected = "a.b.c"

expect(getPackageVersion(packagePath)).toEqual(expected)
})

it("should return invalid version without build metadata", () => {
const packageJSON = {
version: "a.b.c+asd1234",
}
jest.mock(packagePath, () => {
return packageJSON
})

const expected = "a.b.c"

expect(getPackageVersion(packagePath)).toEqual(expected)
})

it("should return version without build metadata", () => {
const packageJSON = {
version: "1.2.3+asd1234",
}
jest.mock(packagePath, () => {
return packageJSON
})

const expected = "1.2.3"

expect(getPackageVersion(packagePath)).toEqual(expected)
})

it("should return version with prefix but without build metadata", () => {
const packageJSON = {
version: "v1.2.3+asd1234",
}
jest.mock(packagePath, () => {
return packageJSON
})

const expected = "v1.2.3"

expect(getPackageVersion(packagePath)).toEqual(expected)
})
})

0 comments on commit 745757d

Please sign in to comment.