123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- exports.default = void 0;
- function _chalk() {
- const data = _interopRequireDefault(require('chalk'));
- _chalk = function () {
- return data;
- };
- return data;
- }
- function _jestUtil() {
- const data = require('jest-util');
- _jestUtil = function () {
- return data;
- };
- return data;
- }
- var _DefaultReporter = _interopRequireDefault(require('./DefaultReporter'));
- function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : {default: obj};
- }
- function _defineProperty(obj, key, value) {
- if (key in obj) {
- Object.defineProperty(obj, key, {
- value: value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- } else {
- obj[key] = value;
- }
- return obj;
- }
- const {ICONS} = _jestUtil().specialChars;
- class VerboseReporter extends _DefaultReporter.default {
- constructor(globalConfig) {
- super(globalConfig);
- _defineProperty(this, '_globalConfig', void 0);
- this._globalConfig = globalConfig;
- }
- static filterTestResults(testResults) {
- return testResults.filter(({status}) => status !== 'pending');
- }
- static groupTestsBySuites(testResults) {
- const root = {
- suites: [],
- tests: [],
- title: ''
- };
- testResults.forEach(testResult => {
- let targetSuite = root; // Find the target suite for this test,
- // creating nested suites as necessary.
- for (const title of testResult.ancestorTitles) {
- let matchingSuite = targetSuite.suites.find(s => s.title === title);
- if (!matchingSuite) {
- matchingSuite = {
- suites: [],
- tests: [],
- title
- };
- targetSuite.suites.push(matchingSuite);
- }
- targetSuite = matchingSuite;
- }
- targetSuite.tests.push(testResult);
- });
- return root;
- }
- onTestResult(test, result, aggregatedResults) {
- super.testFinished(test.context.config, result, aggregatedResults);
- if (!result.skipped) {
- this.printTestFileHeader(
- result.testFilePath,
- test.context.config,
- result
- );
- if (!result.testExecError && !result.skipped) {
- this._logTestResults(result.testResults);
- }
- this.printTestFileFailureMessage(
- result.testFilePath,
- test.context.config,
- result
- );
- }
- super.forceFlushBufferedOutput();
- }
- _logTestResults(testResults) {
- this._logSuite(VerboseReporter.groupTestsBySuites(testResults), 0);
- this._logLine();
- }
- _logSuite(suite, indentLevel) {
- if (suite.title) {
- this._logLine(suite.title, indentLevel);
- }
- this._logTests(suite.tests, indentLevel + 1);
- suite.suites.forEach(suite => this._logSuite(suite, indentLevel + 1));
- }
- _getIcon(status) {
- if (status === 'failed') {
- return _chalk().default.red(ICONS.failed);
- } else if (status === 'pending') {
- return _chalk().default.yellow(ICONS.pending);
- } else if (status === 'todo') {
- return _chalk().default.magenta(ICONS.todo);
- } else {
- return _chalk().default.green(ICONS.success);
- }
- }
- _logTest(test, indentLevel) {
- const status = this._getIcon(test.status);
- const time = test.duration
- ? ` (${(0, _jestUtil().formatTime)(Math.round(test.duration))})`
- : '';
- this._logLine(
- status + ' ' + _chalk().default.dim(test.title + time),
- indentLevel
- );
- }
- _logTests(tests, indentLevel) {
- if (this._globalConfig.expand) {
- tests.forEach(test => this._logTest(test, indentLevel));
- } else {
- const summedTests = tests.reduce(
- (result, test) => {
- if (test.status === 'pending') {
- result.pending.push(test);
- } else if (test.status === 'todo') {
- result.todo.push(test);
- } else {
- this._logTest(test, indentLevel);
- }
- return result;
- },
- {
- pending: [],
- todo: []
- }
- );
- if (summedTests.pending.length > 0) {
- summedTests.pending.forEach(this._logTodoOrPendingTest(indentLevel));
- }
- if (summedTests.todo.length > 0) {
- summedTests.todo.forEach(this._logTodoOrPendingTest(indentLevel));
- }
- }
- }
- _logTodoOrPendingTest(indentLevel) {
- return test => {
- const printedTestStatus =
- test.status === 'pending' ? 'skipped' : test.status;
- const icon = this._getIcon(test.status);
- const text = _chalk().default.dim(`${printedTestStatus} ${test.title}`);
- this._logLine(`${icon} ${text}`, indentLevel);
- };
- }
- _logLine(str, indentLevel) {
- const indentation = ' '.repeat(indentLevel || 0);
- this.log(indentation + (str || ''));
- }
- }
- exports.default = VerboseReporter;
|