Files
release-action/__tests__/Integration.test.ts

94 lines
3.7 KiB
TypeScript

import * as path from "node:path"
import * as github from "@actions/github"
import { beforeEach, describe, it, vi } from "vitest"
import { Action } from "../src/Action.js"
import { ReleaseActionSkipper } from "../src/ActionSkipper.js"
import { GithubArtifactDestroyer } from "../src/ArtifactDestroyer.js"
import { FileArtifactGlobber } from "../src/ArtifactGlobber.js"
import { GithubArtifactUploader } from "../src/ArtifactUploader.js"
import type { Inputs } from "../src/Inputs.js"
import type { Outputs } from "../src/Outputs.js"
import { GithubReleases, type ReleaseData } from "../src/Releases.js"
// This test is currently intended to be manually run during development. To run:
// - Make sure you have an environment variable named GITHUB_TOKEN assigned to your token
// - Remove skip from the test below
describe.skip("Integration Test", () => {
let action: Action
beforeEach(() => {
const token = getToken()
const git = github.getOctokit(token)
const inputs = getInputs()
const outputs = getOutputs()
const releases = new GithubReleases(inputs, git)
const uploader = new GithubArtifactUploader(releases, inputs.replacesArtifacts, inputs.artifactErrorsFailBuild)
const artifactDestroyer = new GithubArtifactDestroyer(releases)
const actionSkipper = new ReleaseActionSkipper(inputs.skipIfReleaseExists, releases, inputs.tag)
action = new Action(inputs, outputs, releases, uploader, artifactDestroyer, actionSkipper)
})
it("Performs action", async () => {
await action.perform()
})
function getInputs(): Inputs {
const MockInputs = vi.fn<() => Inputs>(() => {
return {
allowUpdates: true,
artifactErrorsFailBuild: false,
artifacts: artifacts(),
createdDraft: false,
createdReleaseBody: "This release was generated by release-action's integration test",
createdReleaseName: "Releases Action Integration Test",
commit: undefined,
discussionCategory: "Release",
generateReleaseNotes: true,
immutableCreate: true,
omitBodyDuringUpdate: false,
owner: "ncipollo",
createdPrerelease: false,
replacesArtifacts: true,
removeArtifacts: false,
repo: "actions-playground",
skipIfReleaseExists: false,
tag: "release-action-test",
token: getToken(),
updatedDraft: false,
updatedReleaseBody: "This release was updated by release-action's integration test",
updatedReleaseName: "Releases Action Integration Test",
updatedPrerelease: false,
updateOnlyUnreleased: false,
}
})
return MockInputs()
}
function getOutputs(): Outputs {
const MockOutputs = vi.fn<() => Outputs>(() => {
return {
applyReleaseData(releaseData: ReleaseData) {
console.log(`Release Data: ${releaseData}`)
},
applyAssetUrls(assetUrls: Record<string, string>) {
console.log(`Asset URLs: ${JSON.stringify(assetUrls)}`)
},
}
})
return MockOutputs()
}
function artifacts() {
const globber = new FileArtifactGlobber()
const artifactPath = path.join(__dirname, "Integration.test.ts")
const artifactString = `~/Desktop,~/Desktop/test.txt,blarg.tx, ${artifactPath}`
return globber.globArtifactString(artifactString, "raw", false)
}
function getToken(): string {
return process.env.GITHUB_TOKEN ?? ""
}
})