@nx/cypress 23.1.0-rc.2 → 23.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,5 +8,16 @@ export interface CypressBaseSetupSchema {
8
8
  directory?: string;
9
9
  js?: boolean;
10
10
  jsx?: boolean;
11
+ /**
12
+ * When set, the generated `cypress.config` includes the e2e preset inline so
13
+ * a fresh config is complete on first write - no post-hoc AST merge or
14
+ * overwrite. Omit for a bare `defineConfig({})` (e.g. component testing,
15
+ * which merges in its own `component` block afterwards).
16
+ */
17
+ e2ePreset?: {
18
+ /** Pre-formatted (indented) JSON of NxCypressE2EPresetOptions. */
19
+ presetOptions: string;
20
+ baseUrl?: string;
21
+ };
11
22
  }
12
23
  export declare function addBaseCypressSetup(tree: Tree, options: CypressBaseSetupSchema): void;
@@ -31,6 +31,12 @@ function addBaseCypressSetup(tree, options) {
31
31
  linter: isEslintInstalled(tree) ? 'eslint' : 'none',
32
32
  ext: '',
33
33
  moduleResolution: (0, internal_1.getTsConfigModuleResolution)(tree),
34
+ // The config-*-* templates use `import.meta.url` (ESM) / `__filename`
35
+ // (CJS) - the shape base-setup already selects below - so the e2e preset is
36
+ // rendered correctly for the module system without any AST parsing.
37
+ e2ePreset: !!options.e2ePreset,
38
+ presetOptions: options.e2ePreset?.presetOptions ?? '',
39
+ baseUrl: options.e2ePreset?.baseUrl ?? '',
34
40
  };
35
41
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files/common'), projectConfig.root, templateVars);
36
42
  (0, devkit_1.generateFiles)(tree, isUsingTsSolutionConfig
@@ -1,3 +1,12 @@
1
+ <% if (e2ePreset) { -%>
2
+ const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset');
3
+ <% } -%>
1
4
  const { defineConfig } = require('cypress');
2
-
3
- module.exports = defineConfig({});
5
+ <% if (!e2ePreset) { %>
6
+ <% } -%>
7
+ module.exports = defineConfig({<% if (e2ePreset) { %>
8
+ e2e: {
9
+ ...nxE2EPreset(__filename, <%- presetOptions %>),<% if (baseUrl) { %>
10
+ baseUrl: '<%- baseUrl %>',<% } %>
11
+ },
12
+ <% } %>});
@@ -1,3 +1,12 @@
1
+ <% if (e2ePreset) { -%>
2
+ import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
3
+ <% } -%>
1
4
  import { defineConfig } from 'cypress';
2
-
3
- export default defineConfig({});
5
+ <% if (!e2ePreset) { %>
6
+ <% } -%>
7
+ export default defineConfig({<% if (e2ePreset) { %>
8
+ e2e: {
9
+ ...nxE2EPreset(import.meta.url, <%- presetOptions %>),<% if (baseUrl) { %>
10
+ baseUrl: '<%- baseUrl %>',<% } %>
11
+ },
12
+ <% } %>});
@@ -1,3 +1,12 @@
1
+ <% if (e2ePreset) { -%>
2
+ const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset');
3
+ <% } -%>
1
4
  const { defineConfig } = require('cypress');
2
-
3
- module.exports = defineConfig({});
5
+ <% if (!e2ePreset) { %>
6
+ <% } -%>
7
+ module.exports = defineConfig({<% if (e2ePreset) { %>
8
+ e2e: {
9
+ ...nxE2EPreset(__filename, <%- presetOptions %>),<% if (baseUrl) { %>
10
+ baseUrl: '<%- baseUrl %>',<% } %>
11
+ },
12
+ <% } %>});
@@ -1,3 +1,12 @@
1
+ <% if (e2ePreset) { -%>
2
+ import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
3
+ <% } -%>
1
4
  import { defineConfig } from 'cypress';
2
-
3
- export default defineConfig({});
5
+ <% if (!e2ePreset) { %>
6
+ <% } -%>
7
+ export default defineConfig({<% if (e2ePreset) { %>
8
+ e2e: {
9
+ ...nxE2EPreset(import.meta.url, <%- presetOptions %>),<% if (baseUrl) { %>
10
+ baseUrl: '<%- baseUrl %>',<% } %>
11
+ },
12
+ <% } %>});
@@ -186,13 +186,11 @@ async function addFiles(tree, options, projectGraph, hasPlugin) {
186
186
  tmpl: '',
187
187
  };
188
188
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectConfig.root, fileOpts);
189
- (0, base_setup_1.addBaseCypressSetup)(tree, {
190
- project: options.project,
191
- directory: options.directory,
192
- jsx: options.jsx,
193
- js: options.js,
194
- });
195
189
  const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, options.js ? 'cypress.config.js' : 'cypress.config.ts');
190
+ // A pre-existing config may be user-authored, so we AST-merge our e2e block
191
+ // into it below. A fresh one is generated complete by base-setup, so it never
192
+ // needs AST parsing - loading tsquery crashes under TypeScript 7.
193
+ const cypressConfigExists = tree.exists(cyFile);
196
194
  let webServerCommands;
197
195
  let ciWebServerCommand;
198
196
  let ciBaseUrl;
@@ -216,14 +214,30 @@ async function addFiles(tree, options, projectGraph, hasPlugin) {
216
214
  ciWebServerCommand = `nx run ${parsedTarget.project}:serve-static`;
217
215
  }
218
216
  }
219
- const updatedCyConfig = await (0, config_1.addDefaultE2EConfig)(tree.read(cyFile, 'utf-8'), {
217
+ const e2ePresetOptions = {
220
218
  cypressDir: options.directory,
221
219
  bundler: options.bundler === 'vite' ? 'vite' : undefined,
222
220
  webServerCommands,
223
- ciWebServerCommand: ciWebServerCommand,
221
+ ciWebServerCommand,
224
222
  ciBaseUrl,
225
- }, options.baseUrl);
226
- tree.write(cyFile, updatedCyConfig);
223
+ };
224
+ (0, base_setup_1.addBaseCypressSetup)(tree, {
225
+ project: options.project,
226
+ directory: options.directory,
227
+ jsx: options.jsx,
228
+ js: options.js,
229
+ // Generate a fresh config already containing the e2e preset (base-setup
230
+ // no-ops when a config already exists - see the merge below).
231
+ e2ePreset: {
232
+ presetOptions: JSON.stringify(e2ePresetOptions, null, 2)
233
+ .split('\n')
234
+ .join('\n '),
235
+ baseUrl: options.baseUrl,
236
+ },
237
+ });
238
+ if (cypressConfigExists) {
239
+ tree.write(cyFile, await (0, config_1.addDefaultE2EConfig)(tree.read(cyFile, 'utf-8'), e2ePresetOptions, options.baseUrl));
240
+ }
227
241
  if (options.js) {
228
242
  (0, devkit_1.toJS)(tree);
229
243
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/cypress",
3
- "version": "23.1.0-rc.2",
3
+ "version": "23.1.0",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -89,12 +89,12 @@
89
89
  "semver": "^7.6.3",
90
90
  "tree-kill": "^1.2.2",
91
91
  "tslib": "^2.3.0",
92
- "@nx/devkit": "23.1.0-rc.2",
93
- "@nx/eslint": "23.1.0-rc.2",
94
- "@nx/js": "23.1.0-rc.2"
92
+ "@nx/devkit": "23.1.0",
93
+ "@nx/eslint": "23.1.0",
94
+ "@nx/js": "23.1.0"
95
95
  },
96
96
  "devDependencies": {
97
- "nx": "23.1.0-rc.2"
97
+ "nx": "23.1.0"
98
98
  },
99
99
  "peerDependencies": {
100
100
  "cypress": ">= 13 < 16"