@nx/vitest 22.6.0-beta.0 → 22.6.0-beta.10

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@nx/vitest",
3
3
  "description": "The Nx Plugin for Vitest to enable fast unit testing with Vitest.",
4
- "version": "22.6.0-beta.0",
4
+ "version": "22.6.0-beta.10",
5
5
  "type": "commonjs",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -52,8 +52,8 @@
52
52
  "executors": "./executors.json",
53
53
  "generators": "./generators.json",
54
54
  "dependencies": {
55
- "@nx/devkit": "22.6.0-beta.0",
56
- "@nx/js": "22.6.0-beta.0",
55
+ "@nx/devkit": "22.6.0-beta.10",
56
+ "@nx/js": "22.6.0-beta.10",
57
57
  "tslib": "^2.3.0",
58
58
  "semver": "^7.6.3",
59
59
  "@phenomnomnominal/tsquery": "~6.1.4"
@@ -71,7 +71,7 @@
71
71
  }
72
72
  },
73
73
  "devDependencies": {
74
- "nx": "22.6.0-beta.0"
74
+ "nx": "22.6.0-beta.10"
75
75
  },
76
76
  "types": "./src/index.d.ts"
77
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/vitest/src/executors/test/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAIhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAQlD,wBAAsB,UAAU,CAC9B,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAuF9B;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAcnE"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/vitest/src/executors/test/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAIhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAQlD,wBAAsB,UAAU,CAC9B,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAkG9B;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAcnE"}
@@ -38,7 +38,7 @@ async function getOptions(options, context, projectRoot) {
38
38
  // Filter out options that are handled specially or are parseCLI artifacts
39
39
  const {
40
40
  // Handled specially by executor
41
- testFiles: _testFiles, configFile: _configFile, mode: _mode, runMode: _runMode, reportsDirectory, coverage,
41
+ testFiles: _testFiles, configFile: _configFile, mode: _mode, runMode: _runMode, reportsDirectory, coverage, reporter, reporters,
42
42
  // parseCLI artifacts
43
43
  '--': _dashdash, color: _color, w: _w,
44
44
  // Pass through any additional Vitest options
@@ -53,9 +53,17 @@ async function getOptions(options, context, projectRoot) {
53
53
  // but leaving it here in case someone did not migrate correctly
54
54
  root: resolved?.config?.root ?? root,
55
55
  config: viteConfigPath,
56
- // Pass reporters from config so NxReporter can be merged without losing config reporters
57
- // Safe: CLI options override (not merge with) config reporters, so no duplication
58
- reporters: resolved?.config?.['test']?.reporters,
56
+ // Vitest's resolveConfig processes reporters in two steps:
57
+ // 1. options.reporters (plural) sets resolved.reporters
58
+ // 2. resolved.reporter (singular, from config) overwrites resolved.reporters
59
+ // Setting reporter to [] prevents config's reporter from overriding NxReporter
60
+ // (which is pushed onto reporters in vitest.impl.ts).
61
+ reporter: [],
62
+ reporters: reporter ??
63
+ reporters ??
64
+ // reporter (singular) has higher priority in vitest but is not declared in InlineConfig
65
+ resolved?.config?.['test']?.reporter ??
66
+ resolved?.config?.['test']?.reporters,
59
67
  coverage: {
60
68
  ...(coverage ?? {}),
61
69
  ...(reportsDirectory && { reportsDirectory }),
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EASjB,IAAI,EAGL,MAAM,YAAY,CAAC;AAcpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAmCjD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAOlB;AAED,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAuMlB;AAgMD,eAAe,sBAAsB,CAAC"}
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../packages/vitest/src/generators/configuration/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EASjB,IAAI,EAGL,MAAM,YAAY,CAAC;AAcpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAmCjD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAOlB;AAED,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,SAAS,UAAQ,8BAmNlB;AAuOD,eAAe,sBAAsB,CAAC"}
@@ -68,10 +68,19 @@ async function configurationGeneratorInternal(tree, schema, hasPlugin = false) {
68
68
  const relativeTestSetupPath = (0, devkit_1.joinPathFragments)('src', 'test-setup.ts');
69
69
  const setupFile = (0, devkit_1.joinPathFragments)(root, relativeTestSetupPath);
70
70
  if (!tree.exists(setupFile)) {
71
- if (isAngularV20(tree)) {
71
+ const angularMajorVersion = getAngularMajorVersion(tree);
72
+ const zoneless = schema.zoneless ?? isZonelessProject(tree, schema.project);
73
+ if (angularMajorVersion >= 21) {
72
74
  tree.write(setupFile, `import '@angular/compiler';
73
- import '@analogjs/vitest-angular/setup-zone';
75
+ import '@analogjs/vitest-angular/setup-snapshots';
76
+ import { setupTestBed } from '@analogjs/vitest-angular/setup-testbed';
74
77
 
78
+ setupTestBed(${zoneless ? '' : '{ zoneless: false }'});
79
+ `);
80
+ }
81
+ else if (angularMajorVersion === 20) {
82
+ tree.write(setupFile, `import '@angular/compiler';
83
+ import '@analogjs/vitest-angular/${zoneless ? 'setup-snapshots' : 'setup-zone'}';
75
84
  import {
76
85
  BrowserTestingModule,
77
86
  platformBrowserTesting,
@@ -80,13 +89,12 @@ import { getTestBed } from '@angular/core/testing';
80
89
 
81
90
  getTestBed().initTestEnvironment(
82
91
  BrowserTestingModule,
83
- platformBrowserTesting()
92
+ platformBrowserTesting(),
84
93
  );
85
94
  `);
86
95
  }
87
96
  else {
88
- tree.write(setupFile, `import '@analogjs/vitest-angular/setup-zone';
89
-
97
+ tree.write(setupFile, `import '@analogjs/vitest-angular/${zoneless ? 'setup-snapshots' : 'setup-zone'}';
90
98
  import {
91
99
  BrowserDynamicTestingModule,
92
100
  platformBrowserDynamicTesting,
@@ -95,7 +103,7 @@ import { getTestBed } from '@angular/core/testing';
95
103
 
96
104
  getTestBed().initTestEnvironment(
97
105
  BrowserDynamicTestingModule,
98
- platformBrowserDynamicTesting()
106
+ platformBrowserDynamicTesting(),
99
107
  );
100
108
  `);
101
109
  }
@@ -302,17 +310,47 @@ function tryFindSetupFile(tree, projectRoot) {
302
310
  return setupFile;
303
311
  }
304
312
  }
305
- function isAngularV20(tree) {
313
+ function getAngularMajorVersion(tree) {
306
314
  const angularVersion = (0, devkit_1.getDependencyVersionFromPackageJson)(tree, '@angular/core');
307
315
  if (!angularVersion) {
308
- // assume the latest version will be installed, which will be 20 or later
309
- return true;
316
+ // assume the latest version will be installed
317
+ return 21;
310
318
  }
311
- const cleanedAngularVersion = (0, semver_1.clean)(angularVersion) ?? (0, semver_1.coerce)(angularVersion).version;
319
+ const cleanedAngularVersion = (0, semver_1.clean)(angularVersion) ?? (0, semver_1.coerce)(angularVersion)?.version;
312
320
  if (typeof cleanedAngularVersion !== 'string') {
313
- // assume the latest version will be installed,
314
- return true;
321
+ // assume the latest version will be installed
322
+ return 21;
323
+ }
324
+ return (0, semver_1.major)(cleanedAngularVersion);
325
+ }
326
+ function isZonelessProject(tree, projectName) {
327
+ const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
328
+ if (project.projectType === 'application') {
329
+ const buildTarget = findBuildTarget(project);
330
+ if (!buildTarget?.options?.polyfills) {
331
+ return true;
332
+ }
333
+ const polyfills = buildTarget.options.polyfills;
334
+ const polyfillsList = Array.isArray(polyfills) ? polyfills : [polyfills];
335
+ return !polyfillsList.includes('zone.js');
336
+ }
337
+ // For libraries, check if zone.js is installed in the workspace
338
+ return (0, devkit_1.getDependencyVersionFromPackageJson)(tree, 'zone.js') === null;
339
+ }
340
+ function findBuildTarget(project) {
341
+ for (const target of Object.values(project.targets ?? {})) {
342
+ if ([
343
+ '@angular-devkit/build-angular:browser',
344
+ '@angular-devkit/build-angular:browser-esbuild',
345
+ '@angular-devkit/build-angular:application',
346
+ '@angular/build:application',
347
+ '@nx/angular:application',
348
+ '@nx/angular:browser-esbuild',
349
+ '@nx/angular:webpack-browser',
350
+ ].includes(target.executor)) {
351
+ return target;
352
+ }
315
353
  }
316
- return (0, semver_1.major)(cleanedAngularVersion) >= 20;
354
+ return project.targets?.build ?? null;
317
355
  }
318
356
  exports.default = configurationGenerator;
@@ -14,4 +14,5 @@ export interface VitestGeneratorSchema {
14
14
  // internal options
15
15
  projectType?: 'application' | 'library';
16
16
  viteVersion?: 5 | 6 | 7;
17
+ zoneless?: boolean;
17
18
  }
@@ -65,6 +65,11 @@
65
65
  "default": false,
66
66
  "description": "Do not add dependencies to `package.json`.",
67
67
  "x-priority": "internal"
68
+ },
69
+ "zoneless": {
70
+ "type": "boolean",
71
+ "description": "Whether the Angular project is zoneless. When not provided, it is auto-detected from the project configuration.",
72
+ "x-priority": "internal"
68
73
  }
69
74
  },
70
75
  "required": ["project"]