UNPKG

@testomatio/reporter

Version:
98 lines (96 loc) 4.27 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.pipesFactory = pipesFactory; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const picocolors_1 = __importDefault(require("picocolors")); const constants_js_1 = require("../constants.js"); const testomatio_js_1 = __importDefault(require("./testomatio.js")); const github_js_1 = __importDefault(require("./github.js")); const gitlab_js_1 = __importDefault(require("./gitlab.js")); const csv_js_1 = __importDefault(require("./csv.js")); const html_js_1 = __importDefault(require("./html.js")); const bitbucket_js_1 = require("./bitbucket.js"); const debug_js_1 = require("./debug.js"); async function pipesFactory(params, opts) { const extraPipes = []; // Add extra pipes into package.json file: // "testomatio": { // "pipes": ["my-module-pipe", "./local/js/file/pipe"] // } const packageJsonFile = path_1.default.join(process.cwd(), 'package.json'); if (fs_1.default.existsSync(packageJsonFile)) { const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonFile).toString()); const pipeDefs = packageJson?.testomatio?.pipes || []; for (const pipeDef of pipeDefs) { let PipeClass; try { PipeClass = await Promise.resolve(`${pipeDef}`).then(s => __importStar(require(s))); } catch (err) { console.log(constants_js_1.APP_PREFIX, `Can't load module Testomatio pipe module from ${pipeDef}`); continue; } try { extraPipes.push(new PipeClass(params, opts)); } catch (err) { console.log(constants_js_1.APP_PREFIX, `Can't instantiate Testomatio for ${pipeDef}`, err); continue; } } } const pipes = [ new testomatio_js_1.default(params, opts), new github_js_1.default(params, opts), new gitlab_js_1.default(params, opts), new csv_js_1.default(params, opts), new html_js_1.default(params, opts), new bitbucket_js_1.BitbucketPipe(params, opts), new debug_js_1.DebugPipe(params, opts), ...extraPipes, ]; const pipesEnabled = pipes.filter(p => p.isEnabled); console.log(constants_js_1.APP_PREFIX, picocolors_1.default.cyan('Pipes:'), picocolors_1.default.cyan(pipesEnabled.map(p => p.toString()).join(', ') || 'No pipes enabled')); if (!pipesEnabled.length) { console.log(constants_js_1.APP_PREFIX, picocolors_1.default.dim('If you want to use Testomatio reporter, pass your token as TESTOMATIO env variable')); } return pipes; } module.exports.pipesFactory = pipesFactory;