folio
Version:
A customizable test framework to build your own test frameworks. Foundation for the [Playwright test runner](https://github.com/microsoft/playwright-test).
73 lines • 2.84 kB
JavaScript
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const safe_1 = __importDefault(require("colors/safe"));
const ms_1 = __importDefault(require("ms"));
const base_1 = require("./base");
class ListReporter extends base_1.BaseReporter {
constructor() {
super(...arguments);
this._failure = 0;
this._lastRow = 0;
this._testRows = new Map();
}
onBegin(config, suite) {
super.onBegin(config, suite);
console.log();
}
onTestBegin(test) {
super.onTestBegin(test);
process.stdout.write(' ' + safe_1.default.gray(test.spec.fullTitle() + ': ') + '\n');
this._testRows.set(test, this._lastRow++);
}
onTestEnd(test, result) {
super.onTestEnd(test, result);
const spec = test.spec;
const duration = safe_1.default.dim(` (${ms_1.default(result.duration)})`);
let text = '';
if (result.status === 'skipped') {
text = safe_1.default.green(' - ') + safe_1.default.cyan(spec.fullTitle());
}
else {
const statusMark = result.status === 'passed' ? ' ✓ ' : ' x ';
if (result.status === test.expectedStatus)
text = '\u001b[2K\u001b[0G' + safe_1.default.green(statusMark) + safe_1.default.gray(spec.fullTitle()) + duration;
else
text = '\u001b[2K\u001b[0G' + safe_1.default.red(` ${++this._failure}) ` + spec.fullTitle()) + duration;
}
const testRow = this._testRows.get(test);
// Go up if needed
if (testRow !== this._lastRow)
process.stdout.write(`\u001B[${this._lastRow - testRow}A`);
// Erase line
process.stdout.write('\u001B[2K');
process.stdout.write(text);
// Go down if needed.
if (testRow !== this._lastRow)
process.stdout.write(`\u001B[${this._lastRow - testRow}E`);
}
onEnd() {
super.onEnd();
process.stdout.write('\n');
this.epilogue(true);
}
}
exports.default = ListReporter;
//# sourceMappingURL=list.js.map
;