UNPKG

@itwin/certa

Version:

A mocha-based integration test runner

54 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CertaCore = void 0; exports.certa = certa; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ const ElectronTestRunner_1 = require("./runners/electron/ElectronTestRunner"); const ChromeTestRunner_1 = require("./runners/chrome/ChromeTestRunner"); const NodeTestRunner_1 = require("./runners/node/NodeTestRunner"); const CoverageUtils_1 = require("./utils/CoverageUtils"); const SpawnUtils_1 = require("./utils/SpawnUtils"); class CertaCore { static _runners = {}; static registerTestRunner(environment, runner) { this._runners[environment] = runner; } static getTestRunner(environment) { if (environment in this._runners) return this._runners[environment]; throw new Error(`Unknown TestRunner: "${environment}"`); } } exports.CertaCore = CertaCore; CertaCore.registerTestRunner("node", NodeTestRunner_1.NodeTestRunner); CertaCore.registerTestRunner("chrome", ChromeTestRunner_1.ChromeTestRunner); CertaCore.registerTestRunner("electron", ElectronTestRunner_1.ElectronTestRunner); async function certa(environment, config) { const runner = CertaCore.getTestRunner(environment); // If we're going to measure code coverage, we should stop now and let an `nyc`-wrapped child process take it from here. const alreadyInNyc = process.env.NYC_CWD !== undefined; if (config.cover && runner.supportsCoverage && !alreadyInNyc) return process.exit(await (0, CoverageUtils_1.relaunchForCoverage)()); if (runner.initialize) await runner.initialize(config); // In debug mode, we should now start listening for debugger connections (if we're not already). if (config.debug) (0, SpawnUtils_1.startDebugger)(config.ports.debugging); // Source map any errors in this backend process require("source-map-support").install(); /** * undefined if backendInitModule not specified; * callback if a cleanup function is returned by the backendInitModule export; * empty object if nothing is exported by the backendInitModule */ let cleanUpCallback; if (config.backendInitModule) cleanUpCallback = await require(config.backendInitModule); await runner.runTests(config); if (typeof cleanUpCallback === "function" && runner.supportsCleanup) await cleanUpCallback(); } //# sourceMappingURL=CertaCore.js.map