Skip to content

Commit 37c5fbd

Browse files
committed
test: fail prepare fixtures script if fixtures fail to install deps or build a fixture
1 parent 5a2d6fa commit 37c5fbd

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tests/prepare.mjs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ const promises = fixtures.map((fixture) =>
6262
this.push(chunk.toString().replace(/\n/gm, `\n[${fixture}] `))
6363
callback()
6464
},
65+
flush(callback) {
66+
// final transform might create non-terminated line with a prefix
67+
// so this is just to make sure we end with a newline so further writes
68+
// to same destination stream start on a new line for better readability
69+
this.push('\n')
70+
callback()
71+
},
6572
})
6673
console.log(`[${fixture}] Running \`${cmd}\`...`)
6774
const output = execaCommand(cmd, {
@@ -80,6 +87,11 @@ const promises = fixtures.map((fixture) =>
8087
operation: 'revert',
8188
})
8289
}
90+
if (output.exitCode !== 0) {
91+
const errorMessage = `[${fixture}] 🚨 Failed to install dependencies or build a fixture`
92+
console.error(errorMessage)
93+
throw new Error(errorMessage)
94+
}
8395
fixtureList.delete(fixture)
8496
})
8597
}).finally(() => {
@@ -91,5 +103,22 @@ const promises = fixtures.map((fixture) =>
91103
}
92104
}),
93105
)
94-
await Promise.allSettled(promises)
106+
const prepareFixturesResults = await Promise.allSettled(promises)
107+
const failedFixturesErrors = prepareFixturesResults
108+
.map((promise) => {
109+
if (promise.status === 'rejected') {
110+
return promise.reason
111+
}
112+
return null
113+
})
114+
.filter(Boolean)
115+
116+
if (failedFixturesErrors.length > 0) {
117+
console.error('Some fixtures failed to prepare:')
118+
for (const error of failedFixturesErrors) {
119+
console.error(error.message)
120+
}
121+
process.exit(1)
122+
}
123+
95124
console.log('🎉 All fixtures prepared')

0 commit comments

Comments
 (0)