From f073882ea704884a8889be33f5568147cbc01839 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Tue, 11 Jul 2023 13:41:00 -0700 Subject: [PATCH] tests: save smokehouse outputs to .tmp/smokehouse-output --- .../smokehouse/frontends/smokehouse-bin.js | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/cli/test/smokehouse/frontends/smokehouse-bin.js b/cli/test/smokehouse/frontends/smokehouse-bin.js index e127e6d81b5b..942bd84cbf1a 100644 --- a/cli/test/smokehouse/frontends/smokehouse-bin.js +++ b/cli/test/smokehouse/frontends/smokehouse-bin.js @@ -229,17 +229,25 @@ async function begin() { servers?.forEach(s => s.close()); } + let smokehouseOutputDir; + let testResultsToOutput; if (!smokehouseResult.success) { - const failedTestResults = smokehouseResult.testResults.filter(r => r.failed); - // Save failed runs to directory. In CI, this is uploaded as an artifact. - const failuresDir = `${LH_ROOT}/.tmp/smokehouse-failures`; - fs.rmSync(failuresDir, {recursive: true, force: true}); - fs.mkdirSync(failuresDir); + smokehouseOutputDir = `${LH_ROOT}/.tmp/smokehouse-failures`; + testResultsToOutput = smokehouseResult.testResults.filter(r => r.failed); + } else if (!process.env.CI) { + // Otherwise, only write to disk in debug mode. + smokehouseOutputDir = `${LH_ROOT}/.tmp/smokehouse-output`; + testResultsToOutput = smokehouseResult.testResults; + } + + if (smokehouseOutputDir && testResultsToOutput) { + fs.rmSync(smokehouseOutputDir, {recursive: true, force: true}); + fs.mkdirSync(smokehouseOutputDir); - for (const testResult of failedTestResults) { + for (const testResult of testResultsToOutput) { for (let i = 0; i < testResult.runs.length; i++) { - const runDir = `${failuresDir}/${i}/${testResult.id}`; + const runDir = `${smokehouseOutputDir}/${i}/${testResult.id}`; fs.mkdirSync(runDir, {recursive: true}); const run = testResult.runs[i]; @@ -250,10 +258,18 @@ async function begin() { if (run.networkRequests) { fs.writeFileSync(`${runDir}/networkRequests.txt`, run.networkRequests.join('\n')); } + const config = testDefns.find(test => test.id === testResult.id)?.config; + if (config) { + fs.writeFileSync(`${runDir}/config.json`, JSON.stringify(config, null, 2)); + } } } - const cmd = `yarn smoke ${failedTestResults.map(r => r.id).join(' ')}`; + console.log(`smokehouse artifacts written to ${smokehouseOutputDir}`); + } + + if (!smokehouseResult.success && testResultsToOutput) { + const cmd = `yarn smoke ${testResultsToOutput.map(r => r.id).join(' ')}`; console.log(`rerun failures: ${cmd}`); }