@nx/cypress 16.8.0-beta.4 → 16.8.0-beta.6
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/migrations.json +6 -0
- package/package.json +7 -7
- package/plugins/cypress-preset.d.ts +0 -3
- package/plugins/cypress-preset.js +15 -7
- package/src/executors/cypress/cypress.impl.d.ts +1 -0
- package/src/executors/cypress/cypress.impl.js +180 -210
- package/src/executors/cypress/schema.json +4 -0
- package/src/generators/base-setup/base-setup.js +15 -5
- package/src/generators/component-configuration/component-configuration.js +42 -30
- package/src/generators/configuration/configuration.js +87 -70
- package/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.js +75 -78
- package/src/generators/cypress-project/cypress-project.js +76 -63
- package/src/generators/init/init.js +16 -18
- package/src/generators/migrate-to-cypress-11/conversion.util.js +22 -16
- package/src/generators/migrate-to-cypress-11/migrate-to-cypress-11.js +38 -35
- package/src/migrations/update-12-8-0/remove-typescript-plugin.js +23 -26
- package/src/migrations/update-14-6-1/update-cypress-configs-presets.js +79 -68
- package/src/migrations/update-14-7-0/update-cypress-version-if-10.js +1 -2
- package/src/migrations/update-15-0-0/add-cypress-inputs.js +24 -29
- package/src/migrations/update-15-0-0/update-cy-mount-usage.js +25 -29
- package/src/migrations/update-15-1-0/cypress-11.js +34 -37
- package/src/migrations/update-15-5-0/update-to-cypress-12.js +3 -5
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-2-0/update-cy-tsconfig.js +25 -24
- package/src/migrations/update-16-4-0/tsconfig-sourcemaps.js +52 -49
- package/src/migrations/update-16-8-0/cypress-13.d.ts +7 -0
- package/src/migrations/update-16-8-0/cypress-13.js +179 -0
- package/src/plugins/preprocessor-vite.js +7 -5
- package/src/utils/add-linter.js +78 -81
- package/src/utils/config.js +54 -62
- package/src/utils/ct-helpers.js +6 -8
- package/src/utils/cypress-version.js +1 -1
- package/src/utils/find-target-options.js +37 -43
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateCypressConfigsPresets = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
7
6
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
8
7
|
const cypress_version_1 = require("../../utils/cypress-version");
|
|
9
8
|
const find_target_options_1 = require("../../utils/find-target-options");
|
|
10
|
-
function updateCypressConfigsPresets(tree) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
async function updateCypressConfigsPresets(tree) {
|
|
10
|
+
if ((0, cypress_version_1.installedCypressVersion)() < 10) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const projectsWithoutDevServerTarget = new Set();
|
|
14
|
+
const updateTasks = [];
|
|
15
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName, targetName, configName) => {
|
|
16
|
+
if (options.cypressConfig && tree.exists(options.cypressConfig)) {
|
|
17
|
+
updatePreset(tree, options, targetName);
|
|
14
18
|
}
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
((_d = (_c = projectConfig.targets[targetName]) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.devServerTarget);
|
|
27
|
-
if (!devServerTarget && testingType === 'component') {
|
|
28
|
-
updateTasks.push(addBuildTargetToConfig(tree, projectName, targetName, configName).then((didUpdate) => {
|
|
29
|
-
if (!didUpdate) {
|
|
30
|
-
projectsWithoutDevServerTarget.add(projectName);
|
|
31
|
-
}
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
if (updateTasks.length > 0) {
|
|
36
|
-
cacheComponentTestTarget(tree);
|
|
19
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
20
|
+
const testingType = options.testingType ||
|
|
21
|
+
projectConfig.targets[targetName]?.options?.testingType;
|
|
22
|
+
const devServerTarget = options.devServerTarget ||
|
|
23
|
+
projectConfig.targets[targetName]?.options?.devServerTarget;
|
|
24
|
+
if (!devServerTarget && testingType === 'component') {
|
|
25
|
+
updateTasks.push(addBuildTargetToConfig(tree, projectName, targetName, configName).then((didUpdate) => {
|
|
26
|
+
if (!didUpdate) {
|
|
27
|
+
projectsWithoutDevServerTarget.add(projectName);
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
});
|
|
32
|
+
if (updateTasks.length > 0) {
|
|
33
|
+
cacheComponentTestTarget(tree);
|
|
34
|
+
}
|
|
35
|
+
await Promise.all(updateTasks);
|
|
36
|
+
if (projectsWithoutDevServerTarget.size > 0) {
|
|
37
|
+
devkit_1.logger.warn(`Unable to find a build target to add to the component testing target in the following projects:`);
|
|
38
|
+
devkit_1.logger.warn(`- ${Array.from(projectsWithoutDevServerTarget).join('\n- ')}`);
|
|
39
|
+
devkit_1.logger.warn((0, devkit_1.stripIndents) `
|
|
43
40
|
You can manually add the 'devServerTarget' option to the
|
|
44
41
|
component testing target to specify the build target to use.
|
|
45
42
|
The build configuration should be using @nrwl/web:webpack as the executor.
|
|
@@ -47,8 +44,7 @@ Usually this is a React app in your workspace.
|
|
|
47
44
|
Component testing will fallback to a default configuration if one isn't provided,
|
|
48
45
|
but might require modifications if your projects are more complex.
|
|
49
46
|
`);
|
|
50
|
-
|
|
51
|
-
});
|
|
47
|
+
}
|
|
52
48
|
}
|
|
53
49
|
exports.updateCypressConfigsPresets = updateCypressConfigsPresets;
|
|
54
50
|
function updatePreset(tree, options, targetName) {
|
|
@@ -70,42 +66,57 @@ function updatePreset(tree, options, targetName) {
|
|
|
70
66
|
});
|
|
71
67
|
tree.write(options.cypressConfig, contents);
|
|
72
68
|
}
|
|
73
|
-
function addBuildTargetToConfig(tree, projectName, targetName, configName) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
validExecutorNames: new Set(['@nrwl/web:webpack']),
|
|
79
|
-
skipGetOptions: true,
|
|
80
|
-
});
|
|
81
|
-
// didn't find the config so can't update. consumer should collect list of them and display a warning at the end
|
|
82
|
-
// no reason to fail since the preset will fallback to a default config so should still keep working.
|
|
83
|
-
if (!(projectWithBuild === null || projectWithBuild === void 0 ? void 0 : projectWithBuild.target)) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
87
|
-
// if using a custom config and the devServerTarget default args
|
|
88
|
-
// has a different target, then add it to the custom target config
|
|
89
|
-
// otherwise add it to the default options
|
|
90
|
-
if (configName &&
|
|
91
|
-
projectWithBuild.target !==
|
|
92
|
-
((_b = (_a = projectConfig.targets[targetName]) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.devServerTarget)) {
|
|
93
|
-
projectConfig.targets[targetName].configurations[configName] = Object.assign(Object.assign({}, projectConfig.targets[targetName].configurations[configName]), { devServerTarget: projectWithBuild.target, skipServe: true });
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
projectConfig.targets[targetName].options = Object.assign(Object.assign({}, projectConfig.targets[targetName].options), { devServerTarget: projectWithBuild.target, skipServe: true });
|
|
97
|
-
}
|
|
98
|
-
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
99
|
-
return true;
|
|
69
|
+
async function addBuildTargetToConfig(tree, projectName, targetName, configName) {
|
|
70
|
+
const projectWithBuild = await (0, find_target_options_1.findBuildConfig)(tree, {
|
|
71
|
+
project: projectName,
|
|
72
|
+
validExecutorNames: new Set(['@nrwl/web:webpack']),
|
|
73
|
+
skipGetOptions: true,
|
|
100
74
|
});
|
|
75
|
+
// didn't find the config so can't update. consumer should collect list of them and display a warning at the end
|
|
76
|
+
// no reason to fail since the preset will fallback to a default config so should still keep working.
|
|
77
|
+
if (!projectWithBuild?.target) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
81
|
+
// if using a custom config and the devServerTarget default args
|
|
82
|
+
// has a different target, then add it to the custom target config
|
|
83
|
+
// otherwise add it to the default options
|
|
84
|
+
if (configName &&
|
|
85
|
+
projectWithBuild.target !==
|
|
86
|
+
projectConfig.targets[targetName]?.options?.devServerTarget) {
|
|
87
|
+
projectConfig.targets[targetName].configurations[configName] = {
|
|
88
|
+
...projectConfig.targets[targetName].configurations[configName],
|
|
89
|
+
devServerTarget: projectWithBuild.target,
|
|
90
|
+
skipServe: true,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
projectConfig.targets[targetName].options = {
|
|
95
|
+
...projectConfig.targets[targetName].options,
|
|
96
|
+
devServerTarget: projectWithBuild.target,
|
|
97
|
+
skipServe: true,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
101
|
+
return true;
|
|
101
102
|
}
|
|
102
103
|
function cacheComponentTestTarget(tree) {
|
|
103
|
-
(0, devkit_1.updateJson)(tree, 'nx.json', (json) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
(0, devkit_1.updateJson)(tree, 'nx.json', (json) => ({
|
|
105
|
+
...json,
|
|
106
|
+
tasksRunnerOptions: {
|
|
107
|
+
...json.tasksRunnerOptions,
|
|
108
|
+
default: {
|
|
109
|
+
...json.tasksRunnerOptions?.default,
|
|
110
|
+
options: {
|
|
111
|
+
...json.tasksRunnerOptions?.default?.options,
|
|
112
|
+
cacheableOperations: Array.from(new Set([
|
|
113
|
+
...(json.tasksRunnerOptions?.default?.options
|
|
114
|
+
?.cacheableOperations ?? []),
|
|
115
|
+
'component-test',
|
|
116
|
+
])),
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
}));
|
|
110
121
|
}
|
|
111
122
|
exports.default = updateCypressConfigsPresets;
|
|
@@ -6,8 +6,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
6
6
|
const semver_1 = require("@nx/devkit/src/utils/semver");
|
|
7
7
|
const semver_2 = require("semver");
|
|
8
8
|
function updateCypressVersionIf10(tree) {
|
|
9
|
-
|
|
10
|
-
const installedVersion = (_a = (0, devkit_1.readJson)(tree, 'package.json').devDependencies) === null || _a === void 0 ? void 0 : _a['cypress'];
|
|
9
|
+
const installedVersion = (0, devkit_1.readJson)(tree, 'package.json').devDependencies?.['cypress'];
|
|
11
10
|
if (!installedVersion) {
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
const devkit_1 = require("@nx/devkit");
|
|
5
4
|
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
-
function default_1(tree) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'!{projectRoot}/cypress.config.[jt]s',
|
|
19
|
-
]) {
|
|
20
|
-
productionFileset.add(exclusion);
|
|
21
|
-
}
|
|
22
|
-
nxJson.namedInputs.production = Array.from(productionFileset);
|
|
5
|
+
async function default_1(tree) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
7
|
+
const { cypressTargets, hasComponentTesting } = getCypressTargetNames(tree);
|
|
8
|
+
const hasProductionFileset = !!nxJson.namedInputs?.production;
|
|
9
|
+
if (hasComponentTesting && hasProductionFileset && cypressTargets.size > 0) {
|
|
10
|
+
const productionFileset = new Set(nxJson.namedInputs.production);
|
|
11
|
+
for (const exclusion of [
|
|
12
|
+
'!{projectRoot}/cypress/**/*',
|
|
13
|
+
'!{projectRoot}/**/*.cy.[jt]s?(x)',
|
|
14
|
+
'!{projectRoot}/cypress.config.[jt]s',
|
|
15
|
+
]) {
|
|
16
|
+
productionFileset.add(exclusion);
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
nxJson.namedInputs.production = Array.from(productionFileset);
|
|
19
|
+
}
|
|
20
|
+
for (const targetName of cypressTargets) {
|
|
21
|
+
nxJson.targetDefaults ??= {};
|
|
22
|
+
const cypressTargetDefaults = (nxJson.targetDefaults[targetName] ??= {});
|
|
23
|
+
cypressTargetDefaults.inputs ??= [
|
|
24
|
+
'default',
|
|
25
|
+
hasProductionFileset ? '^production' : '^default',
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
29
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
35
30
|
}
|
|
36
31
|
exports.default = default_1;
|
|
37
32
|
function getCypressTargetNames(tree) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateCyFile = exports.addMountCommand = exports.updateCyMountUsage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const ct_helpers_1 = require("../../utils/ct-helpers");
|
|
6
5
|
const cypress_version_1 = require("../../utils/cypress-version");
|
|
7
6
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -9,35 +8,33 @@ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-opt
|
|
|
9
8
|
const semver_1 = require("@nx/devkit/src/utils/semver");
|
|
10
9
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
11
10
|
const semver_2 = require("semver");
|
|
12
|
-
function updateCyMountUsage(tree) {
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
async function updateCyMountUsage(tree) {
|
|
12
|
+
if ((0, cypress_version_1.installedCypressVersion)() < 10) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
16
|
+
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
|
17
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName) => {
|
|
18
|
+
if (options.testingType !== 'component' || !options.devServerTarget) {
|
|
15
19
|
return;
|
|
16
20
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const parsed = (0, devkit_1.parseTargetString)(options.devServerTarget, graph);
|
|
22
|
+
if (!parsed?.project || !parsed?.target) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const buildProjectConfig = projects.get(parsed.project);
|
|
26
|
+
const framework = getFramework(tree, parsed.configuration
|
|
27
|
+
? buildProjectConfig.targets[parsed.target].configurations[parsed.configuration]
|
|
28
|
+
: buildProjectConfig.targets[parsed.target]);
|
|
29
|
+
const ctProjectConfig = projects.get(projectName);
|
|
30
|
+
addMountCommand(tree, ctProjectConfig.root, framework);
|
|
31
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, ctProjectConfig.sourceRoot, (filePath) => {
|
|
32
|
+
if (ct_helpers_1.CY_FILE_MATCHER.test(filePath)) {
|
|
33
|
+
updateCyFile(tree, filePath, framework);
|
|
26
34
|
}
|
|
27
|
-
const buildProjectConfig = projects.get(parsed.project);
|
|
28
|
-
const framework = getFramework(tree, parsed.configuration
|
|
29
|
-
? buildProjectConfig.targets[parsed.target].configurations[parsed.configuration]
|
|
30
|
-
: buildProjectConfig.targets[parsed.target]);
|
|
31
|
-
const ctProjectConfig = projects.get(projectName);
|
|
32
|
-
addMountCommand(tree, ctProjectConfig.root, framework);
|
|
33
|
-
(0, devkit_1.visitNotIgnoredFiles)(tree, ctProjectConfig.sourceRoot, (filePath) => {
|
|
34
|
-
if (ct_helpers_1.CY_FILE_MATCHER.test(filePath)) {
|
|
35
|
-
updateCyFile(tree, filePath, framework);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
35
|
});
|
|
39
|
-
yield (0, devkit_1.formatFiles)(tree);
|
|
40
36
|
});
|
|
37
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
41
38
|
}
|
|
42
39
|
exports.updateCyMountUsage = updateCyMountUsage;
|
|
43
40
|
function addMountCommand(tree, projectRoot, framework) {
|
|
@@ -47,7 +44,7 @@ function addMountCommand(tree, projectRoot, framework) {
|
|
|
47
44
|
}
|
|
48
45
|
const commandFile = tree.read(commandFilePath, 'utf-8');
|
|
49
46
|
const mountCommand = tsquery_1.tsquery.query(commandFile, 'CallExpression:has(StringLiteral[value="mount"]) PropertyAccessExpression:has(Identifier[name="add"])');
|
|
50
|
-
if (
|
|
47
|
+
if (mountCommand?.length > 0) {
|
|
51
48
|
return;
|
|
52
49
|
}
|
|
53
50
|
const existingCommands = tsquery_1.tsquery.query(commandFile, 'InterfaceDeclaration:has(Identifier[name="Chainable"]) > MethodSignature, InterfaceDeclaration:has(Identifier[name="Chainable"]) > PropertySignature');
|
|
@@ -74,7 +71,7 @@ function addMountCommand(tree, projectRoot, framework) {
|
|
|
74
71
|
* or if the node is the global declaration, then add it,
|
|
75
72
|
* but not to the cypress module declaration inside the global declaration
|
|
76
73
|
*/
|
|
77
|
-
if (
|
|
74
|
+
if (isGlobalDeclaration?.length === 0 ||
|
|
78
75
|
node.name.getText() === 'global') {
|
|
79
76
|
return newModuleDelcaration;
|
|
80
77
|
}
|
|
@@ -84,13 +81,12 @@ function addMountCommand(tree, projectRoot, framework) {
|
|
|
84
81
|
}
|
|
85
82
|
exports.addMountCommand = addMountCommand;
|
|
86
83
|
function getFramework(tree, target) {
|
|
87
|
-
var _a;
|
|
88
84
|
if (target.executor === '@nrwl/angular:webpack-browser' ||
|
|
89
85
|
target.executor === '@angular-devkit/build-angular:browser') {
|
|
90
86
|
return 'angular';
|
|
91
87
|
}
|
|
92
88
|
const pkgJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
93
|
-
const reactDomVersion =
|
|
89
|
+
const reactDomVersion = pkgJson?.dependencies?.['react-dom'];
|
|
94
90
|
const hasReact18 = reactDomVersion &&
|
|
95
91
|
(0, semver_2.gte)((0, semver_1.checkAndCleanWithSemver)('react-dom', reactDomVersion), '18.0.0');
|
|
96
92
|
if (hasReact18) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateProviderUsage = exports.updateUnmountUsage = exports.updateMountHookUsage = exports.updateToCypress11 = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const ct_helpers_1 = require("../../utils/ct-helpers");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
@@ -10,43 +9,41 @@ const path_1 = require("path");
|
|
|
10
9
|
const ts = require("typescript");
|
|
11
10
|
const cypress_version_1 = require("../../utils/cypress-version");
|
|
12
11
|
const versions_1 = require("../../utils/versions");
|
|
13
|
-
function updateToCypress11(tree) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
async function updateToCypress11(tree) {
|
|
13
|
+
const installedVersion = (0, cypress_version_1.installedCypressVersion)();
|
|
14
|
+
if (installedVersion < 10) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
18
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName, targetName, configurationName) => {
|
|
19
|
+
if (options.testingType !== 'component' ||
|
|
20
|
+
!(options.cypressConfig && tree.exists(options.cypressConfig))) {
|
|
17
21
|
return;
|
|
18
22
|
}
|
|
19
|
-
const
|
|
20
|
-
(0,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const projectConfig = projects.get(projectName);
|
|
24
|
+
const commandsFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'commands.ts');
|
|
25
|
+
const framework = getFramework(tree.exists(commandsFile)
|
|
26
|
+
? tree.read(commandsFile, 'utf-8')
|
|
27
|
+
: tree.read(options.cypressConfig, 'utf-8'));
|
|
28
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot, (filePath) => {
|
|
29
|
+
if (!ct_helpers_1.CY_FILE_MATCHER.test(filePath)) {
|
|
23
30
|
return;
|
|
24
31
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
const frameworkFromFile = getFramework(tree.read(filePath, 'utf-8'));
|
|
35
|
-
if (framework === 'react' || frameworkFromFile === 'react') {
|
|
36
|
-
updateUnmountUsage(tree, filePath);
|
|
37
|
-
updateMountHookUsage(tree, filePath);
|
|
38
|
-
}
|
|
39
|
-
if (framework === 'angular' || frameworkFromFile === 'angular') {
|
|
40
|
-
updateProviderUsage(tree, filePath);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
32
|
+
const frameworkFromFile = getFramework(tree.read(filePath, 'utf-8'));
|
|
33
|
+
if (framework === 'react' || frameworkFromFile === 'react') {
|
|
34
|
+
updateUnmountUsage(tree, filePath);
|
|
35
|
+
updateMountHookUsage(tree, filePath);
|
|
36
|
+
}
|
|
37
|
+
if (framework === 'angular' || frameworkFromFile === 'angular') {
|
|
38
|
+
updateProviderUsage(tree, filePath);
|
|
39
|
+
}
|
|
43
40
|
});
|
|
44
|
-
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { cypress: versions_1.cypressVersion });
|
|
45
|
-
yield (0, devkit_1.formatFiles)(tree);
|
|
46
|
-
return () => {
|
|
47
|
-
installTask();
|
|
48
|
-
};
|
|
49
41
|
});
|
|
42
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { cypress: versions_1.cypressVersion });
|
|
43
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
44
|
+
return () => {
|
|
45
|
+
installTask();
|
|
46
|
+
};
|
|
50
47
|
}
|
|
51
48
|
exports.updateToCypress11 = updateToCypress11;
|
|
52
49
|
function updateMountHookUsage(tree, filePath) {
|
|
@@ -78,16 +75,16 @@ ${reactDomImport}`;
|
|
|
78
75
|
}
|
|
79
76
|
exports.updateUnmountUsage = updateUnmountUsage;
|
|
80
77
|
function updateProviderUsage(tree, filePath) {
|
|
81
|
-
var _a;
|
|
82
78
|
const originalContents = tree.read(filePath, 'utf-8');
|
|
83
|
-
const isTestBedImported =
|
|
79
|
+
const isTestBedImported = tsquery_1.tsquery.query(originalContents, ':matches(ImportDeclaration, VariableStatement):has(Identifier[name="TestBed"]):has(StringLiteral[value="@angular/core/testing"])')?.length > 0;
|
|
84
80
|
let updatedProviders = tsquery_1.tsquery.replace(originalContents, 'CallExpression:has(PropertyAccessExpression:has(Identifier[name="mount"]))', (node) => {
|
|
85
|
-
var _a, _b, _c, _d;
|
|
86
81
|
const expressionName = node.expression.getText();
|
|
87
|
-
if (expressionName === 'cy.mount' &&
|
|
82
|
+
if (expressionName === 'cy.mount' && node?.arguments?.length > 1) {
|
|
88
83
|
const component = node.arguments[0].getText();
|
|
89
84
|
if (ts.isObjectLiteralExpression(node.arguments[1])) {
|
|
90
|
-
const providers =
|
|
85
|
+
const providers = node.arguments[1]?.properties
|
|
86
|
+
?.find((p) => p.name?.getText() === 'providers')
|
|
87
|
+
?.getText();
|
|
91
88
|
const noProviders = tsquery_1.tsquery.replace(node.getText(), 'PropertyAssignment:has(Identifier[name="providers"])', (n) => {
|
|
92
89
|
// set it to undefined so we don't run into a hanging comma causing invalid syntax
|
|
93
90
|
return 'providers: undefined';
|
|
@@ -125,16 +125,15 @@ exports.shouldUseCySession = shouldUseCySession;
|
|
|
125
125
|
function shouldNotUseCyInShouldCB(tree, filePath) {
|
|
126
126
|
const content = tree.read(filePath, 'utf-8');
|
|
127
127
|
const markedNestedCyCommands = tsquery_1.tsquery.replace(content, 'CallExpression > PropertyAccessExpression:has(Identifier[name="cy"]):has(Identifier[name="should"])', (node) => {
|
|
128
|
-
var _a, _b;
|
|
129
128
|
if ((0, helpers_1.isAlreadyCommented)(node) ||
|
|
130
129
|
(node.parent && !(0, typescript_1.isCallExpression)(node.parent))) {
|
|
131
130
|
return;
|
|
132
131
|
}
|
|
133
132
|
const parentExpression = node.parent;
|
|
134
|
-
if (
|
|
133
|
+
if (parentExpression?.arguments?.[0] &&
|
|
135
134
|
((0, typescript_1.isArrowFunction)(parentExpression.arguments[0]) ||
|
|
136
135
|
(0, typescript_1.isFunctionExpression)(parentExpression.arguments[0]))) {
|
|
137
|
-
const isUsingNestedCyCommand =
|
|
136
|
+
const isUsingNestedCyCommand = tsquery_1.tsquery.query(parentExpression.arguments[0], 'CallExpression > PropertyAccessExpression:has(Identifier[name="cy"])')?.length > 0;
|
|
138
137
|
if (isUsingNestedCyCommand) {
|
|
139
138
|
return `/**
|
|
140
139
|
* TODO(@nrwl/cypress): Nesting Cypress commands in a should assertion now throws.
|
|
@@ -155,7 +154,6 @@ exports.shouldNotUseCyInShouldCB = shouldNotUseCyInShouldCB;
|
|
|
155
154
|
function shouldNotOverrideCommands(tree, filePath) {
|
|
156
155
|
const content = tree.read(filePath, 'utf-8');
|
|
157
156
|
const markedOverrideUsage = tsquery_1.tsquery.replace(content, 'PropertyAccessExpression:has(Identifier[name="overwrite"]):has(Identifier[name="Cypress"])', (node) => {
|
|
158
|
-
var _a, _b;
|
|
159
157
|
if ((0, helpers_1.isAlreadyCommented)(node)) {
|
|
160
158
|
return;
|
|
161
159
|
}
|
|
@@ -164,7 +162,7 @@ function shouldNotOverrideCommands(tree, filePath) {
|
|
|
164
162
|
if (expression === 'Cypress.Commands') {
|
|
165
163
|
// get value.
|
|
166
164
|
const overwriteExpression = node.parent;
|
|
167
|
-
const command =
|
|
165
|
+
const command = overwriteExpression.arguments?.[0]?.text; // need string without quotes
|
|
168
166
|
if (helpers_1.BANNED_COMMANDS.includes(command)) {
|
|
169
167
|
// overwrite
|
|
170
168
|
return `/**
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
const devkit_1 = require("@nx/devkit");
|
|
5
4
|
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
6
|
-
function replacePackage(tree) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
yield (0, devkit_1.formatFiles)(tree);
|
|
10
|
-
});
|
|
5
|
+
async function replacePackage(tree) {
|
|
6
|
+
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/cypress', '@nx/cypress');
|
|
7
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
11
8
|
}
|
|
12
9
|
exports.default = replacePackage;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeCyTsConfigNames = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
7
|
-
function normalizeCyTsConfigNames(tree) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
yield (0, devkit_1.formatFiles)(tree);
|
|
6
|
+
async function normalizeCyTsConfigNames(tree) {
|
|
7
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
8
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/cypress:cypress', (_, projectName) => {
|
|
9
|
+
const projectConfig = projects.get(projectName);
|
|
10
|
+
const newTsConfigPath = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'tsconfig.json');
|
|
11
|
+
// if there is already a tsconfig.json in the cypress folder, then assume things are setup already
|
|
12
|
+
if (!tree.exists(newTsConfigPath)) {
|
|
13
|
+
moveProjectTsCyConfig(tree, projectConfig, newTsConfigPath);
|
|
14
|
+
moveCyDirTsCyConfig(tree, projectConfig, newTsConfigPath);
|
|
15
|
+
updateCyDirTsConfigReferences(tree, projectConfig);
|
|
16
|
+
}
|
|
21
17
|
});
|
|
18
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
22
19
|
}
|
|
23
20
|
exports.normalizeCyTsConfigNames = normalizeCyTsConfigNames;
|
|
24
21
|
function moveProjectTsCyConfig(tree, projectConfig, newTsConfigPath) {
|
|
25
22
|
if (tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.cy.json'))) {
|
|
26
23
|
tree.rename((0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.cy.json'), newTsConfigPath);
|
|
27
24
|
(0, devkit_1.updateJson)(tree, newTsConfigPath, (json) => {
|
|
28
|
-
var _a, _b;
|
|
29
25
|
json.extends = '../tsconfig.json';
|
|
30
|
-
|
|
31
|
-
json.compilerOptions =
|
|
32
|
-
|
|
26
|
+
json.compilerOptions ??= {};
|
|
27
|
+
json.compilerOptions = {
|
|
28
|
+
...json.compilerOptions,
|
|
29
|
+
sourceMap: false,
|
|
30
|
+
outDir: '../../../dist/out-tsc',
|
|
31
|
+
};
|
|
32
|
+
json.include ??= [];
|
|
33
33
|
json.include = json.include.map((p) => {
|
|
34
34
|
if (p.startsWith('cypress/')) {
|
|
35
35
|
return p.replace('cypress/', '');
|
|
@@ -44,9 +44,11 @@ function moveCyDirTsCyConfig(tree, projectConfig, newTsConfigPath) {
|
|
|
44
44
|
if (tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'tsconfig.cy.json'))) {
|
|
45
45
|
tree.rename((0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'tsconfig.cy.json'), newTsConfigPath);
|
|
46
46
|
(0, devkit_1.updateJson)(tree, newTsConfigPath, (json) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
json.compilerOptions ??= {};
|
|
48
|
+
json.compilerOptions = {
|
|
49
|
+
...json.compilerOptions,
|
|
50
|
+
sourceMap: false,
|
|
51
|
+
};
|
|
50
52
|
return json;
|
|
51
53
|
});
|
|
52
54
|
}
|
|
@@ -56,8 +58,7 @@ function updateCyDirTsConfigReferences(tree, projectConfig) {
|
|
|
56
58
|
return;
|
|
57
59
|
}
|
|
58
60
|
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json'), (json) => {
|
|
59
|
-
|
|
60
|
-
(_a = json.references) !== null && _a !== void 0 ? _a : (json.references = []);
|
|
61
|
+
json.references ??= [];
|
|
61
62
|
if (!json.references) {
|
|
62
63
|
return json;
|
|
63
64
|
}
|