@nx/cypress 17.0.5 → 17.0.6

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.
Files changed (57) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/generators.json +3 -3
  4. package/index.d.ts +2 -2
  5. package/index.js +4 -4
  6. package/migrations.json +0 -24
  7. package/package.json +6 -6
  8. package/plugins/cypress-preset.d.ts +19 -27
  9. package/plugins/cypress-preset.js +11 -102
  10. package/src/executors/cypress/cypress.impl.d.ts +1 -1
  11. package/src/executors/cypress/cypress.impl.js +152 -6
  12. package/src/executors/cypress/schema.json +1 -11
  13. package/src/generators/base-setup/base-setup.d.ts +0 -1
  14. package/src/generators/base-setup/base-setup.js +3 -26
  15. package/src/generators/component-configuration/component-configuration.d.ts +2 -3
  16. package/src/generators/component-configuration/component-configuration.js +27 -50
  17. package/src/generators/component-configuration/files/__directory__/support/component-index.html +1 -4
  18. package/src/generators/component-configuration/schema.d.ts +0 -7
  19. package/src/generators/component-configuration/schema.json +1 -1
  20. package/src/generators/configuration/configuration.d.ts +0 -4
  21. package/src/generators/configuration/configuration.js +26 -90
  22. package/src/generators/configuration/schema.json +1 -1
  23. package/src/generators/cypress-project/cypress-project.js +5 -25
  24. package/src/generators/cypress-project/schema.d.ts +0 -1
  25. package/src/generators/cypress-project/schema.json +1 -1
  26. package/src/generators/init/init.d.ts +0 -2
  27. package/src/generators/init/init.js +15 -71
  28. package/src/generators/init/schema.d.ts +2 -4
  29. package/src/generators/init/schema.json +1 -19
  30. package/src/generators/migrate-to-cypress-11/schema.json +1 -1
  31. package/src/utils/add-linter.d.ts +0 -1
  32. package/src/utils/add-linter.js +4 -4
  33. package/src/utils/config.d.ts +7 -6
  34. package/src/utils/config.js +12 -39
  35. package/src/utils/ct-helpers.d.ts +1 -1
  36. package/src/utils/ct-helpers.js +2 -6
  37. package/src/utils/versions.d.ts +3 -3
  38. package/src/utils/versions.js +3 -3
  39. package/plugin.d.ts +0 -1
  40. package/plugin.js +0 -6
  41. package/src/generators/base-setup/files/config-js-cjs/__directory__/support/commands.js__ext__ +0 -35
  42. package/src/generators/base-setup/files/config-js-cjs/cypress.config.js__ext__ +0 -3
  43. package/src/generators/base-setup/files/config-js-esm/__directory__/support/commands.js__ext__ +0 -35
  44. package/src/generators/base-setup/files/config-js-esm/cypress.config.js__ext__ +0 -3
  45. package/src/generators/base-setup/files/config-ts/__directory__/support/commands.ts__ext__ +0 -35
  46. package/src/migrations/update-18-1-0/update-cypress-version-13-6-6.d.ts +0 -2
  47. package/src/migrations/update-18-1-0/update-cypress-version-13-6-6.js +0 -12
  48. package/src/plugins/plugin.d.ts +0 -9
  49. package/src/plugins/plugin.js +0 -227
  50. package/src/utils/constants.d.ts +0 -4
  51. package/src/utils/constants.js +0 -7
  52. package/src/utils/start-dev-server.d.ts +0 -9
  53. package/src/utils/start-dev-server.js +0 -157
  54. /package/src/generators/base-setup/files/{common/__directory__ → __directory__}/fixtures/example.json +0 -0
  55. /package/src/generators/base-setup/files/{common/__directory__ → __directory__}/support/commands.ts__ext__ +0 -0
  56. /package/src/generators/base-setup/files/{common/__directory__ → __directory__}/tsconfig.json__ext__ +0 -0
  57. /package/src/generators/base-setup/files/{config-ts/cypress.config.ts__ext__ → cypress.config.ts__ext__} +0 -0
@@ -20,16 +20,17 @@ async function addLinterToCyProject(tree, options) {
20
20
  linter: options.linter,
21
21
  skipFormat: true,
22
22
  tsConfigPaths: [(0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json')],
23
+ eslintFilePatterns: [
24
+ `${projectConfig.root}/**/*.${options.js ? 'js' : '{js,ts}'}`,
25
+ ],
23
26
  setParserOptionsProject: options.setParserOptionsProject,
24
27
  skipPackageJson: options.skipPackageJson,
25
28
  rootProject: options.rootProject,
26
- addPlugin: options.addPlugin,
27
29
  }));
28
30
  }
29
31
  if (!options.linter || options.linter !== eslint_1.Linter.EsLint) {
30
32
  return (0, devkit_1.runTasksInSerial)(...tasks);
31
33
  }
32
- options.overwriteExisting = options.overwriteExisting || !eslintFile;
33
34
  tasks.push(!options.skipPackageJson
34
35
  ? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'eslint-plugin-cypress': versions_1.eslintPluginCypressVersion })
35
36
  : () => { });
@@ -37,7 +38,6 @@ async function addLinterToCyProject(tree, options) {
37
38
  const overrides = [];
38
39
  if (options.rootProject) {
39
40
  (0, eslint_file_1.addPluginsToLintConfig)(tree, projectConfig.root, '@nx');
40
- overrides.push(global_eslint_config_1.typeScriptOverride);
41
41
  overrides.push(global_eslint_config_1.javaScriptOverride);
42
42
  }
43
43
  (0, eslint_file_1.addExtendsToLintConfig)(tree, projectConfig.root, 'plugin:cypress/recommended');
@@ -55,7 +55,7 @@ async function addLinterToCyProject(tree, options) {
55
55
  };
56
56
  const addCy6Override = cyVersion && cyVersion < 7;
57
57
  if (options.overwriteExisting) {
58
- overrides.unshift({
58
+ overrides.push({
59
59
  files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
60
60
  parserOptions: !options.setParserOptionsProject
61
61
  ? undefined
@@ -1,17 +1,18 @@
1
- import { type Tree } from '@nx/devkit';
2
- import type { NxComponentTestingOptions, NxCypressE2EPresetOptions } from '../../plugins/cypress-preset';
3
- export declare const CYPRESS_CONFIG_FILE_NAME_PATTERN = "cypress.config.{js,ts,mjs,cjs}";
4
- export declare function addDefaultE2EConfig(cyConfigContents: string, options: NxCypressE2EPresetOptions, baseUrl: string): Promise<string>;
1
+ export declare function addDefaultE2EConfig(cyConfigContents: string, options: {
2
+ directory: string;
3
+ bundler?: string;
4
+ }): Promise<string>;
5
5
  /**
6
6
  * Adds the nxComponentTestingPreset to the cypress config file
7
7
  * Make sure after calling this the correct import statement is addeda
8
8
  * to bring in the nxComponentTestingPreset function
9
9
  **/
10
- export declare function addDefaultCTConfig(cyConfigContents: string, options?: NxComponentTestingOptions): Promise<string>;
10
+ export declare function addDefaultCTConfig(cyConfigContents: string, options?: {
11
+ bundler?: string;
12
+ }): Promise<string>;
11
13
  /**
12
14
  * Adds the mount command for Cypress
13
15
  * Make sure after calling this the correct import statement is added
14
16
  * to bring in the correct mount from cypress.
15
17
  **/
16
18
  export declare function addMountDefinition(cmpCommandFileContents: string): Promise<string>;
17
- export declare function getProjectCypressConfigPath(tree: Tree, projectRoot: string): string;
@@ -1,40 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProjectCypressConfigPath = exports.addMountDefinition = exports.addDefaultCTConfig = exports.addDefaultE2EConfig = exports.CYPRESS_CONFIG_FILE_NAME_PATTERN = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- exports.CYPRESS_CONFIG_FILE_NAME_PATTERN = 'cypress.config.{js,ts,mjs,cjs}';
6
- const TS_QUERY_COMMON_JS_EXPORT_SELECTOR = 'BinaryExpression:has(Identifier[name="module"]):has(Identifier[name="exports"])';
7
- const TS_QUERY_EXPORT_CONFIG_PREFIX = `:matches(ExportAssignment, ${TS_QUERY_COMMON_JS_EXPORT_SELECTOR}) `;
8
- async function addDefaultE2EConfig(cyConfigContents, options, baseUrl) {
3
+ exports.addMountDefinition = exports.addDefaultCTConfig = exports.addDefaultE2EConfig = void 0;
4
+ const TS_QUERY_EXPORT_CONFIG_PREFIX = ':matches(ExportAssignment, BinaryExpression:has(Identifier[name="module"]):has(Identifier[name="exports"]))';
5
+ async function addDefaultE2EConfig(cyConfigContents, options) {
9
6
  if (!cyConfigContents) {
10
7
  throw new Error('The passed in cypress config file is empty!');
11
8
  }
12
9
  const { tsquery } = await Promise.resolve().then(() => require('@phenomnomnominal/tsquery'));
13
- const isCommonJS = tsquery.query(cyConfigContents, TS_QUERY_COMMON_JS_EXPORT_SELECTOR).length >
14
- 0;
15
10
  const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name="e2e"])`);
16
11
  let updatedConfigContents = cyConfigContents;
17
12
  if (testingTypeConfig.length === 0) {
18
- const configValue = `nxE2EPreset(__filename, ${JSON.stringify(options)})`;
13
+ const configValue = options.bundler === 'vite'
14
+ ? `nxE2EPreset(__filename, { cypressDir: '${options.directory}', bundler: 'vite' })`
15
+ : `nxE2EPreset(__filename, { cypressDir: '${options.directory}' })`;
19
16
  updatedConfigContents = tsquery.replace(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node) => {
20
- let baseUrlContents = baseUrl ? `,\nbaseUrl: '${baseUrl}'` : '';
21
17
  if (node.properties.length > 0) {
22
18
  return `{
23
19
  ${node.properties.map((p) => p.getText()).join(',\n')},
24
- e2e: { ...${configValue}${baseUrlContents} }
20
+ e2e: ${configValue}
25
21
  }`;
26
22
  }
27
23
  return `{
28
- e2e: { ...${configValue}${baseUrlContents} }
24
+ e2e: ${configValue}
29
25
  }`;
30
26
  });
31
- return isCommonJS
32
- ? `const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset');
33
-
34
- ${updatedConfigContents}`
35
- : `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
36
-
37
- ${updatedConfigContents}`;
27
+ updatedConfigContents = `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';\n${updatedConfigContents}`;
38
28
  }
39
29
  return updatedConfigContents;
40
30
  }
@@ -52,16 +42,9 @@ async function addDefaultCTConfig(cyConfigContents, options = {}) {
52
42
  const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name="component"])`);
53
43
  let updatedConfigContents = cyConfigContents;
54
44
  if (testingTypeConfig.length === 0) {
55
- let configValue = 'nxComponentTestingPreset(__filename)';
56
- if (options) {
57
- if (options.bundler !== 'vite') {
58
- // vite is the default bundler, so we don't need to set it
59
- delete options.bundler;
60
- }
61
- if (Object.keys(options).length) {
62
- configValue = `nxComponentTestingPreset(__filename, ${JSON.stringify(options)})`;
63
- }
64
- }
45
+ const configValue = options?.bundler === 'vite'
46
+ ? "nxComponentTestingPreset(__filename, { bundler: 'vite' })"
47
+ : 'nxComponentTestingPreset(__filename)';
65
48
  updatedConfigContents = tsquery.replace(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node) => {
66
49
  if (node.properties.length > 0) {
67
50
  return `{
@@ -103,13 +86,3 @@ async function addMountDefinition(cmpCommandFileContents) {
103
86
  return `${updatedInterface}\n${mountCommand}`;
104
87
  }
105
88
  exports.addMountDefinition = addMountDefinition;
106
- function getProjectCypressConfigPath(tree, projectRoot) {
107
- const cypressConfigPaths = (0, devkit_1.glob)(tree, [
108
- (0, devkit_1.joinPathFragments)(projectRoot, exports.CYPRESS_CONFIG_FILE_NAME_PATTERN),
109
- ]);
110
- if (cypressConfigPaths.length === 0) {
111
- throw new Error(`Could not find a cypress config file in ${projectRoot}.`);
112
- }
113
- return cypressConfigPaths[0];
114
- }
115
- exports.getProjectCypressConfigPath = getProjectCypressConfigPath;
@@ -11,6 +11,6 @@ export declare function getTempTailwindPath(context: ExecutorContext): string;
11
11
  * Checks if the childProjectName is a descendent of the parentProjectName
12
12
  * in the project graph
13
13
  **/
14
- export declare function isCtProjectUsingBuildProject(graph: ProjectGraph, parentProjectName: string, childProjectName: string, seen?: Set<string>): boolean;
14
+ export declare function isCtProjectUsingBuildProject(graph: ProjectGraph, parentProjectName: string, childProjectName: string): boolean;
15
15
  export declare function getProjectConfigByPath(graph: ProjectGraph, configPath: string): ProjectConfiguration;
16
16
  export declare function createExecutorContext(graph: ProjectGraph, targets: Record<string, TargetConfiguration>, projectName: string, targetName: string, configurationName: string): ExecutorContext;
@@ -30,18 +30,14 @@ exports.getTempTailwindPath = getTempTailwindPath;
30
30
  * Checks if the childProjectName is a descendent of the parentProjectName
31
31
  * in the project graph
32
32
  **/
33
- function isCtProjectUsingBuildProject(graph, parentProjectName, childProjectName, seen = new Set()) {
34
- if (seen.has(parentProjectName)) {
35
- return false;
36
- }
37
- seen.add(parentProjectName);
33
+ function isCtProjectUsingBuildProject(graph, parentProjectName, childProjectName) {
38
34
  const isProjectDirectDep = graph.dependencies[parentProjectName].some((p) => p.target === childProjectName);
39
35
  if (isProjectDirectDep) {
40
36
  return true;
41
37
  }
42
38
  const maybeIntermediateProjects = graph.dependencies[parentProjectName].filter((p) => !graph.externalNodes[p.target]);
43
39
  for (const maybeIntermediateProject of maybeIntermediateProjects) {
44
- if (isCtProjectUsingBuildProject(graph, maybeIntermediateProject.target, childProjectName, seen)) {
40
+ if (isCtProjectUsingBuildProject(graph, maybeIntermediateProject.target, childProjectName)) {
45
41
  return true;
46
42
  }
47
43
  }
@@ -1,9 +1,9 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const eslintPluginCypressVersion = "^2.13.4";
3
- export declare const typesNodeVersion = "18.16.9";
3
+ export declare const typesNodeVersion = "16.11.7";
4
4
  export declare const cypressViteDevServerVersion = "^2.2.1";
5
- export declare const cypressVersion = "^13.6.6";
5
+ export declare const cypressVersion = "^13.0.0";
6
6
  export declare const cypressWebpackVersion = "^2.0.0";
7
7
  export declare const webpackHttpPluginVersion = "^5.5.0";
8
- export declare const viteVersion = "~5.0.0";
8
+ export declare const viteVersion = "~4.3.9";
9
9
  export declare const htmlWebpackPluginVersion = "^5.5.0";
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.htmlWebpackPluginVersion = exports.viteVersion = exports.webpackHttpPluginVersion = exports.cypressWebpackVersion = exports.cypressVersion = exports.cypressViteDevServerVersion = exports.typesNodeVersion = exports.eslintPluginCypressVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
5
  exports.eslintPluginCypressVersion = '^2.13.4';
6
- exports.typesNodeVersion = '18.16.9';
6
+ exports.typesNodeVersion = '16.11.7';
7
7
  exports.cypressViteDevServerVersion = '^2.2.1';
8
- exports.cypressVersion = '^13.6.6';
8
+ exports.cypressVersion = '^13.0.0';
9
9
  exports.cypressWebpackVersion = '^2.0.0';
10
10
  exports.webpackHttpPluginVersion = '^5.5.0';
11
- exports.viteVersion = '~5.0.0';
11
+ exports.viteVersion = '~4.3.9';
12
12
  exports.htmlWebpackPluginVersion = '^5.5.0';
package/plugin.d.ts DELETED
@@ -1 +0,0 @@
1
- export { createNodes, createDependencies } from './src/plugins/plugin';
package/plugin.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDependencies = exports.createNodes = void 0;
4
- var plugin_1 = require("./src/plugins/plugin");
5
- Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
6
- Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
@@ -1,35 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- // ***********************************************
4
- // This example commands.ts shows you how to
5
- // create various custom commands and overwrite
6
- // existing commands.
7
- //
8
- // For more comprehensive examples of custom
9
- // commands please read more here:
10
- // https://on.cypress.io/custom-commands
11
- // ***********************************************
12
-
13
- // eslint-disable-next-line @typescript-eslint/no-namespace
14
- declare namespace Cypress {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
- interface Chainable<Subject> {
17
- login(email: string, password: string): void;
18
- }
19
- }
20
-
21
- // -- This is a parent command --
22
- Cypress.Commands.add('login', (email, password) => {
23
- console.log('Custom command example: Login', email, password);
24
- });
25
- //
26
- // -- This is a child command --
27
- // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
28
- //
29
- //
30
- // -- This is a dual command --
31
- // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
32
- //
33
- //
34
- // -- This will overwrite an existing command --
35
- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
@@ -1,3 +0,0 @@
1
- const { defineConfig } = require('cypress');
2
-
3
- module.exports = defineConfig({});
@@ -1,35 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- // ***********************************************
4
- // This example commands.ts shows you how to
5
- // create various custom commands and overwrite
6
- // existing commands.
7
- //
8
- // For more comprehensive examples of custom
9
- // commands please read more here:
10
- // https://on.cypress.io/custom-commands
11
- // ***********************************************
12
-
13
- // eslint-disable-next-line @typescript-eslint/no-namespace
14
- declare namespace Cypress {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
- interface Chainable<Subject> {
17
- login(email: string, password: string): void;
18
- }
19
- }
20
-
21
- // -- This is a parent command --
22
- Cypress.Commands.add('login', (email, password) => {
23
- console.log('Custom command example: Login', email, password);
24
- });
25
- //
26
- // -- This is a child command --
27
- // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
28
- //
29
- //
30
- // -- This is a dual command --
31
- // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
32
- //
33
- //
34
- // -- This will overwrite an existing command --
35
- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
@@ -1,3 +0,0 @@
1
- import { defineConfig } from 'cypress';
2
-
3
- export default defineConfig({});
@@ -1,35 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- // ***********************************************
4
- // This example commands.ts shows you how to
5
- // create various custom commands and overwrite
6
- // existing commands.
7
- //
8
- // For more comprehensive examples of custom
9
- // commands please read more here:
10
- // https://on.cypress.io/custom-commands
11
- // ***********************************************
12
-
13
- // eslint-disable-next-line @typescript-eslint/no-namespace
14
- declare namespace Cypress {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
- interface Chainable<Subject> {
17
- login(email: string, password: string): void;
18
- }
19
- }
20
-
21
- // -- This is a parent command --
22
- Cypress.Commands.add('login', (email, password) => {
23
- console.log('Custom command example: Login', email, password);
24
- });
25
- //
26
- // -- This is a child command --
27
- // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
28
- //
29
- //
30
- // -- This is a dual command --
31
- // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
32
- //
33
- //
34
- // -- This will overwrite an existing command --
35
- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
@@ -1,2 +0,0 @@
1
- import { type Tree } from '@nx/devkit';
2
- export default function (tree: Tree): Promise<void>;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const devkit_1 = require("@nx/devkit");
4
- const cypress_version_1 = require("../../utils/cypress-version");
5
- async function default_1(tree) {
6
- if ((0, cypress_version_1.installedCypressVersion)() < 13) {
7
- return;
8
- }
9
- (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { cypress: '^13.6.6' });
10
- await (0, devkit_1.formatFiles)(tree);
11
- }
12
- exports.default = default_1;
@@ -1,9 +0,0 @@
1
- import { CreateDependencies, CreateNodes } from '@nx/devkit';
2
- export interface CypressPluginOptions {
3
- ciTargetName?: string;
4
- targetName?: string;
5
- openTargetName?: string;
6
- componentTestingTargetName?: string;
7
- }
8
- export declare const createDependencies: CreateDependencies;
9
- export declare const createNodes: CreateNodes<CypressPluginOptions>;
@@ -1,227 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNodes = exports.createDependencies = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const path_1 = require("path");
6
- const js_1 = require("@nx/js");
7
- const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
8
- const fs_1 = require("fs");
9
- const workspace_context_1 = require("nx/src/utils/workspace-context");
10
- const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
11
- const cache_directory_1 = require("nx/src/utils/cache-directory");
12
- const constants_1 = require("../utils/constants");
13
- const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
14
- const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'cypress.hash');
15
- const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
16
- const calculatedTargets = {};
17
- function readTargetsCache() {
18
- return (0, devkit_1.readJsonFile)(cachePath);
19
- }
20
- function writeTargetsToCache(targets) {
21
- (0, devkit_1.writeJsonFile)(cachePath, targets);
22
- }
23
- const createDependencies = () => {
24
- writeTargetsToCache(calculatedTargets);
25
- return [];
26
- };
27
- exports.createDependencies = createDependencies;
28
- exports.createNodes = [
29
- '**/cypress.config.{js,ts,mjs,cjs}',
30
- async (configFilePath, options, context) => {
31
- options = normalizeOptions(options);
32
- const projectRoot = (0, path_1.dirname)(configFilePath);
33
- // Do not create a project if package.json and project.json isn't there.
34
- const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
35
- if (!siblingFiles.includes('package.json') &&
36
- !siblingFiles.includes('project.json')) {
37
- return {};
38
- }
39
- const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
40
- (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
41
- ]);
42
- const { targets, metadata } = targetsCache[hash]
43
- ? targetsCache[hash]
44
- : await buildCypressTargets(configFilePath, projectRoot, options, context);
45
- calculatedTargets[hash] = { targets, metadata };
46
- const project = {
47
- projectType: 'application',
48
- targets,
49
- metadata,
50
- };
51
- return {
52
- projects: {
53
- [projectRoot]: project,
54
- },
55
- };
56
- },
57
- ];
58
- function getOutputs(projectRoot, cypressConfig, testingType) {
59
- function getOutput(path) {
60
- if (path.startsWith('..')) {
61
- return (0, devkit_1.joinPathFragments)('{workspaceRoot}', projectRoot, path);
62
- }
63
- else {
64
- return (0, devkit_1.joinPathFragments)('{projectRoot}', path);
65
- }
66
- }
67
- const { screenshotsFolder, videosFolder, e2e, component } = cypressConfig;
68
- const outputs = [];
69
- if (videosFolder) {
70
- outputs.push(getOutput(videosFolder));
71
- }
72
- if (screenshotsFolder) {
73
- outputs.push(getOutput(screenshotsFolder));
74
- }
75
- switch (testingType) {
76
- case 'e2e': {
77
- if (e2e.videosFolder) {
78
- outputs.push(getOutput(e2e.videosFolder));
79
- }
80
- if (e2e.screenshotsFolder) {
81
- outputs.push(getOutput(e2e.screenshotsFolder));
82
- }
83
- break;
84
- }
85
- case 'component': {
86
- if (component.videosFolder) {
87
- outputs.push(getOutput(component.videosFolder));
88
- }
89
- if (component.screenshotsFolder) {
90
- outputs.push(getOutput(component.screenshotsFolder));
91
- }
92
- break;
93
- }
94
- }
95
- return outputs;
96
- }
97
- async function buildCypressTargets(configFilePath, projectRoot, options, context) {
98
- const cypressConfig = await (0, config_utils_1.loadConfigFile)((0, path_1.join)(context.workspaceRoot, configFilePath));
99
- const pluginPresetOptions = {
100
- ...cypressConfig.e2e?.[constants_1.NX_PLUGIN_OPTIONS],
101
- ...cypressConfig.env,
102
- ...cypressConfig.e2e?.env,
103
- };
104
- const webServerCommands = pluginPresetOptions?.webServerCommands;
105
- const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
106
- const targets = {};
107
- let metadata;
108
- if ('e2e' in cypressConfig) {
109
- targets[options.targetName] = {
110
- command: `cypress run`,
111
- options: { cwd: projectRoot },
112
- cache: true,
113
- inputs: getInputs(namedInputs),
114
- outputs: getOutputs(projectRoot, cypressConfig, 'e2e'),
115
- metadata: {
116
- technologies: ['cypress'],
117
- description: 'Runs Cypress Tests',
118
- },
119
- };
120
- if (webServerCommands?.default) {
121
- delete webServerCommands.default;
122
- }
123
- if (Object.keys(webServerCommands ?? {}).length > 0) {
124
- targets[options.targetName].configurations ??= {};
125
- for (const [configuration, webServerCommand] of Object.entries(webServerCommands ?? {})) {
126
- targets[options.targetName].configurations[configuration] = {
127
- command: `cypress run --env webServerCommand="${webServerCommand}"`,
128
- };
129
- }
130
- }
131
- const ciWebServerCommand = pluginPresetOptions?.ciWebServerCommand;
132
- if (ciWebServerCommand) {
133
- const specPatterns = Array.isArray(cypressConfig.e2e.specPattern)
134
- ? cypressConfig.e2e.specPattern.map((p) => (0, path_1.join)(projectRoot, p))
135
- : [(0, path_1.join)(projectRoot, cypressConfig.e2e.specPattern)];
136
- const excludeSpecPatterns = !cypressConfig.e2e
137
- .excludeSpecPattern
138
- ? cypressConfig.e2e.excludeSpecPattern
139
- : Array.isArray(cypressConfig.e2e.excludeSpecPattern)
140
- ? cypressConfig.e2e.excludeSpecPattern.map((p) => (0, path_1.join)(projectRoot, p))
141
- : [(0, path_1.join)(projectRoot, cypressConfig.e2e.excludeSpecPattern)];
142
- const specFiles = (0, workspace_context_1.globWithWorkspaceContext)(context.workspaceRoot, specPatterns, excludeSpecPatterns);
143
- const dependsOn = [];
144
- const outputs = getOutputs(projectRoot, cypressConfig, 'e2e');
145
- const inputs = getInputs(namedInputs);
146
- const groupName = 'E2E (CI)';
147
- metadata = { targetGroups: { [groupName]: [] } };
148
- const ciTargetGroup = metadata.targetGroups[groupName];
149
- for (const file of specFiles) {
150
- const relativeSpecFilePath = (0, devkit_1.normalizePath)((0, path_1.relative)(projectRoot, file));
151
- const targetName = options.ciTargetName + '--' + relativeSpecFilePath;
152
- ciTargetGroup.push(targetName);
153
- targets[targetName] = {
154
- outputs,
155
- inputs,
156
- cache: true,
157
- command: `cypress run --env webServerCommand="${ciWebServerCommand}" --spec ${relativeSpecFilePath}`,
158
- options: {
159
- cwd: projectRoot,
160
- },
161
- metadata: {
162
- technologies: ['cypress'],
163
- description: `Runs Cypress Tests in ${relativeSpecFilePath} in CI`,
164
- },
165
- };
166
- dependsOn.push({
167
- target: targetName,
168
- projects: 'self',
169
- params: 'forward',
170
- });
171
- }
172
- targets[options.ciTargetName] = {
173
- executor: 'nx:noop',
174
- cache: true,
175
- inputs,
176
- outputs,
177
- dependsOn,
178
- metadata: {
179
- technologies: ['cypress'],
180
- description: 'Runs Cypress Tests in CI',
181
- },
182
- };
183
- ciTargetGroup.push(options.ciTargetName);
184
- }
185
- }
186
- if ('component' in cypressConfig) {
187
- // This will not override the e2e target if it is the same
188
- targets[options.componentTestingTargetName] ??= {
189
- command: `cypress run --component`,
190
- options: { cwd: projectRoot },
191
- cache: true,
192
- inputs: getInputs(namedInputs),
193
- outputs: getOutputs(projectRoot, cypressConfig, 'component'),
194
- metadata: {
195
- technologies: ['cypress'],
196
- description: 'Runs Cypress Component Tests',
197
- },
198
- };
199
- }
200
- targets[options.openTargetName] = {
201
- command: `cypress open`,
202
- options: { cwd: projectRoot },
203
- metadata: {
204
- technologies: ['cypress'],
205
- description: 'Opens Cypress',
206
- },
207
- };
208
- return { targets, metadata };
209
- }
210
- function normalizeOptions(options) {
211
- options ??= {};
212
- options.targetName ??= 'e2e';
213
- options.openTargetName ??= 'open-cypress';
214
- options.componentTestingTargetName ??= 'component-test';
215
- options.ciTargetName ??= 'e2e-ci';
216
- return options;
217
- }
218
- function getInputs(namedInputs) {
219
- return [
220
- ...('production' in namedInputs
221
- ? ['default', '^production']
222
- : ['default', '^default']),
223
- {
224
- externalDependencies: ['cypress'],
225
- },
226
- ];
227
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Key used to store options used by the nx plugin for @nx/cypress.
3
- */
4
- export declare const NX_PLUGIN_OPTIONS = "__NxPluginOptions__";
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NX_PLUGIN_OPTIONS = void 0;
4
- /**
5
- * Key used to store options used by the nx plugin for @nx/cypress.
6
- */
7
- exports.NX_PLUGIN_OPTIONS = '__NxPluginOptions__';
@@ -1,9 +0,0 @@
1
- import { ExecutorContext } from '@nx/devkit';
2
- import { CypressExecutorOptions } from '../executors/cypress/cypress.impl';
3
- export declare function startDevServer(opts: Omit<CypressExecutorOptions, 'cypressConfig'>, context: ExecutorContext): AsyncGenerator<{
4
- baseUrl: any;
5
- portLockFilePath?: undefined;
6
- } | {
7
- baseUrl: any;
8
- portLockFilePath: string;
9
- }, void, unknown>;