Skip to content

Commit 9b68b3a

Browse files
committed
add test context since tests are no longer sequential
1 parent 891f5e2 commit 9b68b3a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

test/src/updater/blackboxUpdateTest.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { archFromString, doSpawn, getArchSuffix, log, TmpDir } from "builder-uti
44
import { Arch, Configuration, Platform } from "electron-builder"
55
import fs, { existsSync, outputFile } from "fs-extra"
66
import path from "path"
7-
import { afterAll, beforeAll, describe, expect, ExpectStatic } from "vitest"
7+
import { afterAll, beforeAll, describe, ExpectStatic, TestContext } from "vitest"
88
import { launchAndWaitForQuit } from "../helpers/launchAppCrossPlatform"
99
import { assertPack, modifyPackageJson, PackedContext } from "../helpers/packTester"
1010
import { ELECTRON_VERSION } from "../helpers/testConfig"
@@ -24,23 +24,23 @@ describe("Electron autoupdate (fresh install & update)", () => {
2424
})
2525

2626
// Signing is required for macOS autoupdate
27-
test.ifMac.ifEnv(process.env.CSC_KEY_PASSWORD)("mac", async () => {
28-
await runTest("zip")
27+
test.ifMac.ifEnv(process.env.CSC_KEY_PASSWORD)("mac", async context => {
28+
await runTest(context, "zip")
2929
})
3030

31-
test.ifWindows("win", async () => {
32-
await runTest("nsis")
31+
test.ifWindows("win", async context => {
32+
await runTest(context, "nsis")
3333
})
3434

3535
// must be sequential in order for process.env.ELECTRON_BUILDER_LINUX_PACKAGE_MANAGER to be respected per-test
3636
describe.runIf(process.platform === "linux")("linux", () => {
37-
test.ifEnv(process.env.RUN_APP_IMAGE_TEST && process.arch === "arm64")("AppImage - arm64", async () => {
38-
await runTest("AppImage", Arch.arm64)
37+
test.ifEnv(process.env.RUN_APP_IMAGE_TEST && process.arch === "arm64")("AppImage - arm64", async context => {
38+
await runTest(context, "AppImage", Arch.arm64)
3939
})
4040

4141
// only works on x64, so this will fail on arm64 macs due to arch mismatch
42-
test.ifEnv(process.env.RUN_APP_IMAGE_TEST && process.arch === "x64")("AppImage - x64", async () => {
43-
await runTest("AppImage", Arch.x64)
42+
test.ifEnv(process.env.RUN_APP_IMAGE_TEST && process.arch === "x64")("AppImage - x64", async context => {
43+
await runTest(context, "AppImage", Arch.x64)
4444
})
4545

4646
// package manager tests specific to each distro (and corresponding docker image)
@@ -52,7 +52,7 @@ describe("Electron autoupdate (fresh install & update)", () => {
5252
context.skip()
5353
}
5454
process.env.ELECTRON_BUILDER_LINUX_PACKAGE_MANAGER = pm
55-
await runTest(target, Arch.x64)
55+
await runTest(context, target, Arch.x64)
5656
delete process.env.ELECTRON_BUILDER_LINUX_PACKAGE_MANAGER
5757
})
5858
}
@@ -84,7 +84,9 @@ const packageManagerMap: {
8484
},
8585
}
8686

87-
async function runTest(target: string, arch: Arch = Arch.x64) {
87+
async function runTest(context: TestContext, target: string, arch: Arch = Arch.x64) {
88+
const { expect } = context
89+
8890
const tmpDir = new TmpDir("auto-update")
8991
const outDirs: ApplicationUpdatePaths[] = []
9092
await doBuild(expect, outDirs, Platform.current().createTarget([target], arch), tmpDir, process.platform === "win32")
@@ -116,7 +118,7 @@ async function runTest(target: string, arch: Arch = Arch.x64) {
116118
await new Promise(resolve => setTimeout(resolve, delay))
117119

118120
expect((await verifyAppVersion(NEW_VERSION_NUMBER)).version).toMatch(NEW_VERSION_NUMBER)
119-
})
121+
}).catch(() => tmpDir.cleanupSync())
120122
// windows needs to release file locks, so a delay seems to be needed
121123
await new Promise(resolve => setTimeout(resolve, 1000))
122124
await handleCleanupPerOS({ target })

0 commit comments

Comments
 (0)