Skip to content

Commit

Permalink
Fixed renderer test
Browse files Browse the repository at this point in the history
  • Loading branch information
usmanyunusov committed Feb 19, 2022
1 parent 8b1db4e commit f3d8422
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
7 changes: 6 additions & 1 deletion lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ export function createRenderer(stream, { isTTY = true } = {}) {
return this
},

spin(task) {
task && tasks.push(task)
return this.render()
},

loop() {
timer = setTimeout(() => this.loop(), 130)
return this.render()
return this.spin()
},

start(task) {
Expand Down
37 changes: 23 additions & 14 deletions test/renderer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,41 @@ test('should create is TTY renderer', async () => {
],
}

renderer.start(task)
renderer.spin(task)
task.state = 'run'

await delay(500)
renderer.spin(task)
task.state = 'warn'

await delay(500)
renderer.spin(task)
task.state = 'done'

await delay(500)
renderer.spin(task)
task.state = 'fail'

renderer.stop()

is(
stdout.out,
'\x1B[?25l\x1B[90m*\x1B[39m Test\n' +
'\x1B[90m*\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[33m\\\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[33m|\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[33m/\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[33m↓\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[33m↓\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[33m↓\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[33m↓\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[32m√\x1B[39m Test\x1B[1G\x1B[2K\x1B[32m√\x1B[39m Test\x1B[1G\x1B[2K\x1B[32m√\x1B[39m Test\x1B[1G\x1B[2K\x1B[32m√\x1B[39m Test\x1B[1G\x1B[2K\x1B[31m×\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\n' +
'\x1B[33m|\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[33m↓\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\n' +
'\x1B[33m↓\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\n' +
'\x1B[33m↓\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[32m√\x1B[39m Test\n' +
'\x1B[32m√\x1B[39m Test\n' +
'\x1B[32m√\x1B[39m Test\n' +
'\x1B[32m√\x1B[39m Test\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K\x1B[31m×\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\n' +
'\x1B[31m×\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\n' +
'\x1B[31m×\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\n' +
'\x1B[31m×\x1B[39m Test\n' +
' \x1B[90m*\x1B[39m Sub test\n' +
'\x1B[?25h'
)
Expand Down Expand Up @@ -81,8 +91,7 @@ test('should create is CI renderer', async () => {
]

for (const task of tasks) {
renderer.start(task)
await delay(1000)
renderer.spin(task)
}

renderer.stop()
Expand Down

0 comments on commit f3d8422

Please sign in to comment.