@nxextensions/firebase-cypress
Version:
An NX Plugin for Firebase Applications that would like to use emulators for E2E testing with Cypress
115 lines • 3.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = runCypressInternal;
const tslib_1 = require("tslib");
const devkit_1 = require("@nx/devkit");
const path_1 = require("path");
const fs_1 = require("fs");
const cypress_version_1 = require("./cypress-version");
const request_1 = tslib_1.__importDefault(require("./request"));
const kill_port_1 = require("./kill-port");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Cypress = require('cypress');
async function runCypressInternal(options, context) {
process.env.NX_CYPRESS_TARGET_CONFIGURATION = context.configurationName;
const success = await runCypress(options.baseUrl, options);
return {
success
};
}
async function runCypress(baseUrl, opts) {
var _a, _b;
const cypressVersion = (0, cypress_version_1.installedCypressVersion)();
const projectFolderPath = (0, path_1.dirname)(opts.cypressConfig);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const options = {
project: projectFolderPath,
configFile: (0, path_1.basename)(opts.cypressConfig)
};
if (baseUrl) {
options.config = { baseUrl };
}
if (opts.browser) {
options.browser = opts.browser;
}
if (opts.env) {
options.env = {
...options.env,
...opts.env
};
}
if (opts.spec) {
options.spec = opts.spec;
}
options.tag = opts.tag;
options.exit = opts.exit;
options.headed = opts.headed;
options.runnerUi = opts.runnerUi;
if (opts.headless) {
options.headless = opts.headless;
}
options.record = opts.record;
options.key = opts.key;
options.parallel = opts.parallel;
options.ciBuildId = (_a = opts.ciBuildId) === null || _a === void 0 ? void 0 : _a.toString();
options.group = opts.group;
if (cypressVersion >= 10) {
(_b = options.config) !== null && _b !== void 0 ? _b : (options.config = {});
options.config[opts.testingType] = {
excludeSpecPattern: opts.ignoreTestFiles
};
}
else {
options.ignoreTestFiles = opts.ignoreTestFiles;
}
if (opts.reporter) {
options.reporter = opts.reporter;
}
if (opts.reporterOptions) {
options.reporterOptions = opts.reporterOptions;
}
if (opts.quiet) {
options.quiet = opts.quiet;
}
if (opts.autoCancelAfterFailures !== undefined) {
options.autoCancelAfterFailures = opts.autoCancelAfterFailures;
}
if (opts.testingType)
options.testingType = opts.testingType;
const result = await (opts.watch ? Cypress.open(options) : Cypress.run(options));
cleanupTmpFile(opts.ctTailwindPath);
cleanupTmpFile(opts.portLockFilePath);
if (process.env.NX_VERBOSE_LOGGING === 'true' && opts.portLockFilePath) {
(0, fs_1.readdirSync)((0, path_1.dirname)(opts.portLockFilePath)).forEach((f) => {
if (f.endsWith('.txt')) {
devkit_1.logger.debug(`Lock file ${f} still present`);
}
});
}
await ensureWebServerClosed(options.config.baseUrl);
return !result.totalFailed && !result.failures;
}
function ensureWebServerClosed(url) {
return new Promise((res) => {
void (0, request_1.default)(url, async () => {
const urlParts = url.split(':');
const port = parseInt(urlParts[urlParts.length - 1]);
await (0, kill_port_1.killPort)(port);
res();
}, () => {
res();
});
});
}
function cleanupTmpFile(path) {
try {
if (path && (0, fs_1.existsSync)(path)) {
(0, fs_1.unlinkSync)(path);
}
return true;
}
catch (_a) {
return false;
}
}
//# sourceMappingURL=run-cypress.js.map