@nx/cypress 17.2.0-beta.2 → 17.2.0-beta.3

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.
package/migrations.json CHANGED
@@ -87,6 +87,15 @@
87
87
  "alwaysAddToPackageJson": false
88
88
  }
89
89
  }
90
+ },
91
+ "17.2.0-beta.2": {
92
+ "version": "17.2.0-beta.2",
93
+ "packages": {
94
+ "vite": {
95
+ "version": "^5.0.0",
96
+ "alwaysAddToPackageJson": false
97
+ }
98
+ }
90
99
  }
91
100
  }
92
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/cypress",
3
- "version": "17.2.0-beta.2",
3
+ "version": "17.2.0-beta.3",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Cypress contains executors and generators allowing your workspace to use the powerful Cypress integration testing capabilities.",
6
6
  "repository": {
@@ -34,14 +34,15 @@
34
34
  "migrations": "./migrations.json"
35
35
  },
36
36
  "dependencies": {
37
- "@nx/devkit": "17.2.0-beta.2",
38
- "@nx/eslint": "17.2.0-beta.2",
39
- "@nx/js": "17.2.0-beta.2",
37
+ "@nx/devkit": "17.2.0-beta.3",
38
+ "@nx/eslint": "17.2.0-beta.3",
39
+ "@nx/js": "17.2.0-beta.3",
40
40
  "@phenomnomnominal/tsquery": "~5.0.1",
41
41
  "detect-port": "^1.5.1",
42
+ "string-argv": "^0.3.2",
42
43
  "semver": "7.5.3",
43
44
  "tslib": "^2.3.0",
44
- "@nrwl/cypress": "17.2.0-beta.2"
45
+ "@nrwl/cypress": "17.2.0-beta.3"
45
46
  },
46
47
  "peerDependencies": {
47
48
  "cypress": ">= 3 < 14"
@@ -40,7 +40,7 @@ export type NxCypressE2EPresetOptions = {
40
40
  * default is 'src'
41
41
  **/
42
42
  cypressDir?: string;
43
- devServerTargets?: Record<string, string>;
44
- ciDevServerTarget?: string;
43
+ webServerCommands?: Record<string, string>;
44
+ ciWebServerCommand?: string;
45
45
  };
46
46
  export {};
@@ -5,8 +5,8 @@ const devkit_1 = require("@nx/devkit");
5
5
  const path_1 = require("path");
6
6
  const fs_1 = require("fs");
7
7
  const preprocessor_vite_1 = require("../src/plugins/preprocessor-vite");
8
- const ct_helpers_1 = require("../src/utils/ct-helpers");
9
- const start_dev_server_1 = require("../src/utils/start-dev-server");
8
+ const string_argv_1 = require("string-argv");
9
+ const child_process_1 = require("child_process");
10
10
  function nxBaseCypressPreset(pathToConfig, options) {
11
11
  // used to set babel settings for react CT.
12
12
  process.env.NX_CYPRESS_COMPONENT_TEST =
@@ -51,38 +51,45 @@ function nxE2EPreset(pathToConfig, options) {
51
51
  specPattern: `${basePath}/**/*.cy.{js,jsx,ts,tsx}`,
52
52
  fixturesFolder: `${basePath}/fixtures`,
53
53
  env: {
54
- devServerTargets: options?.devServerTargets,
55
- devServerTargetOptions: {},
56
- ciDevServerTarget: options?.ciDevServerTarget,
54
+ webServerCommands: options?.webServerCommands,
55
+ ciWebServerCommand: options?.ciWebServerCommand,
57
56
  },
58
57
  async setupNodeEvents(on, config) {
59
58
  if (options?.bundler === 'vite') {
60
59
  on('file:preprocessor', (0, preprocessor_vite_1.default)());
61
60
  }
62
- if (!config.env.devServerTargets) {
61
+ if (!config.env.webServerCommands) {
63
62
  return;
64
63
  }
65
- const devServerTarget = config.env.devServerTarget ?? config.env.devServerTargets['default'];
66
- if (!devServerTarget) {
64
+ const webServerCommand = config.env.webServerCommand ?? config.env.webServerCommands.default;
65
+ if (!webServerCommand) {
67
66
  return;
68
67
  }
69
- if (!config.baseUrl && devServerTarget) {
70
- const graph = await (0, devkit_1.createProjectGraphAsync)();
71
- const target = (0, devkit_1.parseTargetString)(devServerTarget, graph);
72
- const context = (0, ct_helpers_1.createExecutorContext)(graph, graph.nodes[target.project].data?.targets, target.project, target.target, target.configuration);
73
- const devServer = (0, start_dev_server_1.startDevServer)({
74
- devServerTarget,
75
- ...config.env.devServerTargetOptions,
76
- }, context);
77
- on('after:run', () => {
78
- devServer.return();
68
+ if (!config.baseUrl && webServerCommand) {
69
+ return new Promise((resolve) => {
70
+ const [command, ...args] = (0, string_argv_1.default)(webServerCommand);
71
+ const serverProcess = (0, child_process_1.spawn)(command, args, {
72
+ stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
73
+ cwd: devkit_1.workspaceRoot,
74
+ // Shell is required for windows but cannot be true on linux because it interferes with terminating the process
75
+ shell: process.platform === 'win32',
76
+ windowsHide: true,
77
+ });
78
+ serverProcess.on('message', (message) => {
79
+ if (typeof message === 'object' &&
80
+ 'type' in message &&
81
+ 'baseUrl' in message &&
82
+ message.type === 'server') {
83
+ config.baseUrl = message.baseUrl;
84
+ resolve(config);
85
+ }
86
+ });
87
+ on('after:run', () => {
88
+ serverProcess.kill('SIGTERM');
89
+ });
79
90
  });
80
- const devServerValue = (await devServer.next()).value;
81
- if (!devServerValue) {
82
- return;
83
- }
84
- return { ...config, baseUrl: devServerValue.baseUrl };
85
91
  }
92
+ return config;
86
93
  },
87
94
  };
88
95
  return baseConfig;
@@ -109,9 +109,6 @@ async function runCypress(baseUrl, opts) {
109
109
  if (opts.browser) {
110
110
  options.browser = opts.browser;
111
111
  }
112
- options.env = {
113
- devServerTarget: opts.devServerTarget,
114
- };
115
112
  if (opts.env) {
116
113
  options.env = {
117
114
  ...options.env,
@@ -95,28 +95,28 @@ async function addFiles(tree, options, projectGraph, hasPlugin) {
95
95
  jsx: options.jsx,
96
96
  });
97
97
  const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
98
- let devServerTargets;
98
+ let webServerCommands;
99
99
  let ciDevServerTarget;
100
100
  if (hasPlugin && !options.baseUrl && options.devServerTarget) {
101
- devServerTargets = {};
102
- devServerTargets.default = options.devServerTarget;
101
+ webServerCommands = {};
102
+ webServerCommands.default = 'nx run ' + options.devServerTarget;
103
103
  const parsedTarget = (0, devkit_1.parseTargetString)(options.devServerTarget, projectGraph);
104
104
  const devServerProjectConfig = (0, devkit_1.readProjectConfiguration)(tree, parsedTarget.project);
105
105
  // Add production e2e target if serve target is found
106
106
  if (parsedTarget.configuration !== 'production' &&
107
107
  devServerProjectConfig.targets[parsedTarget.target]?.configurations?.['production']) {
108
- devServerTargets.production = `${parsedTarget.project}:${parsedTarget.target}:production`;
108
+ webServerCommands.production = `nx run ${parsedTarget.project}:${parsedTarget.target}:production`;
109
109
  }
110
110
  // Add ci/static e2e target if serve target is found
111
111
  if (devServerProjectConfig.targets?.['serve-static']) {
112
- ciDevServerTarget = `${parsedTarget.project}:serve-static`;
112
+ ciDevServerTarget = `nx run ${parsedTarget.project}:serve-static`;
113
113
  }
114
114
  }
115
115
  const updatedCyConfig = await (0, config_1.addDefaultE2EConfig)(tree.read(cyFile, 'utf-8'), {
116
116
  cypressDir: options.directory,
117
117
  bundler: options.bundler === 'vite' ? 'vite' : undefined,
118
- devServerTargets,
119
- ciDevServerTarget: ciDevServerTarget,
118
+ webServerCommands,
119
+ ciWebServerCommand: ciDevServerTarget,
120
120
  }, options.baseUrl);
121
121
  tree.write(cyFile, updatedCyConfig);
122
122
  }
@@ -124,7 +124,7 @@ function buildCypressTargets(configFilePath, projectRoot, options, context) {
124
124
  targets[options.targetName].configurations ??= {};
125
125
  for (const [configuration, devServerTarget] of Object.entries(devServerTargets ?? {})) {
126
126
  targets[options.targetName].configurations[configuration] = {
127
- command: `cypress run --config-file ${relativeConfigPath} --e2e --env.devServerTarget ${devServerTarget}`,
127
+ command: `cypress run --config-file ${relativeConfigPath} --e2e --env.webServerCommand "nx run ${devServerTarget}"`,
128
128
  };
129
129
  }
130
130
  }
@@ -150,7 +150,7 @@ function buildCypressTargets(configFilePath, projectRoot, options, context) {
150
150
  outputs,
151
151
  inputs,
152
152
  cache: true,
153
- command: `cypress run --config-file ${relativeConfigPath} --e2e --env.devServerTarget ${ciDevServerTarget} --spec ${relativeSpecFilePath}`,
153
+ command: `cypress run --config-file ${relativeConfigPath} --e2e --env.webServerCommand "nx run ${ciDevServerTarget}" --spec ${relativeSpecFilePath}`,
154
154
  };
155
155
  dependsOn.push({
156
156
  target: targetName,
@@ -5,5 +5,5 @@ export declare const cypressViteDevServerVersion = "^2.2.1";
5
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 = "~4.3.9";
8
+ export declare const viteVersion = "^5.0.0";
9
9
  export declare const htmlWebpackPluginVersion = "^5.5.0";
@@ -8,5 +8,5 @@ exports.cypressViteDevServerVersion = '^2.2.1';
8
8
  exports.cypressVersion = '^13.0.0';
9
9
  exports.cypressWebpackVersion = '^2.0.0';
10
10
  exports.webpackHttpPluginVersion = '^5.5.0';
11
- exports.viteVersion = '~4.3.9';
11
+ exports.viteVersion = '^5.0.0';
12
12
  exports.htmlWebpackPluginVersion = '^5.5.0';