constructor()

in codelab-final-state/functions/reporter.js [31:71]


  constructor(runner) {
    this._indents = 0;
    const stats = runner.stats;

    runner
      .on(EVENT_SUITE_BEGIN, (suite) => {
        if (suite.total() > 0) {
          console.log(clc.bold.white(suite.title));
        }
        this.increaseIndent();
      })
      .on(EVENT_SUITE_END, () => {
        this.decreaseIndent();
      })
      .on(EVENT_TEST_PASS, test => {
        console.log(`${this.indent()}${clc.bold.green('✓')} ${test.title}`);
      })
      .on(EVENT_TEST_PENDING, test => {
        console.log(`${this.indent()}${clc.bold.blue('?')} ${test.title}`);
      })
      .on(EVENT_TEST_FAIL, (test, err) => {
        console.log(`${this.indent()}${clc.bold.red('✗')} ${test.title}`);
        this.increaseIndent();
        console.log(this.indentMultilineString(`${clc.red(err.message.trim())}`));
        this.decreaseIndent();
      })
      .once(EVENT_RUN_END, () => {
        console.log();
        if (stats.passes > 0) {
          console.log(`${clc.bold.green('✓ Passed')}: ${stats.passes}`);
        }
        if (stats.pending > 0) {
          console.log(`${clc.bold.blue('? Pending')}: ${stats.pending}`);
        }
        if (stats.failures > 0) {
          console.log(`${clc.bold.red('✗ Failed')}: ${stats.failures}`);
        }
        console.log();
        console.log(`${clc.bold.yellow('Duration')}: ${stats.duration}ms`)
      });
  }