Skip to content

Commit

Permalink
Add biome and initial format rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ncipollo committed Feb 17, 2025
1 parent 33bf18d commit 17b5598
Show file tree
Hide file tree
Showing 37 changed files with 3,111 additions and 976 deletions.
6 changes: 6 additions & 0 deletions .idea/biome.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 70 additions & 77 deletions __tests__/Action.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Action} from "../src/Action";
import {Artifact} from "../src/Artifact";
import {Inputs} from "../src/Inputs";
import {Releases} from "../src/Releases";
import {ArtifactUploader} from "../src/ArtifactUploader";
import {Outputs} from "../src/Outputs";
import {ArtifactDestroyer} from "../src/ArtifactDestroyer";
import {ActionSkipper} from "../src/ActionSkipper";
import { Action } from "../src/Action"
import { Artifact } from "../src/Artifact"
import { Inputs } from "../src/Inputs"
import { Releases } from "../src/Releases"
import { ArtifactUploader } from "../src/ArtifactUploader"
import { Outputs } from "../src/Outputs"
import { ArtifactDestroyer } from "../src/ArtifactDestroyer"
import { ActionSkipper } from "../src/ActionSkipper"

const applyReleaseDataMock = jest.fn()
const artifactDestroyMock = jest.fn()
Expand All @@ -18,30 +18,27 @@ const shouldSkipMock = jest.fn()
const updateMock = jest.fn()
const uploadMock = jest.fn()

const artifacts = [
new Artifact('a/art1'),
new Artifact('b/art2')
]
const artifacts = [new Artifact("a/art1"), new Artifact("b/art2")]

const createBody = 'createBody'
const createBody = "createBody"
const createDraft = true
const createName = 'createName'
const commit = 'commit'
const discussionCategory = 'discussionCategory'
const createName = "createName"
const commit = "commit"
const discussionCategory = "discussionCategory"
const generateReleaseNotes = true
const id = 100
const createPrerelease = true
const releaseId = 101
const replacesArtifacts = true
const tag = 'tag'
const token = 'token'
const updateBody = 'updateBody'
const tag = "tag"
const token = "token"
const updateBody = "updateBody"
const updateDraft = false
const updateName = 'updateName'
const updateName = "updateName"
const updatePrerelease = false
const updateOnlyUnreleased = false
const url = 'http://api.example.com'
const makeLatest = 'legacy'
const url = "http://api.example.com"
const makeLatest = "legacy"

describe("Action", () => {
beforeEach(() => {
Expand All @@ -53,27 +50,29 @@ describe("Action", () => {
uploadMock.mockClear()
})

it('creates release but does not upload if no artifact', async () => {
it("creates release but does not upload if no artifact", async () => {
const action = createAction(false, false)

await action.perform()

expect(createMock).toBeCalledWith(tag,
expect(createMock).toBeCalledWith(
tag,
createBody,
commit,
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease)
createPrerelease
)
expect(uploadMock).not.toBeCalled()
assertOutputApplied()
})

it('creates release if no release exists to update', async () => {
it("creates release if no release exists to update", async () => {
const action = createAction(true, true)
const error = {status: 404}
const error = { status: 404 }
getMock.mockRejectedValue(error)

await action.perform()
Expand All @@ -87,19 +86,18 @@ describe("Action", () => {
generateReleaseNotes,
makeLatest,
createName,
createPrerelease)
createPrerelease
)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
assertOutputApplied()
})

it('creates release if no draft releases', async () => {
it("creates release if no draft releases", async () => {
const action = createAction(true, true)
const error = {status: 404}
const error = { status: 404 }
getMock.mockRejectedValue(error)
listMock.mockResolvedValue({
data: [
{id: id, draft: false, tag_name: tag}
]
data: [{ id: id, draft: false, tag_name: tag }],
})

await action.perform()
Expand All @@ -117,10 +115,9 @@ describe("Action", () => {
)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
assertOutputApplied()

})

it('creates release then uploads artifact', async () => {
it("creates release then uploads artifact", async () => {
const action = createAction(false, true)

await action.perform()
Expand All @@ -140,7 +137,7 @@ describe("Action", () => {
assertOutputApplied()
})

it('removes all artifacts when artifact destroyer is enabled', async () => {
it("removes all artifacts when artifact destroyer is enabled", async () => {
const action = createAction(false, true, true)

await action.perform()
Expand All @@ -149,7 +146,7 @@ describe("Action", () => {
assertOutputApplied()
})

it('removes no artifacts when artifact destroyer is disabled', async () => {
it("removes no artifacts when artifact destroyer is disabled", async () => {
const action = createAction(false, true)

await action.perform()
Expand All @@ -158,7 +155,7 @@ describe("Action", () => {
assertOutputApplied()
})

it('skips action', async () => {
it("skips action", async () => {
const action = createAction(false, false, false)
shouldSkipMock.mockResolvedValue(true)

Expand All @@ -168,7 +165,7 @@ describe("Action", () => {
expect(updateMock).not.toBeCalled()
})

it('throws error when create fails', async () => {
it("throws error when create fails", async () => {
const action = createAction(false, true)
createMock.mockRejectedValue("error")

Expand All @@ -193,14 +190,14 @@ describe("Action", () => {
expect(uploadMock).not.toBeCalled()
})

it('throws error when get fails', async () => {
it("throws error when get fails", async () => {
const action = createAction(true, true)
const error = {
errors: [
{
code: 'already_exists'
}
]
code: "already_exists",
},
],
}

createMock.mockRejectedValue(error)
Expand All @@ -215,19 +212,17 @@ describe("Action", () => {
expect(getMock).toBeCalledWith(tag)
expect(updateMock).not.toBeCalled()
expect(uploadMock).not.toBeCalled()

})

it('throws error when list has no data', async () => {

it("throws error when list has no data", async () => {
const action = createAction(true, true)
getMock.mockRejectedValue({status: 404})
getMock.mockRejectedValue({ status: 404 })
const error = {
errors: [
{
code: 'already_exists'
}
]
code: "already_exists",
},
],
}

createMock.mockRejectedValue(error)
Expand All @@ -244,7 +239,7 @@ describe("Action", () => {
expect(updateMock).not.toBeCalled()
})

it('throws error when update fails', async () => {
it("throws error when update fails", async () => {
const action = createAction(true, true)

updateMock.mockRejectedValue("error")
Expand All @@ -270,9 +265,9 @@ describe("Action", () => {
expect(uploadMock).not.toBeCalled()
})

it('throws error when upload fails', async () => {
it("throws error when upload fails", async () => {
const action = createAction(false, true)
const expectedError = {status: 404}
const expectedError = { status: 404 }
uploadMock.mockRejectedValue(expectedError)

expect.hasAssertions()
Expand All @@ -296,15 +291,15 @@ describe("Action", () => {
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
})

it('updates draft release', async () => {
it("updates draft release", async () => {
const action = createAction(true, true)
const error = {status: 404}
const error = { status: 404 }
getMock.mockRejectedValue(error)
listMock.mockResolvedValue({
data: [
{id: 123, draft: false, tag_name: tag},
{id: id, draft: true, tag_name: tag}
]
{ id: 123, draft: false, tag_name: tag },
{ id: id, draft: true, tag_name: tag },
],
})

await action.perform()
Expand All @@ -324,7 +319,7 @@ describe("Action", () => {
assertOutputApplied()
})

it('updates release but does not upload if no artifact', async () => {
it("updates release but does not upload if no artifact", async () => {
const action = createAction(true, false)

await action.perform()
Expand All @@ -344,7 +339,7 @@ describe("Action", () => {
assertOutputApplied()
})

it('updates release then uploads artifact', async () => {
it("updates release then uploads artifact", async () => {
const action = createAction(true, true)

await action.perform()
Expand All @@ -365,12 +360,10 @@ describe("Action", () => {
})

function assertOutputApplied() {
expect(applyReleaseDataMock).toBeCalledWith({id: releaseId, upload_url: url})
expect(applyReleaseDataMock).toBeCalledWith({ id: releaseId, upload_url: url })
}

function createAction(allowUpdates: boolean,
hasArtifact: boolean,
removeArtifacts: boolean = false): Action {
function createAction(allowUpdates: boolean, hasArtifact: boolean, removeArtifacts: boolean = false): Action {
let inputArtifact: Artifact[]
if (hasArtifact) {
inputArtifact = artifacts
Expand All @@ -385,30 +378,30 @@ describe("Action", () => {
listArtifactsForRelease: listArtifactsMock,
listReleases: listMock,
update: updateMock,
uploadArtifact: jest.fn()
uploadArtifact: jest.fn(),
}
})

createMock.mockResolvedValue({
data: {
id: releaseId,
upload_url: url
}
upload_url: url,
},
})
getMock.mockResolvedValue({
data: {
id: id
}
id: id,
},
})
listMock.mockResolvedValue({
data: []
data: [],
})
shouldSkipMock.mockResolvedValue(false)
updateMock.mockResolvedValue({
data: {
id: releaseId,
upload_url: url
}
upload_url: url,
},
})
uploadMock.mockResolvedValue({})

Expand Down Expand Up @@ -436,28 +429,28 @@ describe("Action", () => {
updatedReleaseBody: updateBody,
updatedReleaseName: updateName,
updatedPrerelease: updatePrerelease,
updateOnlyUnreleased: updateOnlyUnreleased
updateOnlyUnreleased: updateOnlyUnreleased,
}
})
const MockOutputs = jest.fn<Outputs, any>(() => {
return {
applyReleaseData: applyReleaseDataMock
applyReleaseData: applyReleaseDataMock,
}
})
const MockUploader = jest.fn<ArtifactUploader, any>(() => {
return {
uploadArtifacts: uploadMock
uploadArtifacts: uploadMock,
}
})
const MockArtifactDestroyer = jest.fn<ArtifactDestroyer, any>(() => {
return {
destroyArtifacts: artifactDestroyMock
destroyArtifacts: artifactDestroyMock,
}
})

const MockActionSkipper = jest.fn<ActionSkipper, any>(() => {
return {
shouldSkip: shouldSkipMock
shouldSkip: shouldSkipMock,
}
})

Expand Down
Loading

0 comments on commit 17b5598

Please sign in to comment.