@nx/jest 20.3.0 → 20.4.0-beta.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2024 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2025 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "20.3.0",
3
+ "version": "20.4.0-beta.0",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Jest contains executors and generators allowing your workspace to use the powerful Jest testing capabilities.",
6
6
  "repository": {
@@ -37,15 +37,15 @@
37
37
  "dependencies": {
38
38
  "@jest/reporters": "^29.4.1",
39
39
  "@jest/test-result": "^29.4.1",
40
- "@nx/devkit": "20.3.0",
41
- "@nx/js": "20.3.0",
40
+ "@nx/devkit": "20.4.0-beta.0",
41
+ "@nx/js": "20.4.0-beta.0",
42
42
  "@phenomnomnominal/tsquery": "~5.0.1",
43
- "chalk": "^4.1.0",
44
43
  "identity-obj-proxy": "3.0.0",
45
44
  "jest-config": "^29.4.1",
46
45
  "jest-resolve": "^29.4.1",
47
46
  "jest-util": "^29.4.1",
48
47
  "minimatch": "9.0.3",
48
+ "picocolors": "^1.1.0",
49
49
  "resolve.exports": "2.0.3",
50
50
  "semver": "^7.5.3",
51
51
  "tslib": "^2.3.0",
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSummary = void 0;
4
4
  const jest_util_1 = require("jest-util");
5
- const chalk = require("chalk");
5
+ const pc = require("picocolors");
6
6
  /**
7
7
  * Copied from the jest repo because these utility functions are not exposed through the package
8
8
  * https://github.com/facebook/jest/blob/7a64ede2163eba4ecc725f448cd92102cd8c14aa/packages/jest-reporters/src/utils.ts
@@ -46,9 +46,9 @@ const getValuesCurrentTestCases = (currentTestCases = []) => {
46
46
  const renderTime = (runTime, estimatedTime, width) => {
47
47
  // If we are more than one second over the estimated time, highlight it.
48
48
  const renderedTime = estimatedTime && runTime >= estimatedTime + 1
49
- ? chalk.bold.yellow((0, jest_util_1.formatTime)(runTime, 0))
49
+ ? pc.bold(pc.yellow((0, jest_util_1.formatTime)(runTime, 0)))
50
50
  : (0, jest_util_1.formatTime)(runTime, 0);
51
- let time = chalk.bold(`Time:`) + ` ${renderedTime}`;
51
+ let time = pc.bold(`Time:`) + ` ${renderedTime}`;
52
52
  if (runTime < estimatedTime) {
53
53
  time += `, estimated ${(0, jest_util_1.formatTime)(estimatedTime, 0)}`;
54
54
  }
@@ -60,8 +60,8 @@ const renderTime = (runTime, estimatedTime, width) => {
60
60
  if (availableWidth >= 2) {
61
61
  time +=
62
62
  '\n' +
63
- chalk.green('█').repeat(length) +
64
- chalk.white('█').repeat(availableWidth - length);
63
+ pc.green('█').repeat(length) +
64
+ pc.white('█').repeat(availableWidth - length);
65
65
  }
66
66
  }
67
67
  return time;
@@ -93,12 +93,12 @@ const getSummary = (aggregatedResults, options) => {
93
93
  const testsTodo = aggregatedResults.numTodoTests;
94
94
  const testsTotal = aggregatedResults.numTotalTests;
95
95
  const width = options?.width || 0;
96
- const suites = chalk.bold('Test Suites: ') +
97
- (suitesFailed ? chalk.bold.red(`${suitesFailed} failed`) + ', ' : '') +
96
+ const suites = pc.bold('Test Suites: ') +
97
+ (suitesFailed ? pc.bold(pc.red(`${suitesFailed} failed`)) + ', ' : '') +
98
98
  (suitesPending
99
- ? chalk.bold.yellow(`${suitesPending} skipped`) + ', '
99
+ ? pc.bold(pc.yellow(`${suitesPending} skipped`)) + ', '
100
100
  : '') +
101
- (suitesPassed ? chalk.bold.green(`${suitesPassed} passed`) + ', ' : '') +
101
+ (suitesPassed ? pc.bold(pc.green(`${suitesPassed} passed`)) + ', ' : '') +
102
102
  (suitesRun !== suitesTotal
103
103
  ? suitesRun + ' of ' + suitesTotal
104
104
  : suitesTotal) +
@@ -108,44 +108,44 @@ const getSummary = (aggregatedResults, options) => {
108
108
  const updatedTestsTodo = testsTodo + numTodoTests;
109
109
  const updatedTestsPassed = testsPassed + numPassingTests;
110
110
  const updatedTestsTotal = testsTotal + numTotalTests;
111
- const tests = chalk.bold('Tests: ') +
111
+ const tests = pc.bold('Tests: ') +
112
112
  (updatedTestsFailed > 0
113
- ? chalk.bold.red(`${updatedTestsFailed} failed`) + ', '
113
+ ? pc.bold(pc.red(`${updatedTestsFailed} failed`)) + ', '
114
114
  : '') +
115
115
  (updatedTestsPending > 0
116
- ? chalk.bold.yellow(`${updatedTestsPending} skipped`) + ', '
116
+ ? pc.bold(pc.yellow(`${updatedTestsPending} skipped`)) + ', '
117
117
  : '') +
118
118
  (updatedTestsTodo > 0
119
- ? chalk.bold.magenta(`${updatedTestsTodo} todo`) + ', '
119
+ ? pc.bold(pc.magenta(`${updatedTestsTodo} todo`)) + ', '
120
120
  : '') +
121
121
  (updatedTestsPassed > 0
122
- ? chalk.bold.green(`${updatedTestsPassed} passed`) + ', '
122
+ ? pc.bold(pc.green(`${updatedTestsPassed} passed`)) + ', '
123
123
  : '') +
124
124
  `${updatedTestsTotal} total`;
125
- const snapshots = chalk.bold('Snapshots: ') +
125
+ const snapshots = pc.bold('Snapshots: ') +
126
126
  (snapshotsFailed
127
- ? chalk.bold.red(`${snapshotsFailed} failed`) + ', '
127
+ ? pc.bold(pc.red(`${snapshotsFailed} failed`)) + ', '
128
128
  : '') +
129
129
  (snapshotsOutdated && !snapshotsDidUpdate
130
- ? chalk.bold.yellow(`${snapshotsOutdated} obsolete`) + ', '
130
+ ? pc.bold(pc.yellow(`${snapshotsOutdated} obsolete`)) + ', '
131
131
  : '') +
132
132
  (snapshotsOutdated && snapshotsDidUpdate
133
- ? chalk.bold.green(`${snapshotsOutdated} removed`) + ', '
133
+ ? pc.bold(pc.green(`${snapshotsOutdated} removed`)) + ', '
134
134
  : '') +
135
135
  (snapshotsFilesRemoved && !snapshotsDidUpdate
136
- ? chalk.bold.yellow((0, jest_util_1.pluralize)('file', snapshotsFilesRemoved) + ' obsolete') + ', '
136
+ ? pc.bold(pc.yellow((0, jest_util_1.pluralize)('file', snapshotsFilesRemoved) + ' obsolete')) + ', '
137
137
  : '') +
138
138
  (snapshotsFilesRemoved && snapshotsDidUpdate
139
- ? chalk.bold.green((0, jest_util_1.pluralize)('file', snapshotsFilesRemoved) + ' removed') + ', '
139
+ ? pc.bold(pc.green((0, jest_util_1.pluralize)('file', snapshotsFilesRemoved) + ' removed')) + ', '
140
140
  : '') +
141
141
  (snapshotsUpdated
142
- ? chalk.bold.green(`${snapshotsUpdated} updated`) + ', '
142
+ ? pc.bold(pc.green(`${snapshotsUpdated} updated`)) + ', '
143
143
  : '') +
144
144
  (snapshotsAdded
145
- ? chalk.bold.green(`${snapshotsAdded} written`) + ', '
145
+ ? pc.bold(pc.green(`${snapshotsAdded} written`)) + ', '
146
146
  : '') +
147
147
  (snapshotsPassed
148
- ? chalk.bold.green(`${snapshotsPassed} passed`) + ', '
148
+ ? pc.bold(pc.green(`${snapshotsPassed} passed`)) + ', '
149
149
  : '') +
150
150
  `${snapshotsTotal} total`;
151
151
  const time = renderTime(runTime, estimatedTime, width);
@@ -49,7 +49,7 @@ function createFiles(tree, options, presetExt) {
49
49
  ? `${rootOffset}tsconfig.base.json`
50
50
  : './tsconfig.json',
51
51
  outDir: isTsSolutionSetup ? `./out-tsc/jest` : `${rootOffset}dist/out-tsc`,
52
- module: !isTsSolutionSetup ? 'commonjs' : undefined,
52
+ module: !isTsSolutionSetup || transformer === 'ts-jest' ? 'commonjs' : undefined,
53
53
  });
54
54
  if (options.setupFile === 'none') {
55
55
  tree.delete((0, path_1.join)(projectConfig.root, './src/test-setup.ts'));
@@ -2,6 +2,10 @@ import { CreateNodes, CreateNodesV2 } from '@nx/devkit';
2
2
  export interface JestPluginOptions {
3
3
  targetName?: string;
4
4
  ciTargetName?: string;
5
+ /**
6
+ * The name that should be used to group atomized tasks on CI
7
+ */
8
+ ciGroupName?: string;
5
9
  /**
6
10
  * Whether to use jest-config and jest-runtime to load Jest configuration and context.
7
11
  * Disabling this is much faster but could be less correct since we are using our own config loader
@@ -119,7 +119,7 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
119
119
  const cache = (target.cache = true);
120
120
  const inputs = (target.inputs = getInputs(namedInputs, rawConfig.preset, projectRoot, context.workspaceRoot, options.disableJestRuntime));
121
121
  let metadata;
122
- const groupName = 'E2E (CI)';
122
+ const groupName = options?.ciGroupName ?? deductGroupNameFromTarget(options?.ciTargetName);
123
123
  if (options.disableJestRuntime) {
124
124
  const outputs = (target.outputs = getOutputs(projectRoot, rawConfig.coverageDirectory
125
125
  ? (0, path_1.join)(context.workspaceRoot, projectRoot, rawConfig.coverageDirectory)
@@ -452,3 +452,24 @@ async function getJestOption(rawConfig, absConfigFilePath, optionName, presetCac
452
452
  }
453
453
  return undefined;
454
454
  }
455
+ /**
456
+ * Helper that tries to deduct the name of the CI group, based on the related target name.
457
+ *
458
+ * This will work well, when the CI target name follows the documented naming convention or similar (for e.g `test-ci`, `e2e-ci`, `ny-e2e-ci`, etc).
459
+ *
460
+ * For example, `test-ci` => `TEST (CI)`, `e2e-ci` => `E2E (CI)`, `my-e2e-ci` => `MY E2E (CI)`
461
+ *
462
+ *
463
+ * @param ciTargetName name of the CI target
464
+ * @returns the deducted group name or `${ciTargetName.toUpperCase()} (CI)` if cannot be deducted automatically
465
+ */
466
+ function deductGroupNameFromTarget(ciTargetName) {
467
+ if (!ciTargetName) {
468
+ return null;
469
+ }
470
+ const parts = ciTargetName.split('-').map((v) => v.toUpperCase());
471
+ if (parts.length > 1) {
472
+ return `${parts.slice(0, -1).join(' ')} (${parts[parts.length - 1]})`;
473
+ }
474
+ return `${parts[0]} (CI)`; // default group name when there is a single segment
475
+ }