UNPKG

@uuv/cypress

Version:

A solution to facilitate the writing and execution of E2E tests understandable by any human being using cucumber(BDD) and cypress

165 lines (164 loc) 6.76 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __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 }); exports.setupNodeEvents = setupNodeEvents; const webpack = __importStar(require("@cypress/webpack-preprocessor")); const cypress_cucumber_preprocessor_1 = require("@badeball/cypress-cucumber-preprocessor"); const fs_1 = __importDefault(require("fs")); const event_1 = require("@uuv/runner-commons/runner/event"); const path_1 = __importDefault(require("path")); async function setupNodeEvents(on, config) { const startedFile = []; await (0, cypress_cucumber_preprocessor_1.addCucumberPreprocessorPlugin)(on, config); await event_1.UUVListenerHelper.build(); on("file:preprocessor", webpack.default({ webpackOptions: { resolve: { extensions: [".ts", ".js"], fallback: { child_process: false, fs: false, path: require.resolve("path-browserify") } }, module: { rules: [ { test: /\.ts$/, exclude: [/node_modules/], use: [ { loader: "ts-loader", options: { transpileOnly: true, } }, ], }, { test: /\.feature$/, use: [ { loader: "@badeball/cypress-cucumber-preprocessor/webpack", options: config, }, ], }, ], }, }, })); on("before:run", async () => { await (0, cypress_cucumber_preprocessor_1.beforeRunHandler)(config); // eslint-disable-next-line dot-notation const a11yReportFilePath = config.env["uuvOptions"].report.a11y.outputFile; // eslint-disable-next-line dot-notation const generateA11yReport = config.env["uuvOptions"].report.a11y.enabled; clearA11yReport(a11yReportFilePath); if (generateA11yReport === true) { await initA11yReport(a11yReportFilePath); } event_1.UUVEventEmitter.getInstance().emitProgressStart(); }); on("after:run", async () => { await (0, cypress_cucumber_preprocessor_1.afterRunHandler)(config); event_1.UUVEventEmitter.getInstance().emitProgressFinish(); }); on("before:spec", async (spec) => { if (!startedFile.includes(spec.absolute)) { await (0, cypress_cucumber_preprocessor_1.beforeSpecHandler)(config, spec); event_1.UUVEventEmitter.getInstance().emitTestSuiteStarted({ testSuiteName: spec.name, testSuitelocation: spec.absolute }); startedFile.push(spec.absolute); } }); on("after:spec", async (spec, results) => { await (0, cypress_cucumber_preprocessor_1.afterSpecHandler)(config, spec, results); results?.tests?.forEach(test => { event_1.UUVEventEmitter.getInstance().emitTestStarted({ testName: test.title[1], testSuiteName: spec.name, testSuitelocation: spec.absolute }); if (test.state === "passed") { event_1.UUVEventEmitter.getInstance().emitTestFinished({ testName: test.title[1], testSuiteName: spec.name, duration: test.duration }); } else if (test.state === "failed") { event_1.UUVEventEmitter.getInstance().emitTestFailed({ testName: test.title[1], testSuiteName: spec.name, duration: test.duration }); } else { event_1.UUVEventEmitter.getInstance().emitTestIgnored({ testName: test.title[1], testSuiteName: spec.name }); } }); event_1.UUVEventEmitter.getInstance().emitTestSuiteFinished({ testSuiteName: spec.name }); }); function clearA11yReport(reportFilePath) { if (fs_1.default.existsSync(reportFilePath)) { fs_1.default.rmSync(reportFilePath); } } async function initA11yReport(reportFilePath) { // eslint-disable-next-line dot-notation const packageJson = await Promise.resolve(`${path_1.default.join(config.env["uuvOptions"].projectDir, "package.json")}`).then(s => __importStar(require(s))); const emptyReport = { app: { name: packageJson.name, description: packageJson.description, usecases: [] } }; fs_1.default.writeFileSync(reportFilePath, JSON.stringify(emptyReport, null, 4), { flag: "w" }); } // Make sure to return the config object as it might have been modified by the plugin. return config; }