@nx/jest 20.1.0 → 20.2.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/package.json +3 -3
- package/src/generators/configuration/configuration.js +16 -0
- package/src/generators/configuration/files/jest.config.ts__tmpl__ +1 -1
- package/src/generators/configuration/files/tsconfig.spec.json__tmpl__ +3 -3
- package/src/generators/configuration/files-angular/jest.config.ts__tmpl__ +1 -1
- package/src/generators/configuration/files-angular/tsconfig.spec.json__tmpl__ +3 -3
- package/src/generators/configuration/lib/create-files.js +16 -2
- package/src/generators/configuration/lib/update-workspace.js +3 -3
- package/src/generators/configuration/schema.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/jest",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.2.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,8 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@jest/reporters": "^29.4.1",
|
|
39
39
|
"@jest/test-result": "^29.4.1",
|
|
40
|
-
"@nx/devkit": "20.
|
|
41
|
-
"@nx/js": "20.
|
|
40
|
+
"@nx/devkit": "20.2.0-beta.0",
|
|
41
|
+
"@nx/js": "20.2.0-beta.0",
|
|
42
42
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
43
43
|
"chalk": "^4.1.0",
|
|
44
44
|
"identity-obj-proxy": "3.0.0",
|
|
@@ -4,6 +4,7 @@ exports.configurationGenerator = configurationGenerator;
|
|
|
4
4
|
exports.configurationGeneratorInternal = configurationGeneratorInternal;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const js_1 = require("@nx/js");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
7
8
|
const config_file_1 = require("../../utils/config/config-file");
|
|
8
9
|
const init_1 = require("../init/init");
|
|
9
10
|
const check_for_test_target_1 = require("./lib/check-for-test-target");
|
|
@@ -48,6 +49,7 @@ function normalizeOptions(tree, options) {
|
|
|
48
49
|
...schemaDefaults,
|
|
49
50
|
...options,
|
|
50
51
|
rootProject: project.root === '.' || project.root === '',
|
|
52
|
+
isTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree),
|
|
51
53
|
};
|
|
52
54
|
}
|
|
53
55
|
function configurationGenerator(tree, schema) {
|
|
@@ -81,9 +83,23 @@ async function configurationGeneratorInternal(tree, schema) {
|
|
|
81
83
|
if (!hasPlugin || options.addExplicitTargets) {
|
|
82
84
|
(0, update_workspace_1.updateWorkspace)(tree, options);
|
|
83
85
|
}
|
|
86
|
+
if (options.isTsSolutionSetup) {
|
|
87
|
+
ignoreTestOutput(tree);
|
|
88
|
+
}
|
|
84
89
|
if (!schema.skipFormat) {
|
|
85
90
|
await (0, devkit_1.formatFiles)(tree);
|
|
86
91
|
}
|
|
87
92
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
88
93
|
}
|
|
94
|
+
function ignoreTestOutput(tree) {
|
|
95
|
+
if (!tree.exists('.gitignore')) {
|
|
96
|
+
devkit_1.logger.warn(`Couldn't find a root .gitignore file to update.`);
|
|
97
|
+
}
|
|
98
|
+
let content = tree.read('.gitignore', 'utf-8');
|
|
99
|
+
if (/^test-output$/gm.test(content)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
content = `${content}\ntest-output\n`;
|
|
103
|
+
tree.write('.gitignore', content);
|
|
104
|
+
}
|
|
89
105
|
exports.default = configurationGenerator;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<% if (supportTsx){ %>'^.+\\.[tj]sx?$'<% } else { %>'^.+\\.[tj]s$'<% } %>: <% if (transformerOptions) { %>['<%= transformer %>', <%- transformerOptions %>]<% } else { %>'<%= transformer %>'<% } %>
|
|
8
8
|
},
|
|
9
9
|
<% if (supportTsx) { %>moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],<% } else { %>moduleFileExtensions: ['ts', 'js', 'html'],<% } %><% } %>
|
|
10
|
-
coverageDirectory: '<%=
|
|
10
|
+
coverageDirectory: '<%= coverageDirectory %>'<% if(rootProject){ %>,
|
|
11
11
|
testMatch: [
|
|
12
12
|
'<rootDir>/src/**/__tests__/**/*.[jt]s?(x)',
|
|
13
13
|
'<rootDir>/src/**/*(*.)@(spec|test).[jt]s?(x)',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "<%= extendedConfig %>",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"outDir": "<%=
|
|
5
|
-
"module": "
|
|
4
|
+
"outDir": "<%= outDir %>",<% if (module) { %>
|
|
5
|
+
"module": "<%= module %>",<% } %>
|
|
6
6
|
"types": ["jest", "node"]
|
|
7
7
|
},<% if(setupFile !== 'none') { %>
|
|
8
8
|
"files": ["src/test-setup.ts"],<% } %>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
preset: '<%= offsetFromRoot %>jest.preset.<%= presetExt %>',
|
|
4
4
|
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],<% if(testEnvironment) { %>
|
|
5
5
|
testEnvironment: '<%= testEnvironment %>',<% } %>
|
|
6
|
-
coverageDirectory: '<%=
|
|
6
|
+
coverageDirectory: '<%= coverageDirectory %>',
|
|
7
7
|
transform: {
|
|
8
8
|
'^.+\\.(ts|mjs|js|html)$': [
|
|
9
9
|
'jest-preset-angular',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "<%= extendedConfig %>",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"outDir": "<%=
|
|
5
|
-
"module": "
|
|
4
|
+
"outDir": "<%= outDir %>",<% if (module) { %>
|
|
5
|
+
"module": "<%= module %>",<% } %>
|
|
6
6
|
"target": "es2016",
|
|
7
7
|
"types": ["jest", "node"]
|
|
8
8
|
},<% if(setupFile !== 'none') { %>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createFiles = createFiles;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
function createFiles(tree, options, presetExt) {
|
|
7
8
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
@@ -22,6 +23,11 @@ function createFiles(tree, options, presetExt) {
|
|
|
22
23
|
transformer = 'ts-jest';
|
|
23
24
|
transformerOptions = "{ tsconfig: '<rootDir>/tsconfig.spec.json' }";
|
|
24
25
|
}
|
|
26
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
27
|
+
const projectRoot = options.rootProject
|
|
28
|
+
? options.project
|
|
29
|
+
: projectConfig.root;
|
|
30
|
+
const rootOffset = (0, devkit_1.offsetFromRoot)(projectConfig.root);
|
|
25
31
|
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, filesFolder), projectConfig.root, {
|
|
26
32
|
tmpl: '',
|
|
27
33
|
...options,
|
|
@@ -33,9 +39,17 @@ function createFiles(tree, options, presetExt) {
|
|
|
33
39
|
transformerOptions,
|
|
34
40
|
js: !!options.js,
|
|
35
41
|
rootProject: options.rootProject,
|
|
36
|
-
projectRoot
|
|
37
|
-
offsetFromRoot:
|
|
42
|
+
projectRoot,
|
|
43
|
+
offsetFromRoot: rootOffset,
|
|
38
44
|
presetExt,
|
|
45
|
+
coverageDirectory: isTsSolutionSetup
|
|
46
|
+
? `test-output/jest/coverage`
|
|
47
|
+
: `${rootOffset}coverage/${projectRoot}`,
|
|
48
|
+
extendedConfig: isTsSolutionSetup
|
|
49
|
+
? `${rootOffset}tsconfig.base.json`
|
|
50
|
+
: './tsconfig.json',
|
|
51
|
+
outDir: isTsSolutionSetup ? `./out-tsc/jest` : `${rootOffset}dist/out-tsc`,
|
|
52
|
+
module: !isTsSolutionSetup ? 'commonjs' : undefined,
|
|
39
53
|
});
|
|
40
54
|
if (options.setupFile === 'none') {
|
|
41
55
|
tree.delete((0, path_1.join)(projectConfig.root, './src/test-setup.ts'));
|
|
@@ -10,9 +10,9 @@ function updateWorkspace(tree, options) {
|
|
|
10
10
|
projectConfig.targets[options.targetName] = {
|
|
11
11
|
executor: '@nx/jest:jest',
|
|
12
12
|
outputs: [
|
|
13
|
-
options.
|
|
14
|
-
?
|
|
15
|
-
: (0, devkit_1.joinPathFragments)('{workspaceRoot}', 'coverage', '{projectRoot}'),
|
|
13
|
+
options.isTsSolutionSetup
|
|
14
|
+
? '{projectRoot}/test-output/jest/coverage'
|
|
15
|
+
: (0, devkit_1.joinPathFragments)('{workspaceRoot}', 'coverage', options.rootProject ? '{projectName}' : '{projectRoot}'),
|
|
16
16
|
],
|
|
17
17
|
options: {
|
|
18
18
|
jestConfig: (0, devkit_1.joinPathFragments)((0, devkit_1.normalizePath)(projectConfig.root), `jest.config.${options.js ? 'js' : 'ts'}`),
|