@nx/playwright 21.0.0-beta.2 → 21.0.0-beta.4

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-beta.2",
3
+ "version": "21.0.0-beta.4",
4
4
  "type": "commonjs",
5
5
  "homepage": "https://nx.dev",
6
6
  "private": false,
@@ -35,9 +35,9 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@phenomnomnominal/tsquery": "~5.0.1",
38
- "@nx/devkit": "21.0.0-beta.2",
39
- "@nx/eslint": "21.0.0-beta.2",
40
- "@nx/js": "21.0.0-beta.2",
38
+ "@nx/devkit": "21.0.0-beta.4",
39
+ "@nx/eslint": "21.0.0-beta.4",
40
+ "@nx/js": "21.0.0-beta.4",
41
41
  "tslib": "^2.3.0",
42
42
  "minimatch": "9.0.3"
43
43
  },
@@ -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: [
@@ -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,
@@ -290,6 +303,53 @@ function addSubfolderToOutput(output, subfolder) {
290
303
  }
291
304
  return (0, node_path_1.join)(output, subfolder);
292
305
  }
306
+ function getWebserverCommandTasks(playwrightConfig) {
307
+ if (!playwrightConfig.webServer) {
308
+ return [];
309
+ }
310
+ const tasks = [];
311
+ const webServer = Array.isArray(playwrightConfig.webServer)
312
+ ? playwrightConfig.webServer
313
+ : [playwrightConfig.webServer];
314
+ for (const server of webServer) {
315
+ if (!server.reuseExistingServer) {
316
+ continue;
317
+ }
318
+ const task = parseTaskFromCommand(server.command);
319
+ if (task) {
320
+ tasks.push(task);
321
+ }
322
+ }
323
+ return tasks;
324
+ }
325
+ function parseTaskFromCommand(command) {
326
+ const nxRunRegex = /^(?:(?:npx|yarn|bun|pnpm|pnpm exec|pnpx) )?nx run (\S+:\S+)$/;
327
+ const infixRegex = /^(?:(?:npx|yarn|bun|pnpm|pnpm exec|pnpx) )?nx (\S+ \S+)$/;
328
+ const nxRunMatch = command.match(nxRunRegex);
329
+ if (nxRunMatch) {
330
+ const [project, target] = nxRunMatch[1].split(':');
331
+ return { project, target };
332
+ }
333
+ const infixMatch = command.match(infixRegex);
334
+ if (infixMatch) {
335
+ const [target, project] = infixMatch[1].split(' ');
336
+ return { project, target };
337
+ }
338
+ return null;
339
+ }
340
+ function getDependsOn(tasks) {
341
+ const projectsPerTask = new Map();
342
+ for (const { project, target } of tasks) {
343
+ if (!projectsPerTask.has(target)) {
344
+ projectsPerTask.set(target, []);
345
+ }
346
+ projectsPerTask.get(target).push(project);
347
+ }
348
+ return Array.from(projectsPerTask.entries()).map(([target, projects]) => ({
349
+ projects,
350
+ target,
351
+ }));
352
+ }
293
353
  function normalizeOutput(path, workspaceRoot, projectRoot) {
294
354
  const fullProjectRoot = (0, node_path_1.resolve)(workspaceRoot, projectRoot);
295
355
  const fullPath = (0, node_path_1.resolve)(fullProjectRoot, path);