@@ -239,12 +239,26 @@ export const generate = task({
239239 } ,
240240} ) ;
241241
242- const goTestFlags = [
243- ...goBuildFlags ,
244- ...goBuildTags ( ) ,
245- ...( options . tests ? [ `-run=${ options . tests } ` ] : [ ] ) ,
246- ...( options . coverage ? [ "-coverprofile=coverage.out" , "-coverpkg=./..." ] : [ ] ) ,
247- ] ;
242+ const coverageDir = path . join ( __dirname , "coverage" ) ;
243+
244+ const ensureCoverageDirExists = memoize ( ( ) => {
245+ if ( options . coverage ) {
246+ fs . mkdirSync ( coverageDir , { recursive : true } ) ;
247+ }
248+ } ) ;
249+
250+ /**
251+ * @param {string } taskName
252+ */
253+ function goTestFlags ( taskName ) {
254+ ensureCoverageDirExists ( ) ;
255+ return [
256+ ...goBuildFlags ,
257+ ...goBuildTags ( ) ,
258+ ...( options . tests ? [ `-run=${ options . tests } ` ] : [ ] ) ,
259+ ...( options . coverage ? [ `-coverprofile=${ path . join ( coverageDir , "coverage." + taskName + ".out" ) } ` , "-coverpkg=./..." ] : [ ] ) ,
260+ ] ;
261+ }
248262
249263const goTestEnv = {
250264 ...( options . concurrentTestPrograms ? { TS_TEST_PROGRAM_SINGLE_THREADED : "false" } : { } ) ,
@@ -260,18 +274,24 @@ const goTestSumFlags = [
260274
261275const $test = $ ( { env : goTestEnv } ) ;
262276
263- const gotestsum = memoize ( ( ) => {
277+ /**
278+ * @param {string } taskName
279+ */
280+ function gotestsum ( taskName ) {
264281 const args = isInstalled ( "gotestsum" ) ? [ "gotestsum" , ...goTestSumFlags , "--" ] : [ "go" , "test" ] ;
265- return args . concat ( goTestFlags ) ;
266- } ) ;
282+ return args . concat ( goTestFlags ( taskName ) ) ;
283+ }
267284
268- const goTest = memoize ( ( ) => {
269- return [ "go" , "test" ] . concat ( goTestFlags ) ;
270- } ) ;
285+ /**
286+ * @param {string } taskName
287+ */
288+ function goTest ( taskName ) {
289+ return [ "go" , "test" ] . concat ( goTestFlags ( taskName ) ) ;
290+ }
271291
272292async function runTests ( ) {
273293 warnIfTypeScriptSubmoduleNotCloned ( ) ;
274- await $test `${ gotestsum ( ) } ./... ${ isCI ? [ "--timeout=45m" ] : [ ] } ` ;
294+ await $test `${ gotestsum ( "tests" ) } ./... ${ isCI ? [ "--timeout=45m" ] : [ ] } ` ;
275295}
276296
277297export const test = task ( {
@@ -282,7 +302,7 @@ export const test = task({
282302async function runTestBenchmarks ( ) {
283303 warnIfTypeScriptSubmoduleNotCloned ( ) ;
284304 // Run the benchmarks once to ensure they compile and run without errors.
285- await $test `${ goTest ( ) } -run=- -bench=. -benchtime=1x ./...` ;
305+ await $test `${ goTest ( "benchmarks" ) } -run=- -bench=. -benchtime=1x ./...` ;
286306}
287307
288308export const testBenchmarks = task ( {
@@ -291,7 +311,7 @@ export const testBenchmarks = task({
291311} ) ;
292312
293313async function runTestTools ( ) {
294- await $test ( { cwd : path . join ( __dirname , "_tools" ) } ) `${ gotestsum ( ) } ./...` ;
314+ await $test ( { cwd : path . join ( __dirname , "_tools" ) } ) `${ gotestsum ( "tools" ) } ./...` ;
295315}
296316
297317export const testTools = task ( {
0 commit comments