UNPKG

@argos-ci/cypress

Version:

Cypress SDK for visual testing with Argos.

48 lines (47 loc) 1.4 kB
// src/task.ts import { upload } from "@argos-ci/core"; import { basename, extname, join, dirname } from "node:path"; import { rename } from "node:fs/promises"; function checkIsCypressFailedResult(results) { return "status" in results && results.status === "failed"; } function registerArgosTask(on, config, options) { on("after:screenshot", async (details) => { const baseName = basename(details.path, extname(details.path)); const newBaseName = baseName.replace(/ \(attempt \d+\)/, ""); const newPath = join( dirname(details.path), newBaseName + extname(details.path) ); await 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 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}`); }); } export { registerArgosTask };