progress.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var BaseReporter = require('./base')
  2. var ProgressReporter = function (formatError, reportSlow, useColors, browserConsoleLogOptions) {
  3. BaseReporter.call(this, formatError, reportSlow, useColors, browserConsoleLogOptions)
  4. this.EXCLUSIVELY_USE_COLORS = false
  5. this._browsers = []
  6. this.writeCommonMsg = function (msg) {
  7. this.write(this._remove() + msg + this._render())
  8. }
  9. this.specSuccess = function () {
  10. this.write(this._refresh())
  11. }
  12. this.onBrowserComplete = function () {
  13. this.write(this._refresh())
  14. }
  15. this.onRunStart = function () {
  16. this._browsers = []
  17. this._isRendered = false
  18. }
  19. this.onBrowserStart = function (browser) {
  20. this._browsers.push(browser)
  21. if (this._isRendered) {
  22. this.write('\n')
  23. }
  24. this.write(this._refresh())
  25. }
  26. this._remove = function () {
  27. if (!this._isRendered) {
  28. return ''
  29. }
  30. var cmd = ''
  31. this._browsers.forEach(function () {
  32. cmd += '\x1B[1A' + '\x1B[2K'
  33. })
  34. this._isRendered = false
  35. return cmd
  36. }
  37. this._render = function () {
  38. this._isRendered = true
  39. return this._browsers.map(this.renderBrowser).join('\n') + '\n'
  40. }
  41. this._refresh = function () {
  42. return this._remove() + this._render()
  43. }
  44. }
  45. // PUBLISH
  46. module.exports = ProgressReporter