@nx/jest 0.0.0-pr-22179-271588f

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.
Files changed (80) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/executors.json +10 -0
  4. package/generators.json +19 -0
  5. package/index.d.ts +8 -0
  6. package/index.js +19 -0
  7. package/migrations.json +105 -0
  8. package/package.json +57 -0
  9. package/plugin.d.ts +1 -0
  10. package/plugin.js +6 -0
  11. package/plugins/resolver.d.ts +1 -0
  12. package/plugins/resolver.js +58 -0
  13. package/preset/index.d.ts +2 -0
  14. package/preset/index.js +4 -0
  15. package/preset/jest-preset.d.ts +2 -0
  16. package/preset/jest-preset.js +33 -0
  17. package/src/executors/jest/jest.impl.d.ts +10 -0
  18. package/src/executors/jest/jest.impl.js +179 -0
  19. package/src/executors/jest/schema.d.ts +44 -0
  20. package/src/executors/jest/schema.json +226 -0
  21. package/src/executors/jest/summary.d.ts +7 -0
  22. package/src/executors/jest/summary.js +154 -0
  23. package/src/generators/configuration/configuration.d.ts +5 -0
  24. package/src/generators/configuration/configuration.js +90 -0
  25. package/src/generators/configuration/files/jest.config.ts__tmpl__ +16 -0
  26. package/src/generators/configuration/files/src/test-setup.ts__tmpl__ +0 -0
  27. package/src/generators/configuration/files/tsconfig.spec.json__tmpl__ +21 -0
  28. package/src/generators/configuration/files-angular/jest.config.ts__tmpl__ +27 -0
  29. package/src/generators/configuration/files-angular/src/test-setup.ts__tmpl__ +1 -0
  30. package/src/generators/configuration/files-angular/tsconfig.spec.json__tmpl__ +22 -0
  31. package/src/generators/configuration/lib/check-for-test-target.d.ts +3 -0
  32. package/src/generators/configuration/lib/check-for-test-target.js +11 -0
  33. package/src/generators/configuration/lib/create-files.d.ts +3 -0
  34. package/src/generators/configuration/lib/create-files.js +47 -0
  35. package/src/generators/configuration/lib/create-jest-config.d.ts +3 -0
  36. package/src/generators/configuration/lib/create-jest-config.js +102 -0
  37. package/src/generators/configuration/lib/ensure-dependencies.d.ts +3 -0
  38. package/src/generators/configuration/lib/ensure-dependencies.js +34 -0
  39. package/src/generators/configuration/lib/update-jestconfig.d.ts +3 -0
  40. package/src/generators/configuration/lib/update-jestconfig.js +26 -0
  41. package/src/generators/configuration/lib/update-tsconfig.d.ts +3 -0
  42. package/src/generators/configuration/lib/update-tsconfig.js +21 -0
  43. package/src/generators/configuration/lib/update-vscode-recommended-extensions.d.ts +2 -0
  44. package/src/generators/configuration/lib/update-vscode-recommended-extensions.js +18 -0
  45. package/src/generators/configuration/lib/update-workspace.d.ts +3 -0
  46. package/src/generators/configuration/lib/update-workspace.js +23 -0
  47. package/src/generators/configuration/schema.d.ts +31 -0
  48. package/src/generators/configuration/schema.json +80 -0
  49. package/src/generators/init/init.d.ts +5 -0
  50. package/src/generators/init/init.js +106 -0
  51. package/src/generators/init/schema.d.ts +8 -0
  52. package/src/generators/init/schema.json +35 -0
  53. package/src/migrations/update-15-0-0/add-jest-inputs.d.ts +2 -0
  54. package/src/migrations/update-15-0-0/add-jest-inputs.js +41 -0
  55. package/src/migrations/update-15-8-0/update-configs-jest-29.d.ts +3 -0
  56. package/src/migrations/update-15-8-0/update-configs-jest-29.js +146 -0
  57. package/src/migrations/update-15-8-0/update-tests-jest-29.d.ts +5 -0
  58. package/src/migrations/update-15-8-0/update-tests-jest-29.js +60 -0
  59. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  60. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  61. package/src/migrations/update-16-5-0/add-test-setup-to-inputs-ignore.d.ts +3 -0
  62. package/src/migrations/update-16-5-0/add-test-setup-to-inputs-ignore.js +18 -0
  63. package/src/migrations/update-17-1-0/move-options-to-target-defaults.d.ts +2 -0
  64. package/src/migrations/update-17-1-0/move-options-to-target-defaults.js +117 -0
  65. package/src/plugins/plugin.d.ts +6 -0
  66. package/src/plugins/plugin.js +130 -0
  67. package/src/utils/ast-utils.d.ts +9 -0
  68. package/src/utils/ast-utils.js +32 -0
  69. package/src/utils/config/find-root-jest-files.d.ts +3 -0
  70. package/src/utils/config/find-root-jest-files.js +23 -0
  71. package/src/utils/config/functions.d.ts +17 -0
  72. package/src/utils/config/functions.js +211 -0
  73. package/src/utils/config/get-jest-projects.d.ts +34 -0
  74. package/src/utils/config/get-jest-projects.js +157 -0
  75. package/src/utils/config/is-preset-cjs.d.ts +2 -0
  76. package/src/utils/config/is-preset-cjs.js +15 -0
  77. package/src/utils/config/update-config.d.ts +20 -0
  78. package/src/utils/config/update-config.js +83 -0
  79. package/src/utils/versions.d.ts +9 -0
  80. package/src/utils/versions.js +12 -0
@@ -0,0 +1,44 @@
1
+ export interface JestExecutorOptions {
2
+ codeCoverage?: boolean;
3
+ config?: string;
4
+ detectOpenHandles?: boolean;
5
+ logHeapUsage?: boolean;
6
+ detectLeaks?: boolean;
7
+ jestConfig: string;
8
+ testFile?: string;
9
+ /**
10
+ * @deprecated set in the jest config file instead
11
+ **/
12
+ setupFile?: string;
13
+ bail?: boolean | number;
14
+ ci?: boolean;
15
+ color?: boolean;
16
+ clearCache?: boolean;
17
+ findRelatedTests?: string;
18
+ forceExit?: boolean;
19
+ json?: boolean;
20
+ maxWorkers?: number | string;
21
+ onlyChanged?: boolean;
22
+ changedSince?: string;
23
+ outputFile?: string;
24
+ passWithNoTests?: boolean;
25
+ randomize?: boolean;
26
+ runInBand?: boolean;
27
+ showConfig?: boolean;
28
+ silent?: boolean;
29
+ testNamePattern?: string;
30
+ testPathIgnorePatterns?: string[];
31
+ testPathPattern?: string[];
32
+ colors?: boolean;
33
+ reporters?: string[];
34
+ verbose?: boolean;
35
+ coverageReporters?: string[];
36
+ coverageDirectory?: string;
37
+ testResultsProcessor?: string;
38
+ updateSnapshot?: boolean;
39
+ useStderr?: boolean;
40
+ watch?: boolean;
41
+ watchAll?: boolean;
42
+ testLocationInResults?: boolean;
43
+ testTimeout?: number;
44
+ }
@@ -0,0 +1,226 @@
1
+ {
2
+ "version": 2,
3
+ "outputCapture": "direct-nodejs",
4
+ "title": "Jest Builder",
5
+ "description": "Jest target options for Build Facade.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "presets": [
9
+ {
10
+ "name": "Pass Without Tests",
11
+ "keys": ["jestConfig", "passWithNoTests"]
12
+ },
13
+ {
14
+ "name": "Code Coverage",
15
+ "keys": ["jestConfig", "coverageReporters"]
16
+ },
17
+ {
18
+ "name": "Stop After 'n' Failed",
19
+ "keys": ["jestConfig", "bail"]
20
+ }
21
+ ],
22
+ "properties": {
23
+ "codeCoverage": {
24
+ "description": "Indicates that test coverage information should be collected and reported in the output. (https://jestjs.io/docs/cli#--coverageboolean)",
25
+ "type": "boolean",
26
+ "aliases": ["coverage"]
27
+ },
28
+ "config": {
29
+ "description": "The path to a Jest config file specifying how to find and execute tests. If no `rootDir` is set in the config, the directory containing the config file is assumed to be the `rootDir` for the project. This can also be a JSON-encoded value which Jest will use as configuration.",
30
+ "type": "string"
31
+ },
32
+ "clearCache": {
33
+ "description": "Deletes the Jest cache directory and then exits without running tests. Will delete Jest's default cache directory. _Note: clearing the cache will reduce performance_.",
34
+ "type": "boolean"
35
+ },
36
+ "detectOpenHandles": {
37
+ "description": "Attempt to collect and print open handles preventing Jest from exiting cleanly (https://jestjs.io/docs/cli#--detectopenhandles)",
38
+ "type": "boolean"
39
+ },
40
+ "logHeapUsage": {
41
+ "description": "Logs the heap usage after every test. Useful to debug memory leaks. Use together with --runInBand and --expose-gc in node.",
42
+ "type": "boolean"
43
+ },
44
+ "detectLeaks": {
45
+ "description": "**EXPERIMENTAL**: Detect memory leaks in tests. After executing a test, it will try to garbage collect the global object used, and fail if it was leaked",
46
+ "type": "boolean"
47
+ },
48
+ "jestConfig": {
49
+ "description": "The path of the Jest configuration. (https://jestjs.io/docs/en/configuration)",
50
+ "type": "string",
51
+ "x-completion-type": "file",
52
+ "x-completion-glob": "jest.config@(.js|.ts)"
53
+ },
54
+ "testFile": {
55
+ "description": "The name of the file to test.",
56
+ "type": "string"
57
+ },
58
+ "tsConfig": {
59
+ "description": "The name of the Typescript configuration file.",
60
+ "type": "string",
61
+ "x-deprecated": "Use the ts-jest configuration options in the jest config file instead."
62
+ },
63
+ "setupFile": {
64
+ "description": "The name of a setup file used by Jest.",
65
+ "type": "string",
66
+ "x-deprecated": "Use the setupFilesAfterEnv option in the jest config file. https://jestjs.io/docs/en/configuration#setupfilesafterenv-array"
67
+ },
68
+ "bail": {
69
+ "alias": "b",
70
+ "description": "Exit the test suite immediately after `n` number of failing tests. (https://jestjs.io/docs/cli#--bail)",
71
+ "oneOf": [
72
+ {
73
+ "type": "number"
74
+ },
75
+ {
76
+ "type": "boolean"
77
+ }
78
+ ]
79
+ },
80
+ "ci": {
81
+ "description": "Whether to run Jest in continuous integration (CI) mode. This option is on by default in most popular CI environments. It will prevent snapshots from being written unless explicitly requested. (https://jestjs.io/docs/cli#--ci)",
82
+ "type": "boolean"
83
+ },
84
+ "color": {
85
+ "alias": "colors",
86
+ "description": "Forces test results output color highlighting (even if `stdout` is not a TTY). Set to false if you would like to have no colors. (https://jestjs.io/docs/cli#--colors)",
87
+ "type": "boolean"
88
+ },
89
+ "findRelatedTests": {
90
+ "description": "Find and run the tests that cover a comma separated list of source files that were passed in as arguments. (https://jestjs.io/docs/cli#--findrelatedtests-spaceseparatedlistofsourcefiles)",
91
+ "type": "string"
92
+ },
93
+ "forceExit": {
94
+ "description": "Force Jest to exit after all tests have completed running. This is useful when resources set up by test code cannot be adequately cleaned up.This feature is an escape-hatch. If Jest doesn't exit at the end of a test run, it means external resources are still being held on to or timers are still pending in your code. It is advised to tear down external resources after each test to make sure Jest can shut down cleanly. You can use --detectOpenHandles to help track it down.",
95
+ "type": "boolean"
96
+ },
97
+ "json": {
98
+ "description": "Prints the test results in `JSON`. This mode will send all other test output and user messages to `stderr`. (https://jestjs.io/docs/cli#--json)",
99
+ "type": "boolean"
100
+ },
101
+ "maxWorkers": {
102
+ "alias": "w",
103
+ "description": "Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. Useful for CI. (its usually best not to override this default) (https://jestjs.io/docs/cli#--maxworkersnumstring)",
104
+ "oneOf": [
105
+ {
106
+ "type": "number"
107
+ },
108
+ {
109
+ "type": "string"
110
+ }
111
+ ]
112
+ },
113
+ "onlyChanged": {
114
+ "alias": "o",
115
+ "description": "Attempts to identify which tests to run based on which files have changed in the current repository. Only works if you're running tests in a `git` or `hg` repository at the moment. (https://jestjs.io/docs/cli#--onlychanged)",
116
+ "type": "boolean"
117
+ },
118
+ "changedSince": {
119
+ "description": "Runs tests related to the changes since the provided branch or commit hash. If the current branch has diverged from the given branch, then only changes made locally will be tested. (https://jestjs.io/docs/cli#--changedsince)",
120
+ "type": "string"
121
+ },
122
+ "outputFile": {
123
+ "description": "Write test results to a file when the `--json` option is also specified. (https://jestjs.io/docs/cli#--outputfilefilename)",
124
+ "type": "string"
125
+ },
126
+ "passWithNoTests": {
127
+ "description": "Will not fail if no tests are found (for example while using `--testPathPattern`.) (https://jestjs.io/docs/cli#--passwithnotests)",
128
+ "type": "boolean"
129
+ },
130
+ "randomize": {
131
+ "description": "Shuffle the order of the tests within a file. The shuffling is based on the seed. This option is only supported using the default jest-circus test runner.",
132
+ "type": "boolean"
133
+ },
134
+ "runInBand": {
135
+ "alias": "i",
136
+ "description": "Run all tests serially in the current process (rather than creating a worker pool of child processes that run tests). This is sometimes useful for debugging, but such use cases are pretty rare. Useful for CI. (https://jestjs.io/docs/cli#--runinband)",
137
+ "type": "boolean"
138
+ },
139
+ "showConfig": {
140
+ "description": "Print your Jest config and then exits. (https://jestjs.io/docs/en/cli#--showconfig)",
141
+ "type": "boolean"
142
+ },
143
+ "silent": {
144
+ "description": "Prevent tests from printing messages through the console. (https://jestjs.io/docs/cli#--silent)",
145
+ "type": "boolean"
146
+ },
147
+ "testNamePattern": {
148
+ "alias": "t",
149
+ "description": "Run only tests with a name that matches the regex pattern. (https://jestjs.io/docs/cli#--testnamepatternregex)",
150
+ "type": "string"
151
+ },
152
+ "testPathIgnorePatterns": {
153
+ "description": "An array of regexp pattern strings that is matched against all tests paths before executing the test. Only run those tests with a path that does not match with the provided regexp expressions. (https://jestjs.io/docs/cli#--testpathignorepatternsregexarray)",
154
+ "type": "array",
155
+ "items": {
156
+ "type": "string"
157
+ }
158
+ },
159
+ "testPathPattern": {
160
+ "description": "An array of regexp pattern strings that is matched against all tests paths before executing the test. (https://jestjs.io/docs/cli#--testpathpatternregex)",
161
+ "type": "array",
162
+ "items": {
163
+ "type": "string"
164
+ },
165
+ "default": []
166
+ },
167
+ "colors": {
168
+ "description": "Forces test results output highlighting even if stdout is not a TTY. (https://jestjs.io/docs/cli#--colors)",
169
+ "type": "boolean"
170
+ },
171
+ "reporters": {
172
+ "description": "Run tests with specified reporters. Reporter options are not available via CLI. Example with multiple reporters: `jest --reporters=\"default\" --reporters=\"jest-junit\"`. (https://jestjs.io/docs/cli#--reporters)",
173
+ "type": "array",
174
+ "items": {
175
+ "type": "string"
176
+ }
177
+ },
178
+ "verbose": {
179
+ "description": "Display individual test results with the test suite hierarchy. (https://jestjs.io/docs/cli#--verbose)",
180
+ "type": "boolean"
181
+ },
182
+ "coverageReporters": {
183
+ "description": "A list of reporter names that Jest uses when writing coverage reports. Any istanbul reporter.",
184
+ "type": "array",
185
+ "items": {
186
+ "type": "string"
187
+ }
188
+ },
189
+ "coverageDirectory": {
190
+ "description": "The directory where Jest should output its coverage files.",
191
+ "type": "string",
192
+ "x-completion-type": "directory"
193
+ },
194
+ "testResultsProcessor": {
195
+ "description": "Node module that implements a custom results processor. (https://jestjs.io/docs/en/configuration#testresultsprocessor-string)",
196
+ "type": "string"
197
+ },
198
+ "updateSnapshot": {
199
+ "alias": "u",
200
+ "description": "Use this flag to re-record snapshots. Can be used together with a test suite pattern or with `--testNamePattern` to re-record snapshot for test matching the pattern. (https://jestjs.io/docs/cli#--updatesnapshot)",
201
+ "type": "boolean"
202
+ },
203
+ "useStderr": {
204
+ "description": "Divert all output to stderr.",
205
+ "type": "boolean"
206
+ },
207
+ "watch": {
208
+ "description": "Watch files for changes and rerun tests related to changed files. If you want to re-run all tests when a file has changed, use the `--watchAll` option. (https://jestjs.io/docs/cli#--watch)",
209
+ "type": "boolean"
210
+ },
211
+ "watchAll": {
212
+ "description": "Watch files for changes and rerun all tests when something changes. If you want to re-run only the tests that depend on the changed files, use the `--watch` option. (https://jestjs.io/docs/cli#--watchall)",
213
+ "type": "boolean"
214
+ },
215
+ "testLocationInResults": {
216
+ "description": "Adds a location field to test results. Used to report location of a test in a reporter. { \"column\": 4, \"line\": 5 } (https://jestjs.io/docs/cli#--testlocationinresults)",
217
+ "type": "boolean"
218
+ },
219
+ "testTimeout": {
220
+ "description": "Default timeout of a test in milliseconds. Default value: `5000`. (https://jestjs.io/docs/cli#--testtimeoutnumber)",
221
+ "type": "number"
222
+ }
223
+ },
224
+ "required": ["jestConfig"],
225
+ "examplesFile": "../../../docs/jest-examples.md"
226
+ }
@@ -0,0 +1,7 @@
1
+ import { AggregatedResult } from '@jest/reporters';
2
+ export declare const getSummary: (aggregatedResults: AggregatedResult, options?: {
3
+ currentTestCases?: any;
4
+ estimatedTime?: number;
5
+ roundTime?: boolean;
6
+ width?: number;
7
+ }) => string;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSummary = void 0;
4
+ const jest_util_1 = require("jest-util");
5
+ const chalk = require("chalk");
6
+ /**
7
+ * Copied from the jest repo because these utility functions are not exposed through the package
8
+ * https://github.com/facebook/jest/blob/7a64ede2163eba4ecc725f448cd92102cd8c14aa/packages/jest-reporters/src/utils.ts
9
+ */
10
+ const PROGRESS_BAR_WIDTH = 40;
11
+ const getValuesCurrentTestCases = (currentTestCases = []) => {
12
+ let numFailingTests = 0;
13
+ let numPassingTests = 0;
14
+ let numPendingTests = 0;
15
+ let numTodoTests = 0;
16
+ let numTotalTests = 0;
17
+ currentTestCases.forEach((testCase) => {
18
+ switch (testCase.testCaseResult.status) {
19
+ case 'failed': {
20
+ numFailingTests++;
21
+ break;
22
+ }
23
+ case 'passed': {
24
+ numPassingTests++;
25
+ break;
26
+ }
27
+ case 'skipped': {
28
+ numPendingTests++;
29
+ break;
30
+ }
31
+ case 'todo': {
32
+ numTodoTests++;
33
+ break;
34
+ }
35
+ }
36
+ numTotalTests++;
37
+ });
38
+ return {
39
+ numFailingTests,
40
+ numPassingTests,
41
+ numPendingTests,
42
+ numTodoTests,
43
+ numTotalTests,
44
+ };
45
+ };
46
+ const renderTime = (runTime, estimatedTime, width) => {
47
+ // If we are more than one second over the estimated time, highlight it.
48
+ const renderedTime = estimatedTime && runTime >= estimatedTime + 1
49
+ ? chalk.bold.yellow((0, jest_util_1.formatTime)(runTime, 0))
50
+ : (0, jest_util_1.formatTime)(runTime, 0);
51
+ let time = chalk.bold(`Time:`) + ` ${renderedTime}`;
52
+ if (runTime < estimatedTime) {
53
+ time += `, estimated ${(0, jest_util_1.formatTime)(estimatedTime, 0)}`;
54
+ }
55
+ // Only show a progress bar if the test run is actually going to take
56
+ // some time.
57
+ if (estimatedTime > 2 && runTime < estimatedTime && width) {
58
+ const availableWidth = Math.min(PROGRESS_BAR_WIDTH, width);
59
+ const length = Math.min(Math.floor((runTime / estimatedTime) * availableWidth), availableWidth);
60
+ if (availableWidth >= 2) {
61
+ time +=
62
+ '\n' +
63
+ chalk.green('█').repeat(length) +
64
+ chalk.white('█').repeat(availableWidth - length);
65
+ }
66
+ }
67
+ return time;
68
+ };
69
+ const getSummary = (aggregatedResults, options) => {
70
+ let runTime = (Date.now() - aggregatedResults.startTime) / 1000;
71
+ if (options?.roundTime) {
72
+ runTime = Math.floor(runTime);
73
+ }
74
+ const { numFailingTests, numPendingTests, numTodoTests, numPassingTests, numTotalTests, } = getValuesCurrentTestCases(options?.currentTestCases);
75
+ const estimatedTime = options?.estimatedTime || 0;
76
+ const snapshotResults = aggregatedResults.snapshot;
77
+ const snapshotsAdded = snapshotResults.added;
78
+ const snapshotsFailed = snapshotResults.unmatched;
79
+ const snapshotsOutdated = snapshotResults.unchecked;
80
+ const snapshotsFilesRemoved = snapshotResults.filesRemoved;
81
+ const snapshotsDidUpdate = snapshotResults.didUpdate;
82
+ const snapshotsPassed = snapshotResults.matched;
83
+ const snapshotsTotal = snapshotResults.total;
84
+ const snapshotsUpdated = snapshotResults.updated;
85
+ const suitesFailed = aggregatedResults.numFailedTestSuites;
86
+ const suitesPassed = aggregatedResults.numPassedTestSuites;
87
+ const suitesPending = aggregatedResults.numPendingTestSuites;
88
+ const suitesRun = suitesFailed + suitesPassed;
89
+ const suitesTotal = aggregatedResults.numTotalTestSuites;
90
+ const testsFailed = aggregatedResults.numFailedTests;
91
+ const testsPassed = aggregatedResults.numPassedTests;
92
+ const testsPending = aggregatedResults.numPendingTests;
93
+ const testsTodo = aggregatedResults.numTodoTests;
94
+ const testsTotal = aggregatedResults.numTotalTests;
95
+ const width = options?.width || 0;
96
+ const suites = chalk.bold('Test Suites: ') +
97
+ (suitesFailed ? chalk.bold.red(`${suitesFailed} failed`) + ', ' : '') +
98
+ (suitesPending
99
+ ? chalk.bold.yellow(`${suitesPending} skipped`) + ', '
100
+ : '') +
101
+ (suitesPassed ? chalk.bold.green(`${suitesPassed} passed`) + ', ' : '') +
102
+ (suitesRun !== suitesTotal
103
+ ? suitesRun + ' of ' + suitesTotal
104
+ : suitesTotal) +
105
+ ` total`;
106
+ const updatedTestsFailed = testsFailed + numFailingTests;
107
+ const updatedTestsPending = testsPending + numPendingTests;
108
+ const updatedTestsTodo = testsTodo + numTodoTests;
109
+ const updatedTestsPassed = testsPassed + numPassingTests;
110
+ const updatedTestsTotal = testsTotal + numTotalTests;
111
+ const tests = chalk.bold('Tests: ') +
112
+ (updatedTestsFailed > 0
113
+ ? chalk.bold.red(`${updatedTestsFailed} failed`) + ', '
114
+ : '') +
115
+ (updatedTestsPending > 0
116
+ ? chalk.bold.yellow(`${updatedTestsPending} skipped`) + ', '
117
+ : '') +
118
+ (updatedTestsTodo > 0
119
+ ? chalk.bold.magenta(`${updatedTestsTodo} todo`) + ', '
120
+ : '') +
121
+ (updatedTestsPassed > 0
122
+ ? chalk.bold.green(`${updatedTestsPassed} passed`) + ', '
123
+ : '') +
124
+ `${updatedTestsTotal} total`;
125
+ const snapshots = chalk.bold('Snapshots: ') +
126
+ (snapshotsFailed
127
+ ? chalk.bold.red(`${snapshotsFailed} failed`) + ', '
128
+ : '') +
129
+ (snapshotsOutdated && !snapshotsDidUpdate
130
+ ? chalk.bold.yellow(`${snapshotsOutdated} obsolete`) + ', '
131
+ : '') +
132
+ (snapshotsOutdated && snapshotsDidUpdate
133
+ ? chalk.bold.green(`${snapshotsOutdated} removed`) + ', '
134
+ : '') +
135
+ (snapshotsFilesRemoved && !snapshotsDidUpdate
136
+ ? chalk.bold.yellow((0, jest_util_1.pluralize)('file', snapshotsFilesRemoved) + ' obsolete') + ', '
137
+ : '') +
138
+ (snapshotsFilesRemoved && snapshotsDidUpdate
139
+ ? chalk.bold.green((0, jest_util_1.pluralize)('file', snapshotsFilesRemoved) + ' removed') + ', '
140
+ : '') +
141
+ (snapshotsUpdated
142
+ ? chalk.bold.green(`${snapshotsUpdated} updated`) + ', '
143
+ : '') +
144
+ (snapshotsAdded
145
+ ? chalk.bold.green(`${snapshotsAdded} written`) + ', '
146
+ : '') +
147
+ (snapshotsPassed
148
+ ? chalk.bold.green(`${snapshotsPassed} passed`) + ', '
149
+ : '') +
150
+ `${snapshotsTotal} total`;
151
+ const time = renderTime(runTime, estimatedTime, width);
152
+ return [suites, tests, snapshots, time].join('\n');
153
+ };
154
+ exports.getSummary = getSummary;
@@ -0,0 +1,5 @@
1
+ import { JestProjectSchema } from './schema';
2
+ import { Tree, GeneratorCallback } from '@nx/devkit';
3
+ export declare function configurationGenerator(tree: Tree, schema: JestProjectSchema): Promise<GeneratorCallback>;
4
+ export declare function configurationGeneratorInternal(tree: Tree, schema: JestProjectSchema): Promise<GeneratorCallback>;
5
+ export default configurationGenerator;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configurationGeneratorInternal = exports.configurationGenerator = void 0;
4
+ const init_1 = require("../init/init");
5
+ const check_for_test_target_1 = require("./lib/check-for-test-target");
6
+ const create_files_1 = require("./lib/create-files");
7
+ const create_jest_config_1 = require("./lib/create-jest-config");
8
+ const ensure_dependencies_1 = require("./lib/ensure-dependencies");
9
+ const update_tsconfig_1 = require("./lib/update-tsconfig");
10
+ const update_vscode_recommended_extensions_1 = require("./lib/update-vscode-recommended-extensions");
11
+ const update_workspace_1 = require("./lib/update-workspace");
12
+ const devkit_1 = require("@nx/devkit");
13
+ const js_1 = require("@nx/js");
14
+ const is_preset_cjs_1 = require("../../utils/config/is-preset-cjs");
15
+ const schemaDefaults = {
16
+ setupFile: 'none',
17
+ babelJest: false,
18
+ supportTsx: false,
19
+ skipSetupFile: false,
20
+ skipSerializers: false,
21
+ testEnvironment: 'jsdom',
22
+ };
23
+ function normalizeOptions(tree, options) {
24
+ if (!options.testEnvironment) {
25
+ options.testEnvironment = 'jsdom';
26
+ }
27
+ const nxJson = (0, devkit_1.readNxJson)(tree);
28
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
29
+ nxJson.useInferencePlugins !== false;
30
+ options.addPlugin ??= addPlugin;
31
+ options.targetName ??= 'test';
32
+ if (!options.hasOwnProperty('supportTsx')) {
33
+ options.supportTsx = false;
34
+ }
35
+ // if we support TSX or compiler is not tsc, then we don't support angular(html templates)
36
+ if (options.supportTsx ||
37
+ options.babelJest ||
38
+ ['swc', 'babel'].includes(options.compiler)) {
39
+ options.skipSerializers = true;
40
+ }
41
+ if (options.skipSetupFile) {
42
+ // setupFile is always 'none'
43
+ options.setupFile = schemaDefaults.setupFile;
44
+ }
45
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
46
+ return {
47
+ ...schemaDefaults,
48
+ ...options,
49
+ rootProject: project.root === '.' || project.root === '',
50
+ };
51
+ }
52
+ function configurationGenerator(tree, schema) {
53
+ return configurationGeneratorInternal(tree, { addPlugin: false, ...schema });
54
+ }
55
+ exports.configurationGenerator = configurationGenerator;
56
+ async function configurationGeneratorInternal(tree, schema) {
57
+ const options = normalizeOptions(tree, schema);
58
+ const tasks = [];
59
+ tasks.push(await (0, js_1.initGenerator)(tree, { ...schema, skipFormat: true }));
60
+ tasks.push(await (0, init_1.jestInitGenerator)(tree, { ...options, skipFormat: true }));
61
+ if (!schema.skipPackageJson) {
62
+ tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, options));
63
+ }
64
+ const presetExt = (0, is_preset_cjs_1.isPresetCjs)(tree) ? 'cjs' : 'js';
65
+ await (0, create_jest_config_1.createJestConfig)(tree, options, presetExt);
66
+ (0, check_for_test_target_1.checkForTestTarget)(tree, options);
67
+ (0, create_files_1.createFiles)(tree, options, presetExt);
68
+ (0, update_tsconfig_1.updateTsConfig)(tree, options);
69
+ (0, update_vscode_recommended_extensions_1.updateVsCodeRecommendedExtensions)(tree);
70
+ const nxJson = (0, devkit_1.readNxJson)(tree);
71
+ const hasPlugin = nxJson.plugins?.some((p) => {
72
+ if (typeof p === 'string') {
73
+ return p === '@nx/jest/plugin' && options.targetName === 'test';
74
+ }
75
+ else {
76
+ return (p.plugin === '@nx/jest/plugin' &&
77
+ (p.options?.targetName ?? 'test') ===
78
+ options.targetName);
79
+ }
80
+ });
81
+ if (!hasPlugin || options.addExplicitTargets) {
82
+ (0, update_workspace_1.updateWorkspace)(tree, options);
83
+ }
84
+ if (!schema.skipFormat) {
85
+ await (0, devkit_1.formatFiles)(tree);
86
+ }
87
+ return (0, devkit_1.runTasksInSerial)(...tasks);
88
+ }
89
+ exports.configurationGeneratorInternal = configurationGeneratorInternal;
90
+ exports.default = configurationGenerator;
@@ -0,0 +1,16 @@
1
+ /* eslint-disable */
2
+ <% if(js){ %>module.exports =<% } else{ %>export default<% } %> {
3
+ displayName: '<%= project %>',
4
+ preset: '<%= offsetFromRoot %>jest.preset.<%= presetExt %>',<% if(setupFile !== 'none') { %>
5
+ setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],<% } %><% if(testEnvironment) { %>
6
+ testEnvironment: '<%= testEnvironment %>',<% } %><% if(skipSerializers){ %>
7
+ transform: {
8
+ <% if (supportTsx){ %>'^.+\\.[tj]sx?$'<% } else { %>'^.+\\.[tj]s$'<% } %>: <% if (transformerOptions) { %>['<%= transformer %>', <%- transformerOptions %>]<% } else { %>'<%= transformer %>'<% } %>
9
+ },
10
+ <% if (supportTsx) { %>moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],<% } else { %>moduleFileExtensions: ['ts', 'js', 'html'],<% } %><% } %>
11
+ coverageDirectory: '<%= offsetFromRoot %>coverage/<%= projectRoot %>'<% if(rootProject){ %>,
12
+ testMatch: [
13
+ '<rootDir>/src/**/__tests__/**/*.[jt]s?(x)',
14
+ '<rootDir>/src/**/*(*.)@(spec|test).[jt]s?(x)',
15
+ ],<% } %>
16
+ };
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },<% if(setupFile !== 'none') { %>
8
+ "files": ["src/test-setup.ts"],<% } %>
9
+ "include": [
10
+ "jest.config.ts",
11
+ "src/**/*.test.ts",
12
+ "src/**/*.spec.ts",<% if (supportTsx) { %>
13
+ "src/**/*.test.tsx",
14
+ "src/**/*.spec.tsx",
15
+ "src/**/*.test.js",
16
+ "src/**/*.spec.js",
17
+ "src/**/*.test.jsx",
18
+ "src/**/*.spec.jsx",<% } %>
19
+ "src/**/*.d.ts"
20
+ ]
21
+ }
@@ -0,0 +1,27 @@
1
+ /* eslint-disable */
2
+ <% if(js){ %>module.exports =<% } else{ %>export default<% } %> {
3
+ displayName: '<%= project %>',
4
+ preset: '<%= offsetFromRoot %>jest.preset.<%= presetExt %>',
5
+ setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],<% if(testEnvironment) { %>
6
+ testEnvironment: '<%= testEnvironment %>',<% } %>
7
+ coverageDirectory: '<%= offsetFromRoot %>coverage/<%= projectRoot %>',
8
+ transform: {
9
+ '^.+\\.(ts|mjs|js|html)$': [
10
+ 'jest-preset-angular',
11
+ {
12
+ tsconfig: '<rootDir>/tsconfig.spec.json',
13
+ stringifyContentPathRegex: '\\.(html|svg)$',
14
+ },
15
+ ],
16
+ },
17
+ transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)']<% if(!skipSerializers) { %>,
18
+ snapshotSerializers: [
19
+ 'jest-preset-angular/build/serializers/no-ng-attributes',
20
+ 'jest-preset-angular/build/serializers/ng-snapshot',
21
+ 'jest-preset-angular/build/serializers/html-comment',
22
+ ]<% } %><% if(rootProject){ %>,
23
+ testMatch: [
24
+ '<rootDir>/src/**/__tests__/**/*.[jt]s?(x)',
25
+ '<rootDir>/src/**/*(*.)@(spec|test).[jt]s?(x)',
26
+ ],<% } %>
27
+ };
@@ -0,0 +1 @@
1
+ import 'jest-preset-angular/setup-jest';
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
+ "module": "commonjs",
6
+ "target": "es2016",
7
+ "types": ["jest", "node"]
8
+ },<% if(setupFile !== 'none') { %>
9
+ "files": ["src/test-setup.ts"],<% } %>
10
+ "include": [
11
+ "jest.config.ts",
12
+ "src/**/*.test.ts",
13
+ "src/**/*.spec.ts",<% if (supportTsx) { %>
14
+ "src/**/*.test.tsx",
15
+ "src/**/*.spec.tsx",
16
+ "src/**/*.test.js",
17
+ "src/**/*.spec.js",
18
+ "src/**/*.test.jsx",
19
+ "src/**/*.spec.jsx",<% } %>
20
+ "src/**/*.d.ts"
21
+ ]
22
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NormalizedJestProjectSchema } from '../schema';
3
+ export declare function checkForTestTarget(tree: Tree, options: NormalizedJestProjectSchema): void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkForTestTarget = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function checkForTestTarget(tree, options) {
6
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
7
+ if (projectConfig?.targets?.test) {
8
+ throw new Error(`${options.project}: already has a test target set.`);
9
+ }
10
+ }
11
+ exports.checkForTestTarget = checkForTestTarget;
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NormalizedJestProjectSchema } from '../schema';
3
+ export declare function createFiles(tree: Tree, options: NormalizedJestProjectSchema, presetExt: 'cjs' | 'js'): void;