@@ -4,7 +4,7 @@ import fs from "node:fs"
44import os from "node:os"
55import path from "node:path"
66import { describe , it } from "node:test"
7- import { fileURLToPath } from "node:url"
7+ import { fileURLToPath , pathToFileURL } from "node:url"
88
99import {
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
213214describe ( "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+
262288describe ( "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