UNPKG

folio

Version:

A customizable test framework to build your own test frameworks. Foundation for the [Playwright test runner](https://github.com/microsoft/playwright-test).

112 lines 4.44 kB
"use strict"; /** * 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 path = __importStar(require("path")); const base_1 = require("./base"); class LineReporter extends base_1.BaseReporter { constructor() { super(...arguments); this._current = 0; this._failures = 0; this._parametersToPreview = new Set(); } onBegin(config, suite) { super.onBegin(config, suite); this._total = suite.total; console.log(); } onStdOut(chunk, test) { this._dumpToStdio(test, chunk, process.stdout); } onStdErr(chunk, test) { this._dumpToStdio(test, chunk, process.stderr); } _dumpToStdio(test, chunk, stream) { if (this.config.quiet) return; stream.write(`\u001B[1A\u001B[2K`); if (test && this._lastTest !== test) { // Write new header for the output. stream.write(safe_1.default.gray(`${path.basename(test.spec.file)} - ${test.spec.fullTitle()}\n`)); this._lastTest = test; } stream.write(chunk); console.log(); } onTestEnd(test, result) { super.onTestEnd(test, result); const spec = test.spec; const baseName = path.basename(spec.file); const width = process.stdout.columns - 1; const title = `[${++this._current}/${this._total}] ${baseName} - ${spec.fullTitle()}`.substring(0, width); const params = title.length < width ? this._parametersString(test).substring(0, width - title.length) : ''; process.stdout.write(`\u001B[1A\u001B[2K${title}${safe_1.default.gray(params)}\n`); if (!this.willRetry(test, result) && !test.ok()) { process.stdout.write(`\u001B[1A\u001B[2K`); console.log(base_1.formatFailure(this.config, test, ++this._failures)); console.log(); } } onEnd() { process.stdout.write(`\u001B[1A\u001B[2K`); super.onEnd(); this.epilogue(false); } _parametersString(test) { if (!this._parameterSnapshot) { this._parameterSnapshot = { ...test.parameters }; return ''; } // Collect names of parameters that have different values. for (const key of Object.keys(test.parameters)) { if (this._parameterSnapshot[key] !== test.parameters[key]) this._parametersToPreview.add(key); } const preview = {}; for (const key of this._parametersToPreview) preview[key] = test.parameters[key]; if (Object.keys(preview).length) return ' [' + base_1.serializeParameters(preview) + ']'; else return ''; } } exports.default = LineReporter; //# sourceMappingURL=line.js.map