Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
431 changes: 366 additions & 65 deletions __snapshots__/deploy.test.ts.snap

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"@david/service-store": "jsr:@david/service-store@^0.3.0",
"@david/dax": "jsr:@david/dax@^0.45.0",
"@levibostian/cathy": "jsr:@levibostian/cathy@^2.0.1",
"@levibostian/sh-style": "jsr:@levibostian/sh-style@^0.9.0",
"@std/cli": "jsr:@std/cli@^1.0.20",
"@std/path": "jsr:@std/path@^1.1.4",
"@std/semver": "jsr:@std/semver@^1.0.4",
"@std/testing": "jsr:@std/testing@^1.0.10",
"@std/assert": "jsr:@std/assert@^1.0.12",
"ansi-styles": "npm:ansi-styles@6.2.3",
"cathy": "npm:cathy@^1.4.0",
"env-ci": "npm:env-ci@^11.2.0",
"shell-quote": "npm:shell-quote@^1.8.2",
"globrex": "npm:globrex@^0.1.2",
Expand All @@ -22,8 +23,8 @@
"run-coverage": "deno coverage reports/coverage/ --include=$(pwd) && deno coverage reports/coverage/ --include=$(pwd) --lcov --output=reports/coverage.lcov",
// main test task that runs *all* tests and coverage commands.
"test": "deno task test-deploy-scripts && deno task run-tests && deno task run-coverage",
"test-update": "deno task test-only -- --update",
"compile": "deno compile --output $OUTPUT_FILE_NAME --allow-env --allow-net=api.github.com --allow-run --allow-read --allow-write=/tmp,/var/folders,/home/runner/work/_temp --target $DENO_TARGET index.ts",
"test-update": "deno task test -- --update",
"compile": "deno compile --output $OUTPUT_FILE_NAME --allow-env --allow-net=api.github.com --allow-run --allow-read --allow-write --target $DENO_TARGET index.ts",
"compile-all": "OUTPUT_FILE_NAME=dist/bin-x86_64-Linux DENO_TARGET=x86_64-unknown-linux-gnu deno task compile && OUTPUT_FILE_NAME=dist/bin-aarch64-Linux DENO_TARGET=aarch64-unknown-linux-gnu deno task compile && OUTPUT_FILE_NAME=dist/bin-x86_64-Darwin DENO_TARGET=x86_64-apple-darwin deno task compile && OUTPUT_FILE_NAME=dist/bin-aarch64-Darwin DENO_TARGET=aarch64-apple-darwin deno task compile",
"format": "deno fmt",
"lint": "deno fmt && deno lint --fix"
Expand Down
56 changes: 39 additions & 17 deletions deno.lock

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

39 changes: 25 additions & 14 deletions deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { restore, stub } from "@std/testing/mock"
import { assertSnapshot } from "@std/testing/snapshot"
import { run } from "./deploy.ts"
import { GetCommitsSinceLatestReleaseStep } from "./lib/steps/get-commits-since-latest-release.ts"
import { getLogMock } from "./lib/log.test.ts"
import { Environment } from "./lib/environment.ts"
import { PrepareTestModeEnvStep } from "./lib/steps/prepare-testmode-env.ts"
import { mock, when } from "./lib/mock/mock.ts"
Expand All @@ -15,6 +14,7 @@ import { ConvenienceStep } from "./lib/steps/convenience.ts"
import { GitCommit } from "./lib/types/git.ts"
import { GitCommitFake } from "./lib/types/git.test.ts"
import { Git } from "./lib/git.ts"
import { Logger } from "./lib/log.ts"

describe("run the tool in different scenarios", () => {
afterEach(() => {
Expand Down Expand Up @@ -264,20 +264,20 @@ describe("test github actions output", () => {

describe("user facing logs", () => {
it("given no commits will trigger a release, expect logs to easily communicate that to the user", async (t) => {
const { logMock } = await setupTestEnvironmentAndRun({
const { logger } = await setupTestEnvironmentAndRun({
commitsSinceLatestRelease: [new GitCommitFake()],
nextReleaseVersion: undefined,
})

await assertSnapshot(t, logMock.getLogs({ includeDebugLogs: false }))
await assertSnapshot(t, logger.lines.join("\n"))
})

it("given no commits created since last deployment, expect logs to easily communicate that to the user", async (t) => {
const { logMock } = await setupTestEnvironmentAndRun({
const { logger } = await setupTestEnvironmentAndRun({
commitsSinceLatestRelease: [],
})

await assertSnapshot(t, logMock.getLogs({ includeDebugLogs: false }))
await assertSnapshot(t, logger.lines.join("\n"))
})

it("given no release has ever been made, expect logs to easily communicate that to the user", async (t) => {
Expand All @@ -286,13 +286,13 @@ describe("user facing logs", () => {
sha: "trigger-release",
})

const { logMock } = await setupTestEnvironmentAndRun({
const { logger } = await setupTestEnvironmentAndRun({
latestRelease: null,
commitsSinceLatestRelease: [givenLatestCommitOnBranch],
nextReleaseVersion: "1.0.0",
})

await assertSnapshot(t, logMock.getLogs({ includeDebugLogs: false }))
await assertSnapshot(t, logger.lines.join("\n"))
})

it("given running in test mode, given commits that trigger a release, expect logs to easily communicate that to the user", async (t) => {
Expand All @@ -304,15 +304,19 @@ describe("user facing logs", () => {
sha: "trigger-release",
})

const { logMock } = await setupTestEnvironmentAndRun({
const { logger } = await setupTestEnvironmentAndRun({
pullRequestTargetBranchName: givenTargetBranch,
currentBranchName: givenBaseBranch,
githubActionEventThatTriggeredTool: "pull_request",
commitsSinceLatestRelease: [givenLatestCommitOnBranch],
nextReleaseVersion: "1.0.0",
pullRequestsMerged: [{ pullRequestTitle: "Add sweet feature", pullRequestNumber: 123 }, {
pullRequestTitle: "Update main branch",
pullRequestNumber: 124,
}],
})

await assertSnapshot(t, logMock.getLogs({ includeDebugLogs: false }))
await assertSnapshot(t, logger.lines.join("\n"))
})
})

Expand Down Expand Up @@ -434,6 +438,7 @@ const setupTestEnvironmentAndRun = async ({
pullRequestTargetBranchName,
currentBranchName,
commitsCreatedBySimulatedMerge,
pullRequestsMerged,
gitCommitsCurrentBranch,
simulatedMergeType,
}: {
Expand All @@ -445,9 +450,13 @@ const setupTestEnvironmentAndRun = async ({
pullRequestTargetBranchName?: string
currentBranchName?: string
commitsCreatedBySimulatedMerge?: GitCommit[]
pullRequestsMerged?: { pullRequestTitle: string; pullRequestNumber: number }[]
gitCommitsCurrentBranch?: GitCommit[]
simulatedMergeType?: "merge" | "rebase" | "squash"
}) => {
const logger = new Logger()
logger.init() // must call init so we record the lines logged.

// Set some defaults.
const pullRequestTargetBranch = pullRequestTargetBranchName || "main" // assume we are running a pull_request event that merges into main
const currentBranch = currentBranchName || "main" // assume we are running a push event
Expand Down Expand Up @@ -502,8 +511,6 @@ const setupTestEnvironmentAndRun = async ({
return
})

const logMock = getLogMock()

const environment = {} as Environment
const setOutputMock = stub(
environment,
Expand Down Expand Up @@ -560,7 +567,11 @@ const setupTestEnvironmentAndRun = async ({
const prepareEnvironmentForTestModeMock = when(prepareEnvironmentForTestMode, "prepareEnvironmentForTestMode", async () => {
if (!isRunningInPullRequest) return undefined

return { currentGitBranch: pullRequestTargetBranch, commitsCreatedDuringSimulatedMerges: commitsCreatedBySimulatedMerge || [] }
return {
currentGitBranch: pullRequestTargetBranch,
commitsCreatedDuringSimulatedMerges: commitsCreatedBySimulatedMerge || [],
pullRequestsMerged: pullRequestsMerged || [],
}
})

const gitMock = mock<Git>()
Expand All @@ -570,7 +581,7 @@ const setupTestEnvironmentAndRun = async ({
stepRunner,
prepareEnvironmentForTestMode,
getCommitsSinceLatestReleaseStep,
log: logMock,
log: logger,
git: gitMock,
environment,
simulatedMergeType: simulatedMergeType || "merge",
Expand All @@ -581,7 +592,7 @@ const setupTestEnvironmentAndRun = async ({
getCommitsSinceLatestReleaseStepMock,
determineNextReleaseVersionStepMock,
deployStepMock,
logMock,
logger,
setOutputMock,
environmentIsRunningInPullRequestMock,
prepareEnvironmentForTestModeMock,
Expand Down
Loading
Loading