@nx/playwright 21.0.0-canary.20250206-8bd0bcd → 21.0.0-canary.20250418-8619c1d

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/playwright",
3
- "version": "21.0.0-canary.20250206-8bd0bcd",
3
+ "version": "21.0.0-canary.20250418-8619c1d",
4
4
  "type": "commonjs",
5
5
  "homepage": "https://nx.dev",
6
6
  "private": false,
@@ -35,26 +35,18 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@phenomnomnominal/tsquery": "~5.0.1",
38
- "@nx/devkit": "21.0.0-canary.20250206-8bd0bcd",
39
- "@nx/eslint": "21.0.0-canary.20250206-8bd0bcd",
40
- "@nx/js": "21.0.0-canary.20250206-8bd0bcd",
38
+ "@nx/devkit": "21.0.0-canary.20250418-8619c1d",
39
+ "@nx/eslint": "21.0.0-canary.20250418-8619c1d",
40
+ "@nx/js": "21.0.0-canary.20250418-8619c1d",
41
41
  "tslib": "^2.3.0",
42
42
  "minimatch": "9.0.3"
43
43
  },
44
44
  "peerDependencies": {
45
- "@playwright/test": "^1.36.0",
46
- "@nx/webpack": "file:../webpack",
47
- "@nx/vite": "file:../vite"
45
+ "@playwright/test": "^1.36.0"
48
46
  },
49
47
  "peerDependenciesMeta": {
50
48
  "@playwright/test": {
51
49
  "optional": true
52
- },
53
- "@nx/webpack": {
54
- "optional": true
55
- },
56
- "@nx/vite": {
57
- "optional": true
58
50
  }
59
51
  },
60
52
  "executors": "./executors.json",
@@ -115,10 +115,10 @@ async function configurationGeneratorInternal(tree, rawOptions) {
115
115
  name: importPath,
116
116
  version: '0.0.1',
117
117
  private: true,
118
- nx: {
119
- name: options.project,
120
- },
121
118
  };
119
+ if (options.project !== importPath) {
120
+ packageJson.nx = { name: options.project };
121
+ }
122
122
  (0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
123
123
  }
124
124
  ignoreTestOutput(tree);
@@ -26,13 +26,13 @@ export default defineConfig({
26
26
  webServer: {
27
27
  command: '<%= webServerCommand %>',
28
28
  url: '<%= webServerAddress %>',
29
- reuseExistingServer: !process.env.CI,
29
+ reuseExistingServer: true,
30
30
  cwd: workspaceRoot
31
31
  },<% } else {%>
32
32
  // webServer: {
33
33
  // command: 'npm run start',
34
34
  // url: 'http://127.0.0.1:3000',
35
- // reuseExistingServer: !process.env.CI,
35
+ // reuseExistingServer: true,
36
36
  // cwd: workspaceRoot,
37
37
  // },<% } %>
38
38
  projects: [
@@ -84,8 +84,9 @@ async function default_1(tree) {
84
84
  : 'preview', projectToMigrate.configFileType === 'webpack'
85
85
  ? 'serveStaticTargetName'
86
86
  : 'previewTargetName', projectToMigrate.configFileType === 'webpack'
87
- ? (await getDynamicImportedModule('@nx/webpack/src/plugins/plugin', '@nx/webpack should be installed when attempting to setup @nx/playwright with a webpack config file.')).createNodesV2
88
- : (await getDynamicImportedModule('@nx/vite/plugin', '@nx/vite should be installed when attempting to setup @nx/playwright with a vite config file.')).createNodesV2)) ??
87
+ ? require('@nx/webpack/plugin').createNodesV2
88
+ : require('@nx/vite/plugin')
89
+ .createNodesV2)) ??
89
90
  getServeStaticLikeTarget(tree, graph, projectToMigrate.projectName, projectToMigrate.configFileType === 'webpack'
90
91
  ? '@nx/web:file-server'
91
92
  : '@nx/vite:preview-server');
@@ -131,14 +132,6 @@ async function default_1(tree) {
131
132
  await (0, add_e2e_ci_target_defaults_1.default)(tree);
132
133
  await (0, devkit_1.formatFiles)(tree);
133
134
  }
134
- async function getDynamicImportedModule(moduleName, error) {
135
- try {
136
- return (await Promise.resolve(`${moduleName}`).then(s => require(s)));
137
- }
138
- catch {
139
- throw new Error(error);
140
- }
141
- }
142
135
  async function getServeStaticTargetNameForConfigFile(tree, pluginName, configFile, defaultTargetName, targetNamePluginOption, createNodesV2) {
143
136
  const nxJson = (0, devkit_1.readNxJson)(tree);
144
137
  const matchingPluginRegistrations = nxJson.plugins?.filter((p) => typeof p === 'string' ? p === pluginName : p.plugin === pluginName);
@@ -14,7 +14,14 @@ const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
14
14
  const file_hasher_1 = require("nx/src/hasher/file-hasher");
15
15
  const pmc = (0, devkit_1.getPackageManagerCommand)();
16
16
  function readTargetsCache(cachePath) {
17
- return (0, node_fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
17
+ try {
18
+ return process.env.NX_CACHE_PROJECT_GRAPH !== 'false'
19
+ ? (0, devkit_1.readJsonFile)(cachePath)
20
+ : {};
21
+ }
22
+ catch {
23
+ return {};
24
+ }
18
25
  }
19
26
  function writeTargetsToCache(cachePath, results) {
20
27
  (0, devkit_1.writeJsonFile)(cachePath, results);
@@ -78,12 +85,12 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
78
85
  let metadata;
79
86
  const testOutput = getTestOutput(playwrightConfig);
80
87
  const reporterOutputs = getReporterOutputs(playwrightConfig);
88
+ const webserverCommandTasks = getWebserverCommandTasks(playwrightConfig);
81
89
  const baseTargetConfig = {
82
90
  command: 'playwright test',
83
91
  options: {
84
92
  cwd: '{projectRoot}',
85
93
  },
86
- parallelism: false,
87
94
  metadata: {
88
95
  technologies: ['playwright'],
89
96
  description: 'Runs Playwright Tests',
@@ -97,6 +104,12 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
97
104
  },
98
105
  },
99
106
  };
107
+ if (webserverCommandTasks.length) {
108
+ baseTargetConfig.dependsOn = getDependsOn(webserverCommandTasks);
109
+ }
110
+ else {
111
+ baseTargetConfig.parallelism = false;
112
+ }
100
113
  targets[options.targetName] = {
101
114
  ...baseTargetConfig,
102
115
  cache: true,
@@ -174,7 +187,6 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
174
187
  inputs: ciBaseTargetConfig.inputs,
175
188
  outputs: ciBaseTargetConfig.outputs,
176
189
  dependsOn,
177
- parallelism: false,
178
190
  metadata: {
179
191
  technologies: ['playwright'],
180
192
  description: 'Runs Playwright Tests in CI',
@@ -189,6 +201,9 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
189
201
  },
190
202
  },
191
203
  };
204
+ if (!webserverCommandTasks.length) {
205
+ targets[options.ciTargetName].parallelism = false;
206
+ }
192
207
  ciTargetGroup.push(options.ciTargetName);
193
208
  }
194
209
  return { targets, metadata };
@@ -290,6 +305,53 @@ function addSubfolderToOutput(output, subfolder) {
290
305
  }
291
306
  return (0, node_path_1.join)(output, subfolder);
292
307
  }
308
+ function getWebserverCommandTasks(playwrightConfig) {
309
+ if (!playwrightConfig.webServer) {
310
+ return [];
311
+ }
312
+ const tasks = [];
313
+ const webServer = Array.isArray(playwrightConfig.webServer)
314
+ ? playwrightConfig.webServer
315
+ : [playwrightConfig.webServer];
316
+ for (const server of webServer) {
317
+ if (!server.reuseExistingServer) {
318
+ continue;
319
+ }
320
+ const task = parseTaskFromCommand(server.command);
321
+ if (task) {
322
+ tasks.push(task);
323
+ }
324
+ }
325
+ return tasks;
326
+ }
327
+ function parseTaskFromCommand(command) {
328
+ const nxRunRegex = /^(?:(?:npx|yarn|bun|pnpm|pnpm exec|pnpx) )?nx run (\S+:\S+)$/;
329
+ const infixRegex = /^(?:(?:npx|yarn|bun|pnpm|pnpm exec|pnpx) )?nx (\S+ \S+)$/;
330
+ const nxRunMatch = command.match(nxRunRegex);
331
+ if (nxRunMatch) {
332
+ const [project, target] = nxRunMatch[1].split(':');
333
+ return { project, target };
334
+ }
335
+ const infixMatch = command.match(infixRegex);
336
+ if (infixMatch) {
337
+ const [target, project] = infixMatch[1].split(' ');
338
+ return { project, target };
339
+ }
340
+ return null;
341
+ }
342
+ function getDependsOn(tasks) {
343
+ const projectsPerTask = new Map();
344
+ for (const { project, target } of tasks) {
345
+ if (!projectsPerTask.has(target)) {
346
+ projectsPerTask.set(target, []);
347
+ }
348
+ projectsPerTask.get(target).push(project);
349
+ }
350
+ return Array.from(projectsPerTask.entries()).map(([target, projects]) => ({
351
+ projects,
352
+ target,
353
+ }));
354
+ }
293
355
  function normalizeOutput(path, workspaceRoot, projectRoot) {
294
356
  const fullProjectRoot = (0, node_path_1.resolve)(workspaceRoot, projectRoot);
295
357
  const fullPath = (0, node_path_1.resolve)(fullProjectRoot, path);