Skip to content

Commit 0082736

Browse files
committed
fix: disable spinner in CI
closes google#1008
1 parent 756b742 commit 0082736

File tree

4 files changed

+51
-37
lines changed

4 files changed

+51
-37
lines changed

scripts/build-tests.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ apis.forEach((name) => {
4444
: ''
4545
fileContents += `
4646
describe('vendor ${name} API ', () => {
47+
// prettier-ignore
4748
test('exports', () => {
4849
assert.equal(typeof ${name}, '${typeof api}')${methodChecks}
4950
})

src/goods.ts

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ export async function spinner<T>(
175175
callback = title
176176
title = ''
177177
}
178+
if (process.env.CI) return callback!()
179+
178180
let i = 0
179181
const spin = () =>
180182
process.stderr.write(` ${'⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'[i++ % 10]} ${title}\r`)

test/goods.test.js

+37-17
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,51 @@ describe('goods', () => {
132132
assert.ok(Date.now() >= now + 2 + 4 + 8 + 16 + 32)
133133
})
134134

135-
test('spinner() works', async () => {
136-
const out = await zx(`
135+
describe('spinner()', () => {
136+
test('works', async () => {
137+
const out = await zx(
138+
`
139+
process.env.CI = ''
137140
echo(await spinner(async () => {
138141
await sleep(100)
139142
await $\`echo hidden\`
140143
return $\`echo result\`
141144
}))
142-
`)
143-
assert(out.stdout.includes('result'))
144-
assert(!out.stderr.includes('result'))
145-
assert(!out.stderr.includes('hidden'))
146-
})
147-
148-
test('spinner() with title works', async () => {
149-
const out = await zx(`
145+
`,
146+
{ CI: '' }
147+
)
148+
assert(out.stdout.includes('result'))
149+
assert(out.stderr.includes('⠋'))
150+
assert(!out.stderr.includes('result'))
151+
assert(!out.stderr.includes('hidden'))
152+
})
153+
154+
test('with title', async () => {
155+
const out = await zx(
156+
`
157+
process.env.CI = ''
150158
await spinner('processing', () => sleep(100))
151-
`)
152-
assert.match(out.stderr, /processing/)
153-
})
159+
`
160+
)
161+
assert.match(out.stderr, /processing/)
162+
})
163+
164+
test('disabled in CI', async () => {
165+
const out = await zx(
166+
`
167+
process.env.CI = 'true'
168+
await spinner('processing', () => sleep(100))
169+
`
170+
)
171+
assert.doesNotMatch(out.stderr, /processing/)
172+
})
154173

155-
test('spinner() stops on throw', async () => {
156-
const out = await zx(`
174+
test('stops on throw', async () => {
175+
const out = await zx(`
157176
await spinner('processing', () => $\`wtf-cmd\`)
158177
`)
159-
assert.match(out.stderr, /Error:/)
160-
assert(out.exitCode !== 0)
178+
assert.match(out.stderr, /Error:/)
179+
assert(out.exitCode !== 0)
180+
})
161181
})
162182
})

test/vendor-export.test.js

+11-20
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@ import {
2525
} from '../build/vendor.js'
2626

2727
describe('vendor chalk API ', () => {
28+
// prettier-ignore
2829
test('exports', () => {
2930
assert.equal(typeof chalk, 'function')
3031
assert.equal(typeof chalk.level, 'number', 'chalk.level')
3132
})
3233
})
3334

3435
describe('vendor depseek API ', () => {
36+
// prettier-ignore
3537
test('exports', () => {
3638
assert.equal(typeof depseek, 'function')
3739
})
3840
})
3941

4042
describe('vendor fs API ', () => {
43+
// prettier-ignore
4144
test('exports', () => {
4245
assert.equal(typeof fs, 'object')
4346
assert.equal(typeof fs.default, 'object', 'fs.default')
@@ -56,11 +59,7 @@ describe('vendor fs API ', () => {
5659
assert.equal(typeof fs.cp, 'function', 'fs.cp')
5760
assert.equal(typeof fs.cpSync, 'function', 'fs.cpSync')
5861
assert.equal(typeof fs.createReadStream, 'function', 'fs.createReadStream')
59-
assert.equal(
60-
typeof fs.createWriteStream,
61-
'function',
62-
'fs.createWriteStream'
63-
)
62+
assert.equal(typeof fs.createWriteStream, 'function', 'fs.createWriteStream')
6463
assert.equal(typeof fs.exists, 'function', 'fs.exists')
6564
assert.equal(typeof fs.existsSync, 'function', 'fs.existsSync')
6665
assert.equal(typeof fs.fchown, 'function', 'fs.fchown')
@@ -167,17 +166,9 @@ describe('vendor fs API ', () => {
167166
assert.equal(typeof fs.ensureLink, 'function', 'fs.ensureLink')
168167
assert.equal(typeof fs.ensureLinkSync, 'function', 'fs.ensureLinkSync')
169168
assert.equal(typeof fs.createSymlink, 'function', 'fs.createSymlink')
170-
assert.equal(
171-
typeof fs.createSymlinkSync,
172-
'function',
173-
'fs.createSymlinkSync'
174-
)
169+
assert.equal(typeof fs.createSymlinkSync, 'function', 'fs.createSymlinkSync')
175170
assert.equal(typeof fs.ensureSymlink, 'function', 'fs.ensureSymlink')
176-
assert.equal(
177-
typeof fs.ensureSymlinkSync,
178-
'function',
179-
'fs.ensureSymlinkSync'
180-
)
171+
assert.equal(typeof fs.ensureSymlinkSync, 'function', 'fs.ensureSymlinkSync')
181172
assert.equal(typeof fs.readJson, 'function', 'fs.readJson')
182173
assert.equal(typeof fs.readJsonSync, 'function', 'fs.readJsonSync')
183174
assert.equal(typeof fs.writeJson, 'function', 'fs.writeJson')
@@ -208,12 +199,14 @@ describe('vendor fs API ', () => {
208199
})
209200

210201
describe('vendor minimist API ', () => {
202+
// prettier-ignore
211203
test('exports', () => {
212204
assert.equal(typeof minimist, 'function')
213205
})
214206
})
215207

216208
describe('vendor ps API ', () => {
209+
// prettier-ignore
217210
test('exports', () => {
218211
assert.equal(typeof ps, 'object')
219212
assert.equal(typeof ps.kill, 'function', 'ps.kill')
@@ -225,13 +218,15 @@ describe('vendor ps API ', () => {
225218
})
226219

227220
describe('vendor which API ', () => {
221+
// prettier-ignore
228222
test('exports', () => {
229223
assert.equal(typeof which, 'function')
230224
assert.equal(typeof which.sync, 'function', 'which.sync')
231225
})
232226
})
233227

234228
describe('vendor YAML API ', () => {
229+
// prettier-ignore
235230
test('exports', () => {
236231
assert.equal(typeof YAML, 'object')
237232
assert.equal(typeof YAML.Alias, 'function', 'YAML.Alias')
@@ -259,11 +254,7 @@ describe('vendor YAML API ', () => {
259254
assert.equal(typeof YAML.isScalar, 'function', 'YAML.isScalar')
260255
assert.equal(typeof YAML.isSeq, 'function', 'YAML.isSeq')
261256
assert.equal(typeof YAML.parse, 'function', 'YAML.parse')
262-
assert.equal(
263-
typeof YAML.parseAllDocuments,
264-
'function',
265-
'YAML.parseAllDocuments'
266-
)
257+
assert.equal(typeof YAML.parseAllDocuments, 'function', 'YAML.parseAllDocuments')
267258
assert.equal(typeof YAML.parseDocument, 'function', 'YAML.parseDocument')
268259
assert.equal(typeof YAML.stringify, 'function', 'YAML.stringify')
269260
assert.equal(typeof YAML.visit, 'function', 'YAML.visit')

0 commit comments

Comments
 (0)