Commit d68c7fd
Changed files (2)
src
test
src/experimental.ts
@@ -94,8 +94,12 @@ export async function spinner<T>(
return within(async () => {
$.verbose = false
const id = setInterval(spin, 100)
- const result = await callback!()
- clearInterval(id)
+ let result: T
+ try {
+ result = await callback!()
+ } finally {
+ clearInterval(id)
+ }
return result
})
}
test/experimental.test.js
@@ -22,6 +22,8 @@ $.verbose = false
function zx(script) {
return $`node build/cli.js --experimental --eval ${script}`
+ .nothrow()
+ .timeout('5s')
}
test('retry() works', async () => {
@@ -75,4 +77,12 @@ test('spinner() with title works', async () => {
assert.match(out.stderr, 'processing')
})
+test('spinner() stops on throw', async () => {
+ let out = await zx(`
+ await spinner('processing', () => $\`wtf-cmd\`)
+ `)
+ assert.match(out.stderr, 'Error:')
+ assert.is.not(out.exitCode, 0)
+})
+
test.run()