Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Only output test logs on failure in CI (vercel#27604)
Browse files Browse the repository at this point in the history
This updates to only output a test's logs when it fails to reduce the noise in the CI's logs to allow easier investigating a failure. This also updates azure to leverage the `run-tests` script when testing ie11 to allow retrying similar to our other tests.
  • Loading branch information
ijjk authored Jul 29, 2021
1 parent 0d2e7af commit 9a73b80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ stages:
- job: test_ie11
pool:
vmImage: 'windows-2019'
variables:
BROWSER_NAME: internet explorer
steps:
- checkout: none
- task: NodeTool@0
Expand All @@ -86,7 +88,7 @@ stages:
path: $(System.DefaultWorkingDirectory)
displayName: Cache Build
- script: |
yarn testie --forceExit test/integration/production/ test/integration/css-client-nav/ test/integration/rewrites-has-condition/
node run-tests.js -c 1 test/integration/production/test/index.test.js test/integration/css-client-nav/test/index.test.js test/integration/rewrites-has-condition/test/index.test.js
displayName: 'Run tests'
- job: test_unit
Expand Down
23 changes: 21 additions & 2 deletions run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ async function main() {
}
} catch (err) {
console.log(`Failed to fetch timings data`, err)
process.exit(1)
}
}
}
Expand Down Expand Up @@ -183,6 +184,7 @@ async function main() {
const runTest = (test = '', usePolling) =>
new Promise((resolve, reject) => {
const start = new Date().getTime()
let outputChunks = []
const child = spawn(
'node',
[
Expand All @@ -196,7 +198,7 @@ async function main() {
test,
],
{
stdio: 'inherit',
stdio: ['ignore', 'pipe', 'pipe'],
env: {
JEST_RETRY_TIMES: 0,
...process.env,
Expand All @@ -217,10 +219,19 @@ async function main() {
},
}
)
child.stdout.on('data', (chunk) => {
outputChunks.push(chunk)
})
child.stderr.on('data', (chunk) => {
outputChunks.push(chunk)
})
children.add(child)
child.on('exit', (code) => {
children.delete(child)
if (code) reject(new Error(`failed with code: ${code}`))
if (code) {
outputChunks.forEach((chunk) => process.stdout.write(chunk))
reject(new Error(`failed with code: ${code}`))
}
resolve(new Date().getTime() - start)
})
})
Expand All @@ -242,12 +253,16 @@ async function main() {

for (let i = 0; i < NUM_RETRIES + 1; i++) {
try {
console.log(`Starting ${test} retry ${i}/${NUM_RETRIES}`)
const time = await runTest(test, i > 0)
timings.push({
file: test,
time,
})
passed = true
console.log(
`Finished ${test} on retry ${i}/${NUM_RETRIES} in ${time / 1000}s`
)
break
} catch (err) {
if (i < NUM_RETRIES) {
Expand Down Expand Up @@ -287,12 +302,16 @@ async function main() {

for (let i = 0; i < NUM_RETRIES + 1; i++) {
try {
console.log(`Starting ${test} retry ${i}/${NUM_RETRIES}`)
const time = await runTest(test, i > 0)
timings.push({
file: test,
time,
})
passed = true
console.log(
`Finished ${test} on retry ${i}/${NUM_RETRIES} in ${time / 1000}s`
)
break
} catch (err) {
if (i < NUM_RETRIES) {
Expand Down

0 comments on commit 9a73b80

Please sign in to comment.