UNPKG

@currents/nx

Version:
134 lines 5.84 kB
"use strict"; /// <reference types="cypress" /> Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const devkit_1 = require("@nx/devkit"); const path_1 = require("path"); const cypress_cloud_1 = require("cypress-cloud"); function cypressExecutor(options, context) { var _a, e_1, _b, _c; return tslib_1.__awaiter(this, void 0, void 0, function* () { options = normalizeOptions(options, context); // this is used by cypress component testing presets to build the executor contexts with the correct configuration options. process.env['NX_CYPRESS_TARGET_CONFIGURATION'] = context.configurationName; let success; try { for (var _d = true, _e = tslib_1.__asyncValues(startDevServer(options, context)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) { _c = _f.value; _d = false; const _baseUrl = _c; options.baseUrl = _baseUrl; try { success = yield runCurrents(options); if (!options.watch) break; } catch (e) { devkit_1.logger.error(e.message); success = false; if (!options.watch) break; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) yield _b.call(_e); } finally { if (e_1) throw e_1.error; } } return { success }; }); } exports.default = cypressExecutor; function normalizeOptions(options, context) { options.env = options.env || {}; if (options.tsConfig) { const tsConfigPath = (0, path_1.join)(context.root, options.tsConfig); options.env['tsConfig'] = tsConfigPath; process.env['TS_NODE_PROJECT'] = tsConfigPath; } return options; } function startDevServer(opts, context) { return tslib_1.__asyncGenerator(this, arguments, function* startDevServer_1() { var _a, e_2, _b, _c; // no dev server, return the provisioned base url if (!opts.devServerTarget || opts.skipServe) { yield yield tslib_1.__await(opts.baseUrl); return yield tslib_1.__await(void 0); } const { project, target, configuration } = (0, devkit_1.parseTargetString)(opts.devServerTarget); const devServerTargetOpts = (0, devkit_1.readTargetOptions)({ project, target, configuration }, context); const targetSupportsWatchOpt = Object.keys(devServerTargetOpts).includes('watch'); try { for (var _d = true, _e = tslib_1.__asyncValues(yield tslib_1.__await((0, devkit_1.runExecutor)({ project, target, configuration }, // @NOTE: Do not forward watch option if not supported by the target dev server, // this is relevant for running Cypress against dev server target that does not support this option, // for instance @nguniversal/builders:ssr-dev-server. targetSupportsWatchOpt ? { watch: opts.watch } : {}, context))), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) { _c = _f.value; _d = false; const output = _c; if (!output.success && !opts.watch) throw new Error('Could not compile application files'); yield yield tslib_1.__await(opts.baseUrl || output.baseUrl); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e)); } finally { if (e_2) throw e_2.error; } } }); } /** * Initialize the Cypress test runner with the provided project configuration. * By default, Cypress will run tests from the CLI without the GUI and provide directly the results in the console output. */ function runCurrents(opts) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { // Cypress expects the folder where a cypress config is present const projectFolderPath = (0, path_1.dirname)(opts.cypressConfig); const options = { project: projectFolderPath, configFile: (0, path_1.basename)(opts.cypressConfig), }; // If not, will use the `baseUrl` normally from `cypress.json` if (opts.baseUrl) { options.config = { baseUrl: opts.baseUrl }; } if (opts.browser) { options['browser'] = opts.browser; } if (opts.env) { options.env = opts.env; } if (opts.spec) { options.spec = opts.spec; } options.tag = opts.tag; options.record = opts.record; options.recordKey = opts.key; options.parallel = opts.parallel; options.ciBuildId = (_a = opts.ciBuildId) === null || _a === void 0 ? void 0 : _a.toString(); options.group = opts.group; if (opts.reporter) { options['reporter'] = opts.reporter; } if (opts.reporterOptions) { options['reporterOptions'] = opts.reporterOptions; } options.testingType = opts.testingType; const result = yield (0, cypress_cloud_1.run)(options); if (!result || result.status === 'failed') { return false; } return (result.runs.reduce((acc, run) => { var _a, _b; return acc + ((_a = run.stats.failures) !== null && _a !== void 0 ? _a : 0) + ((_b = run.stats.skipped) !== null && _b !== void 0 ? _b : 0); }, 0) === 0); }); } //# sourceMappingURL=currents.impl.js.map