UNPKG

@nxextensions/firebase-cypress

Version:

An NX Plugin for Firebase Applications that would like to use emulators for E2E testing with Cypress

63 lines (61 loc) 3.09 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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CYPRESS_CONFIG_FILE_NAME_PATTERN = void 0; exports.addDefaultE2eConfig = addDefaultE2eConfig; exports.CYPRESS_CONFIG_FILE_NAME_PATTERN = 'cypress.config.{js,ts,mjs,cjs}'; const TS_QUERY_COMMON_JS_EXPORT_SELECTOR = 'BinaryExpression:has(Identifier[name="module"]):has(Identifier[name="exports"])'; const TS_QUERY_EXPORT_CONFIG_PREFIX = `:matches(ExportAssignment, ${TS_QUERY_COMMON_JS_EXPORT_SELECTOR}) `; async function addDefaultE2eConfig(cyConfigContents, options, baseUrl) { if (!cyConfigContents) { throw new Error('The selected cypress config file is empty!'); } const { tsquery } = await Promise.resolve().then(() => __importStar(require('@phenomnomnominal/tsquery'))); const isCommonJS = tsquery.query(cyConfigContents, TS_QUERY_COMMON_JS_EXPORT_SELECTOR).length > 0; const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name"e2e"])`); let updatedConfigContents = cyConfigContents; if (testingTypeConfig.length === 0) { const configValue = `nxE2EPreset(__filename, ${JSON.stringify(options)})`; updatedConfigContents = tsquery.replace(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node) => { const baseUrlContents = baseUrl ? `,\nbaseUrl: '${baseUrl}'` : ''; if (node.properties.length > 0) { return `{ ${node.properties.map((p) => p.getText()).join(',\n')}, e2e: { ...${configValue}${baseUrlContents} } }`; } return `{ e2e: { ...${configValue}${baseUrlContents} } }`; }); return isCommonJS ? `const { nxE2EPreset } = require('@nxextensions/firebase-cypress'); ${updatedConfigContents}` : `import { nxE2EPreset } from '@nxextensions/firebase-cypress'; ${updatedConfigContents}`; } return updatedConfigContents; } //# sourceMappingURL=config.js.map