Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions scripts/stryker-diff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ export function resolveVitestBinary(repoRoot, packageEntry) {
return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates.at(-1)
}

export function resolveStrykerTempDir(repoRoot, runRoot) {
return path.relative(runRoot, path.join(repoRoot, ".stryker-tmp")) || ".stryker-tmp"
}

export function discoverRelatedTestFiles(repoRoot, packageEntry, reportDirectory) {
const packageRoot = path.join(repoRoot, packageEntry.root)
const runRoot = path.join(repoRoot, packageEntry.runRoot ?? packageEntry.root)
Expand Down Expand Up @@ -378,6 +382,7 @@ function runStryker(repoRoot, packageEntry, reportRoot, dryRunOnly) {
.relative(runRoot, path.join(packageRoot, packageEntry.vitestConfig))
.replaceAll("\\", "/"),
STRYKER_REPORT_DIR: reportDirectory,
STRYKER_TEMP_DIR: resolveStrykerTempDir(repoRoot, runRoot),
STRYKER_IN_PLACE: "false",
STRYKER_VITEST_RELATED: packageEntry.vitestRelated === false ? "false" : "true",
STRYKER_TEST_FILES: JSON.stringify(packageEntry.testFiles ?? []),
Expand Down
28 changes: 27 additions & 1 deletion scripts/stryker-diff.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "node:fs"
import os from "node:os"
import path from "node:path"
import { describe, it } from "node:test"
import { fileURLToPath } from "node:url"
import { fileURLToPath, pathToFileURL } from "node:url"

import {
MAX_CHANGED_LINES,
Expand All @@ -23,6 +23,7 @@ import {
parseNameStatus,
parseVitestTestFiles,
preferDirectTestFiles,
resolveStrykerTempDir,
resolveVitestBinary,
packageForPath,
runManifest,
Expand Down Expand Up @@ -211,6 +212,11 @@ describe("preferDirectTestFiles", () => {
})

describe("related-test discovery", () => {
it("keeps Stryker's temp directory relative to each run root", () => {
assert.equal(resolveStrykerTempDir("/repo", "/repo"), ".stryker-tmp")
assert.equal(resolveStrykerTempDir("/repo", "/repo/src"), path.join("..", ".stryker-tmp"))
})

it("resolves Vitest from each package before falling back to the repository", () => {
const repo = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-vitest-"))
const extension = PACKAGE_CONFIGS.find(({ id }) => id === "extension")
Expand Down Expand Up @@ -259,6 +265,26 @@ describe("related-test discovery", () => {
})
})

describe("Stryker configuration", () => {
it("uses the default or configured temp directory", async () => {
const originalTempDir = process.env.STRYKER_TEMP_DIR
const configUrl = pathToFileURL(path.join(repositoryRoot, "stryker.config.mjs"))

try {
delete process.env.STRYKER_TEMP_DIR
const defaultConfig = (await import(`${configUrl.href}?temp-dir=default`)).default
assert.equal(defaultConfig.tempDirName, ".stryker-tmp")

process.env.STRYKER_TEMP_DIR = path.join("..", ".stryker-tmp")
const configuredConfig = (await import(`${configUrl.href}?temp-dir=configured`)).default
assert.equal(configuredConfig.tempDirName, path.join("..", ".stryker-tmp"))
} finally {
if (originalTempDir === undefined) delete process.env.STRYKER_TEMP_DIR
else process.env.STRYKER_TEMP_DIR = originalTempDir
}
})
})

describe("selectFromGit", () => {
it("derives changed executable ranges from the base/head merge base", () => {
const repo = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-diff-"))
Expand Down
2 changes: 1 addition & 1 deletion src/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ export default [
},
},
{
ignores: ["webview-ui", "out"],
ignores: [".stryker-tmp", "webview-ui", "out"],
},
]
4 changes: 2 additions & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"useUnknownInCatchVariables": false
},
"include": ["."],
"exclude": ["node_modules"],
"exclude": ["**/.stryker-tmp", "node_modules"],
"watchOptions": {
"watchFile": "useFsEvents",
"watchDirectory": "useFsEvents",
"fallbackPolling": "dynamicPriority",
"synchronousWatchDirectory": true,
"excludeDirectories": ["**/node_modules", "**/dist", "**/.turbo"]
"excludeDirectories": ["**/node_modules", "**/dist", "**/.stryker-tmp", "**/.turbo"]
}
}
2 changes: 2 additions & 0 deletions stryker.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const vitestConfig = process.env.STRYKER_VITEST_CONFIG ?? "vitest.config.ts"
const reportDirectory = process.env.STRYKER_REPORT_DIR ?? "reports/mutation"
const tempDirName = process.env.STRYKER_TEMP_DIR ?? ".stryker-tmp"
const testFiles = JSON.parse(process.env.STRYKER_TEST_FILES ?? "[]")

export default {
Expand All @@ -12,6 +13,7 @@ export default {
testFiles,
incremental: false,
inPlace: process.env.STRYKER_IN_PLACE === "true",
tempDirName,
concurrency: 2,
timeoutMS: 5_000,
timeoutFactor: 1.5,
Expand Down
Loading