Skip to content

Commit 60f11c7

Browse files
committed
fix(ci): keep Stryker temp paths traversable
1 parent 9e69f97 commit 60f11c7

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎scripts/stryker-diff.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ export function resolveVitestBinary(repoRoot, packageEntry) {
313313
return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates.at(-1)
314314
}
315315

316+
export function resolveStrykerTempDir(repoRoot, runRoot) {
317+
return path.relative(runRoot, path.join(repoRoot, ".stryker-tmp")) || ".stryker-tmp"
318+
}
319+
316320
export function discoverRelatedTestFiles(repoRoot, packageEntry, reportDirectory) {
317321
const packageRoot = path.join(repoRoot, packageEntry.root)
318322
const runRoot = path.join(repoRoot, packageEntry.runRoot ?? packageEntry.root)
@@ -378,7 +382,7 @@ function runStryker(repoRoot, packageEntry, reportRoot, dryRunOnly) {
378382
.relative(runRoot, path.join(packageRoot, packageEntry.vitestConfig))
379383
.replaceAll("\\", "/"),
380384
STRYKER_REPORT_DIR: reportDirectory,
381-
STRYKER_TEMP_DIR: path.join(repoRoot, ".stryker-tmp", packageEntry.id),
385+
STRYKER_TEMP_DIR: resolveStrykerTempDir(repoRoot, runRoot),
382386
STRYKER_IN_PLACE: "false",
383387
STRYKER_VITEST_RELATED: packageEntry.vitestRelated === false ? "false" : "true",
384388
STRYKER_TEST_FILES: JSON.stringify(packageEntry.testFiles ?? []),

‎scripts/stryker-diff.test.mjs‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from "node:fs"
44
import os from "node:os"
55
import path from "node:path"
66
import { describe, it } from "node:test"
7-
import { fileURLToPath } from "node:url"
7+
import { fileURLToPath, pathToFileURL } from "node:url"
88

99
import {
1010
MAX_CHANGED_LINES,
@@ -23,6 +23,7 @@ import {
2323
parseNameStatus,
2424
parseVitestTestFiles,
2525
preferDirectTestFiles,
26+
resolveStrykerTempDir,
2627
resolveVitestBinary,
2728
packageForPath,
2829
runManifest,
@@ -211,6 +212,11 @@ describe("preferDirectTestFiles", () => {
211212
})
212213

213214
describe("related-test discovery", () => {
215+
it("keeps Stryker's temp directory relative to each run root", () => {
216+
assert.equal(resolveStrykerTempDir("/repo", "/repo"), ".stryker-tmp")
217+
assert.equal(resolveStrykerTempDir("/repo", "/repo/src"), path.join("..", ".stryker-tmp"))
218+
})
219+
214220
it("resolves Vitest from each package before falling back to the repository", () => {
215221
const repo = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-vitest-"))
216222
const extension = PACKAGE_CONFIGS.find(({ id }) => id === "extension")
@@ -259,6 +265,26 @@ describe("related-test discovery", () => {
259265
})
260266
})
261267

268+
describe("Stryker configuration", () => {
269+
it("uses the default or configured temp directory", async () => {
270+
const originalTempDir = process.env.STRYKER_TEMP_DIR
271+
const configUrl = pathToFileURL(path.join(repositoryRoot, "stryker.config.mjs"))
272+
273+
try {
274+
delete process.env.STRYKER_TEMP_DIR
275+
const defaultConfig = (await import(`${configUrl.href}?temp-dir=default`)).default
276+
assert.equal(defaultConfig.tempDirName, ".stryker-tmp")
277+
278+
process.env.STRYKER_TEMP_DIR = path.join("..", ".stryker-tmp")
279+
const configuredConfig = (await import(`${configUrl.href}?temp-dir=configured`)).default
280+
assert.equal(configuredConfig.tempDirName, path.join("..", ".stryker-tmp"))
281+
} finally {
282+
if (originalTempDir === undefined) delete process.env.STRYKER_TEMP_DIR
283+
else process.env.STRYKER_TEMP_DIR = originalTempDir
284+
}
285+
})
286+
})
287+
262288
describe("selectFromGit", () => {
263289
it("derives changed executable ranges from the base/head merge base", () => {
264290
const repo = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-diff-"))

0 commit comments

Comments
 (0)