Skip to content

Commit

Permalink
added getPackageVersion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MHekert committed Nov 18, 2021
1 parent 5c2c92b commit 4861e88
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/getPackageVersion.test.ts
Original file line number Diff line number Diff line change
@@ -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 4861e88

Please sign in to comment.