UNPKG

@argos-ci/cypress

Version:

Cypress SDK for visual testing with Argos.

73 lines (71 loc) 2.55 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/task.ts var task_exports = {}; __export(task_exports, { registerArgosTask: () => registerArgosTask }); module.exports = __toCommonJS(task_exports); var import_core = require("@argos-ci/core"); var import_node_path = require("path"); var import_promises = require("fs/promises"); function checkIsCypressFailedResult(results) { return "status" in results && results.status === "failed"; } function registerArgosTask(on, config, options) { on("after:screenshot", async (details) => { const baseName = (0, import_node_path.basename)(details.path, (0, import_node_path.extname)(details.path)); const newBaseName = baseName.replace(/ \(attempt \d+\)/, ""); const newPath = (0, import_node_path.join)( (0, import_node_path.dirname)(details.path), newBaseName + (0, import_node_path.extname)(details.path) ); await (0, import_promises.rename)(details.path, newPath); return { path: newPath }; }); on("after:run", async (results) => { const { screenshotsFolder } = config; if (!screenshotsFolder) { return; } const { uploadToArgos = true } = options || {}; if (!uploadToArgos) { return; } const res = await (0, import_core.upload)({ ...options, files: ["**/*.png"], root: screenshotsFolder, metadata: { testReport: checkIsCypressFailedResult(results) ? { status: "failed" } : { status: "passed", stats: { startTime: results.startedTestsAt, duration: results.totalDuration } } } }); console.log(`\u2705 Argos build created: ${res.build.url}`); }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { registerArgosTask });