@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
63 lines • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VisualTestingPlaywrightReporter = void 0;
var tslib_1 = require("tslib");
var promises_1 = require("node:fs/promises");
var node_path_1 = require("node:path");
/**
* Playwright reporter for visual testing
*/
var VisualTestingPlaywrightReporter = /** @class */ (function () {
function VisualTestingPlaywrightReporter(options) {
this.outputFile = options.outputFile || (0, node_path_1.join)(process.cwd(), 'playwright-reports/visual-testing/report.json');
}
/**
* @inheritdoc
*/
VisualTestingPlaywrightReporter.prototype.printsToStdio = function () {
return false;
};
/**
* @inheritdoc
*/
VisualTestingPlaywrightReporter.prototype.onBegin = function (_, suite) {
this.suite = suite;
};
/**
* @inheritdoc
*/
VisualTestingPlaywrightReporter.prototype.onEnd = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var screenshotsToUpdate;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
screenshotsToUpdate = this.suite.allTests().flatMap(function (test) {
return test.results.flatMap(function (result) {
return result.errors
.map(function (error) { return error.matcherResult; })
.filter(function (matcherResult) {
return (matcherResult === null || matcherResult === void 0 ? void 0 : matcherResult.name) === 'toHaveScreenshot'
&& typeof matcherResult.actual === 'string'
&& typeof matcherResult.expected === 'string'
&& !matcherResult.pass;
})
.map(function (_a) {
var actual = _a.actual, expected = _a.expected;
return ({ actual: actual, expected: expected });
});
});
});
return [4 /*yield*/, (0, promises_1.mkdir)((0, node_path_1.dirname)(this.outputFile), { recursive: true })];
case 1:
_a.sent();
return [2 /*return*/, (0, promises_1.writeFile)(this.outputFile, JSON.stringify(screenshotsToUpdate, null, 2))];
}
});
});
};
return VisualTestingPlaywrightReporter;
}());
exports.VisualTestingPlaywrightReporter = VisualTestingPlaywrightReporter;
exports.default = VisualTestingPlaywrightReporter;
//# sourceMappingURL=index.js.map