@nx/cypress 16.10.0 → 17.0.0-beta.1
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/index.d.ts +0 -2
- package/index.js +1 -4
- package/migrations.json +0 -18
- package/package.json +5 -5
- package/src/generators/component-configuration/component-configuration.js +7 -15
- package/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.d.ts +0 -7
- package/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.js +0 -103
- package/src/generators/convert-tslint-to-eslint/schema.json +0 -45
- package/src/migrations/update-12-8-0/remove-typescript-plugin.d.ts +0 -2
- package/src/migrations/update-12-8-0/remove-typescript-plugin.js +0 -85
- package/src/migrations/update-14-6-1/update-cypress-configs-presets.d.ts +0 -3
- package/src/migrations/update-14-6-1/update-cypress-configs-presets.js +0 -122
- package/src/migrations/update-14-7-0/update-cypress-version-if-10.d.ts +0 -3
- package/src/migrations/update-14-7-0/update-cypress-version-if-10.js +0 -31
package/index.d.ts
CHANGED
|
@@ -6,6 +6,4 @@ export declare const cypressComponentConfiguration: typeof componentConfiguratio
|
|
|
6
6
|
export { configurationGenerator as cypressE2EConfigurationGenerator };
|
|
7
7
|
export { cypressProjectGenerator } from './src/generators/cypress-project/cypress-project';
|
|
8
8
|
export { cypressInitGenerator } from './src/generators/init/init';
|
|
9
|
-
/** @deprecated This generator will be removed in v17 */
|
|
10
|
-
export { conversionGenerator } from './src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint';
|
|
11
9
|
export { migrateCypressProject } from './src/generators/migrate-to-cypress-11/migrate-to-cypress-11';
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateCypressProject = exports.
|
|
3
|
+
exports.migrateCypressProject = exports.cypressInitGenerator = exports.cypressProjectGenerator = exports.cypressE2EConfigurationGenerator = exports.cypressComponentConfiguration = exports.componentConfigurationGenerator = exports.configurationGenerator = void 0;
|
|
4
4
|
const configuration_1 = require("./src/generators/configuration/configuration");
|
|
5
5
|
Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
|
|
6
6
|
Object.defineProperty(exports, "cypressE2EConfigurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
|
|
@@ -13,8 +13,5 @@ var cypress_project_1 = require("./src/generators/cypress-project/cypress-projec
|
|
|
13
13
|
Object.defineProperty(exports, "cypressProjectGenerator", { enumerable: true, get: function () { return cypress_project_1.cypressProjectGenerator; } });
|
|
14
14
|
var init_1 = require("./src/generators/init/init");
|
|
15
15
|
Object.defineProperty(exports, "cypressInitGenerator", { enumerable: true, get: function () { return init_1.cypressInitGenerator; } });
|
|
16
|
-
/** @deprecated This generator will be removed in v17 */
|
|
17
|
-
var convert_tslint_to_eslint_1 = require("./src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint");
|
|
18
|
-
Object.defineProperty(exports, "conversionGenerator", { enumerable: true, get: function () { return convert_tslint_to_eslint_1.conversionGenerator; } });
|
|
19
16
|
var migrate_to_cypress_11_1 = require("./src/generators/migrate-to-cypress-11/migrate-to-cypress-11");
|
|
20
17
|
Object.defineProperty(exports, "migrateCypressProject", { enumerable: true, get: function () { return migrate_to_cypress_11_1.migrateCypressProject; } });
|
package/migrations.json
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"generators": {
|
|
3
|
-
"remove-typescript-plugin": {
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"version": "12.8.0-beta.0",
|
|
6
|
-
"description": "Remove Typescript Preprocessor Plugin",
|
|
7
|
-
"factory": "./src/migrations/update-12-8-0/remove-typescript-plugin"
|
|
8
|
-
},
|
|
9
|
-
"update-cypress-configs-preset": {
|
|
10
|
-
"cli": "nx",
|
|
11
|
-
"version": "14.6.1-beta.0",
|
|
12
|
-
"description": "Change Cypress e2e and component testing presets to use __filename instead of __dirname and include a devServerTarget for component testing.",
|
|
13
|
-
"factory": "./src/migrations/update-14-6-1/update-cypress-configs-presets"
|
|
14
|
-
},
|
|
15
|
-
"update-cypress-if-v10": {
|
|
16
|
-
"cli": "nx",
|
|
17
|
-
"version": "14.7.0-beta.0",
|
|
18
|
-
"description": "Update Cypress if using v10 to support latest component testing features",
|
|
19
|
-
"factory": "./src/migrations/update-14-7-0/update-cypress-version-if-10"
|
|
20
|
-
},
|
|
21
3
|
"add-cypress-inputs": {
|
|
22
4
|
"cli": "nx",
|
|
23
5
|
"version": "15.0.0-beta.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/cypress",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Cypress contains executors and generators allowing your workspace to use the powerful Cypress integration testing capabilities.",
|
|
6
6
|
"repository": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"detect-port": "^1.5.1",
|
|
39
39
|
"semver": "7.5.3",
|
|
40
40
|
"tslib": "^2.3.0",
|
|
41
|
-
"@nx/devkit": "
|
|
42
|
-
"@nx/js": "
|
|
43
|
-
"@nx/linter": "
|
|
44
|
-
"@nrwl/cypress": "
|
|
41
|
+
"@nx/devkit": "17.0.0-beta.1",
|
|
42
|
+
"@nx/js": "17.0.0-beta.1",
|
|
43
|
+
"@nx/linter": "17.0.0-beta.1",
|
|
44
|
+
"@nrwl/cypress": "17.0.0-beta.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"cypress": ">= 3 < 14"
|
|
@@ -68,22 +68,14 @@ function addTargetToProject(tree, projectConfig, opts) {
|
|
|
68
68
|
}
|
|
69
69
|
function updateNxJsonConfiguration(tree) {
|
|
70
70
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
71
|
-
nxJson.tasksRunnerOptions
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
...(nxJson?.tasksRunnerOptions?.default?.options
|
|
79
|
-
?.cacheableOperations ?? []),
|
|
80
|
-
'component-test',
|
|
81
|
-
])),
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
};
|
|
71
|
+
const cacheableOperations = nxJson.tasksRunnerOptions?.default?.options?.cacheableOperations;
|
|
72
|
+
if (cacheableOperations && !cacheableOperations.includes('component-test')) {
|
|
73
|
+
cacheableOperations.push('component-test');
|
|
74
|
+
}
|
|
75
|
+
nxJson.targetDefaults ??= {};
|
|
76
|
+
nxJson.targetDefaults['component-test'] ??= {};
|
|
77
|
+
nxJson.targetDefaults['component-test'].cache ??= true;
|
|
85
78
|
if (nxJson.namedInputs) {
|
|
86
|
-
nxJson.targetDefaults ??= {};
|
|
87
79
|
const productionFileSet = nxJson.namedInputs?.production;
|
|
88
80
|
if (productionFileSet) {
|
|
89
81
|
nxJson.namedInputs.production = Array.from(new Set([
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
2
|
-
import { ConvertTSLintToESLintSchema } from '@nx/linter';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated This generator will be removed in v17
|
|
5
|
-
*/
|
|
6
|
-
export declare function conversionGenerator(host: Tree, options: ConvertTSLintToESLintSchema): Promise<() => Promise<void>>;
|
|
7
|
-
export declare const conversionSchematic: (generatorOptions: ConvertTSLintToESLintSchema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.conversionSchematic = exports.conversionGenerator = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const linter_1 = require("@nx/linter");
|
|
6
|
-
const add_linter_1 = require("../../utils/add-linter");
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated This generator will be removed in v17
|
|
9
|
-
*/
|
|
10
|
-
async function conversionGenerator(host, options) {
|
|
11
|
-
/**
|
|
12
|
-
* The ProjectConverter instance encapsulates all the standard operations we need
|
|
13
|
-
* to perform in order to convert a project from TSLint to ESLint, as well as some
|
|
14
|
-
* extensibility points for adjusting the behavior on a per package basis.
|
|
15
|
-
*
|
|
16
|
-
* E.g. @nx/angular projects might need to make different changes to the final
|
|
17
|
-
* ESLint config when compared with @nx/next projects.
|
|
18
|
-
*
|
|
19
|
-
* See the ProjectConverter implementation for a full breakdown of what it does.
|
|
20
|
-
*/
|
|
21
|
-
const projectConverter = new linter_1.ProjectConverter({
|
|
22
|
-
host,
|
|
23
|
-
projectName: options.project,
|
|
24
|
-
ignoreExistingTslintConfig: options.ignoreExistingTslintConfig,
|
|
25
|
-
eslintInitializer: async ({ projectName, projectConfig }) => {
|
|
26
|
-
await (0, add_linter_1.addLinterToCyProject)(host, {
|
|
27
|
-
linter: linter_1.Linter.EsLint,
|
|
28
|
-
project: projectName,
|
|
29
|
-
/**
|
|
30
|
-
* We set the parserOptions.project config just in case the converted config uses
|
|
31
|
-
* rules which require type-checking. Later in the conversion we check if it actually
|
|
32
|
-
* does and remove the config again if it doesn't, so that it is most efficient.
|
|
33
|
-
*/
|
|
34
|
-
setParserOptionsProject: true,
|
|
35
|
-
cypressDir: 'src',
|
|
36
|
-
overwriteExisting: true,
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* If root eslint configuration already exists it will not be recreated
|
|
42
|
-
* but we also don't want to re-run the tslint config conversion
|
|
43
|
-
* as it was likely already done
|
|
44
|
-
*/
|
|
45
|
-
const rootEslintConfigExists = host.exists('.eslintrc.json');
|
|
46
|
-
/**
|
|
47
|
-
* Create the standard (which is applicable to the current package) ESLint setup
|
|
48
|
-
* for converting the project.
|
|
49
|
-
*/
|
|
50
|
-
const eslintInitInstallTask = await projectConverter.initESLint();
|
|
51
|
-
/**
|
|
52
|
-
* Convert the root tslint.json and apply the converted rules to the root .eslintrc.json.
|
|
53
|
-
*/
|
|
54
|
-
const rootConfigInstallTask = await projectConverter.convertRootTSLintConfig((json) => removeCodelyzerRelatedRules(json), rootEslintConfigExists);
|
|
55
|
-
/**
|
|
56
|
-
* Convert the project's tslint.json to an equivalent ESLint config.
|
|
57
|
-
*/
|
|
58
|
-
const projectConfigInstallTask = await projectConverter.convertProjectConfig((json) => json);
|
|
59
|
-
/**
|
|
60
|
-
* Clean up the original TSLint configuration for the project.
|
|
61
|
-
*/
|
|
62
|
-
projectConverter.removeProjectTSLintFile();
|
|
63
|
-
// Only project shouldn't be added as a default
|
|
64
|
-
const { project, ...defaults } = options;
|
|
65
|
-
/**
|
|
66
|
-
* Store user preferences for the collection
|
|
67
|
-
*/
|
|
68
|
-
projectConverter.setDefaults('@nx/cypress', defaults);
|
|
69
|
-
/**
|
|
70
|
-
* Based on user preference and remaining usage, remove TSLint from the workspace entirely.
|
|
71
|
-
*/
|
|
72
|
-
let uninstallTSLintTask = () => Promise.resolve(undefined);
|
|
73
|
-
if (options.removeTSLintIfNoMoreTSLintTargets &&
|
|
74
|
-
!projectConverter.isTSLintUsedInWorkspace()) {
|
|
75
|
-
uninstallTSLintTask = projectConverter.removeTSLintFromWorkspace();
|
|
76
|
-
}
|
|
77
|
-
if (!options.skipFormat) {
|
|
78
|
-
await (0, devkit_1.formatFiles)(host);
|
|
79
|
-
}
|
|
80
|
-
return async () => {
|
|
81
|
-
await eslintInitInstallTask();
|
|
82
|
-
await rootConfigInstallTask();
|
|
83
|
-
await projectConfigInstallTask();
|
|
84
|
-
await uninstallTSLintTask();
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
exports.conversionGenerator = conversionGenerator;
|
|
88
|
-
exports.conversionSchematic = (0, devkit_1.convertNxGenerator)(conversionGenerator);
|
|
89
|
-
/**
|
|
90
|
-
* Remove any @angular-eslint rules that were applied as a result of converting prior codelyzer
|
|
91
|
-
* rules, because they are only relevant for Angular projects.
|
|
92
|
-
*/
|
|
93
|
-
function removeCodelyzerRelatedRules(json) {
|
|
94
|
-
for (const ruleName of Object.keys(json.rules)) {
|
|
95
|
-
if (ruleName.startsWith('@angular-eslint')) {
|
|
96
|
-
delete json.rules[ruleName];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (json.plugins) {
|
|
100
|
-
json.plugins = json.plugins.filter((plugin) => !plugin.startsWith('@angular-eslint'));
|
|
101
|
-
}
|
|
102
|
-
return json;
|
|
103
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema",
|
|
3
|
-
"$id": "cypress-convert-tslint-to-eslint",
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"title": "Convert a Cypress project from TSLint to ESLint",
|
|
6
|
-
"description": "Convert a Cypress project from TSLint to ESLint.\n_NOTE: Does not work in `--dry-run` mode_.",
|
|
7
|
-
"x-deprecated": "This generator is deprecated and will be removed in a future version of Nx. Migrate to ESLint.",
|
|
8
|
-
"examples": [
|
|
9
|
-
{
|
|
10
|
-
"command": "nx g convert-tslint-to-eslint myapp",
|
|
11
|
-
"description": "Convert the Cypress project `myapp` from TSLint to ESLint."
|
|
12
|
-
}
|
|
13
|
-
],
|
|
14
|
-
"type": "object",
|
|
15
|
-
"properties": {
|
|
16
|
-
"project": {
|
|
17
|
-
"description": "The name of the Cypress project to convert.",
|
|
18
|
-
"type": "string",
|
|
19
|
-
"$default": {
|
|
20
|
-
"$source": "argv",
|
|
21
|
-
"index": 0
|
|
22
|
-
},
|
|
23
|
-
"x-prompt": "Which Cypress project would you like to convert from TSLint to ESLint?"
|
|
24
|
-
},
|
|
25
|
-
"ignoreExistingTslintConfig": {
|
|
26
|
-
"type": "boolean",
|
|
27
|
-
"description": "If true we will not use existing TSLint config as a reference, we will just reset the project with the latest recommended ESLint config.",
|
|
28
|
-
"default": false,
|
|
29
|
-
"x-prompt": "Would you like to ignore the existing TSLint config? Recommended if the TSLint config has not been altered much as it makes the new ESLint config cleaner."
|
|
30
|
-
},
|
|
31
|
-
"removeTSLintIfNoMoreTSLintTargets": {
|
|
32
|
-
"type": "boolean",
|
|
33
|
-
"description": "If this conversion leaves no more TSLint usage in the workspace, it will remove TSLint and related dependencies and configuration.",
|
|
34
|
-
"default": true,
|
|
35
|
-
"x-prompt": "Would you like to remove TSLint and its related config if there are no TSLint projects remaining after this conversion?"
|
|
36
|
-
},
|
|
37
|
-
"skipFormat": {
|
|
38
|
-
"type": "boolean",
|
|
39
|
-
"description": "Skip formatting files.",
|
|
40
|
-
"default": false,
|
|
41
|
-
"x-priority": "internal"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
"required": ["project"]
|
|
45
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
const typescript_1 = require("typescript");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const cypress_version_1 = require("../../utils/cypress-version");
|
|
7
|
-
async function removeTypescriptPlugin(tree) {
|
|
8
|
-
const cypressVersion = (0, cypress_version_1.installedCypressVersion)();
|
|
9
|
-
if (cypressVersion < 7) {
|
|
10
|
-
console.warn(`Cypress v${cypressVersion} is installed. This migration was skipped. Please rerun this migration after updating to Cypress 7.`);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
for (const [_, proj] of (0, devkit_1.getProjects)(tree)) {
|
|
14
|
-
const cypressTargets = getCypressTargets(proj);
|
|
15
|
-
if (cypressTargets.length <= 0) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
for (const target of cypressTargets) {
|
|
19
|
-
const cypressConfigs = getCypressConfigs(target);
|
|
20
|
-
for (const config of cypressConfigs) {
|
|
21
|
-
const cypressConfig = (0, devkit_1.readJson)(tree, config);
|
|
22
|
-
if (cypressConfig.pluginsFile) {
|
|
23
|
-
let pluginPath = (0, path_1.join)((0, path_1.dirname)(config), cypressConfig.pluginsFile);
|
|
24
|
-
if (!tree.exists(pluginPath)) {
|
|
25
|
-
pluginPath = ['.js', '.ts']
|
|
26
|
-
.map((ext) => pluginPath + ext)
|
|
27
|
-
.find((path) => tree.exists(path));
|
|
28
|
-
}
|
|
29
|
-
removePreprocessor(tree, pluginPath);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
35
|
-
}
|
|
36
|
-
exports.default = removeTypescriptPlugin;
|
|
37
|
-
function removePreprocessor(tree, pluginPath) {
|
|
38
|
-
const pluginContents = tree.read(pluginPath, 'utf-8');
|
|
39
|
-
const sourceFile = (0, typescript_1.createSourceFile)(pluginPath, pluginContents, typescript_1.ScriptTarget.ESNext, true);
|
|
40
|
-
const deletions = [];
|
|
41
|
-
const callback = (node) => {
|
|
42
|
-
// Look for the invocation of preprocessTypescript
|
|
43
|
-
if ((0, typescript_1.isCallExpression)(node) &&
|
|
44
|
-
(0, typescript_1.isIdentifier)(node.expression) &&
|
|
45
|
-
node.expression.getText(sourceFile) === 'preprocessTypescript' &&
|
|
46
|
-
node.arguments.length < 2) {
|
|
47
|
-
// Get the Statement that the function call belongs to
|
|
48
|
-
let n = node.parent;
|
|
49
|
-
while (!(0, typescript_1.isExpressionStatement)(n) && n === sourceFile) {
|
|
50
|
-
n = n.parent;
|
|
51
|
-
}
|
|
52
|
-
deletions.push({
|
|
53
|
-
type: devkit_1.ChangeType.Delete,
|
|
54
|
-
start: n.getStart(),
|
|
55
|
-
length: n.getWidth() +
|
|
56
|
-
(pluginContents[n.getStart() + n.getWidth()] === ';' ? 1 : 0),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
// Call the callback for every node in the file
|
|
61
|
-
sourceFile.forEachChild(recurse);
|
|
62
|
-
function recurse(node) {
|
|
63
|
-
callback(node);
|
|
64
|
-
node.forEachChild((child) => recurse(child));
|
|
65
|
-
}
|
|
66
|
-
// Remove the preprocessor from the file
|
|
67
|
-
tree.write(pluginPath, (0, devkit_1.applyChangesToString)(pluginContents, deletions));
|
|
68
|
-
}
|
|
69
|
-
function getCypressConfigs(target) {
|
|
70
|
-
if (!target.configurations && !target.options.cypressConfig) {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
else if (!target.configurations && target.options.cypressConfig) {
|
|
74
|
-
return [target.options.cypressConfig];
|
|
75
|
-
}
|
|
76
|
-
return [target.options, Object.values(target.configurations)]
|
|
77
|
-
.filter((options) => !!options.cypressConfig)
|
|
78
|
-
.map((options) => options.cypressConfig);
|
|
79
|
-
}
|
|
80
|
-
function getCypressTargets(proj) {
|
|
81
|
-
if (!proj.targets) {
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
return Object.values(proj.targets).filter((target) => target.executor === '@nrwl/cypress:cypress');
|
|
85
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateCypressConfigsPresets = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
-
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
7
|
-
const cypress_version_1 = require("../../utils/cypress-version");
|
|
8
|
-
const find_target_options_1 = require("../../utils/find-target-options");
|
|
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);
|
|
18
|
-
}
|
|
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
|
-
}));
|
|
30
|
-
}
|
|
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) `
|
|
40
|
-
You can manually add the 'devServerTarget' option to the
|
|
41
|
-
component testing target to specify the build target to use.
|
|
42
|
-
The build configuration should be using @nrwl/web:webpack as the executor.
|
|
43
|
-
Usually this is a React app in your workspace.
|
|
44
|
-
Component testing will fallback to a default configuration if one isn't provided,
|
|
45
|
-
but might require modifications if your projects are more complex.
|
|
46
|
-
`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.updateCypressConfigsPresets = updateCypressConfigsPresets;
|
|
50
|
-
function updatePreset(tree, options, targetName) {
|
|
51
|
-
let contents = tsquery_1.tsquery.replace(tree.read(options.cypressConfig, 'utf-8'), 'CallExpression', (node) => {
|
|
52
|
-
// technically someone could have both component and e2e in the same project.
|
|
53
|
-
const expression = node.expression.getText();
|
|
54
|
-
if (expression === 'nxE2EPreset') {
|
|
55
|
-
return 'nxE2EPreset(__filename)';
|
|
56
|
-
}
|
|
57
|
-
else if (expression === 'nxE2EStorybookPreset') {
|
|
58
|
-
return 'nxE2EStorybookPreset(__filename)';
|
|
59
|
-
}
|
|
60
|
-
else if (node.expression.getText() === 'nxComponentTestingPreset') {
|
|
61
|
-
return targetName && targetName !== 'component-test' // the default
|
|
62
|
-
? `nxComponentTestingPreset(__filename, { ctTargetName: '${targetName}' })`
|
|
63
|
-
: 'nxComponentTestingPreset(__filename)';
|
|
64
|
-
}
|
|
65
|
-
return;
|
|
66
|
-
});
|
|
67
|
-
tree.write(options.cypressConfig, contents);
|
|
68
|
-
}
|
|
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,
|
|
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;
|
|
102
|
-
}
|
|
103
|
-
function cacheComponentTestTarget(tree) {
|
|
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
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
exports.default = updateCypressConfigsPresets;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateCypressVersionIf10 = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
// don't import from root level to prevent issue where angular isn't installed.
|
|
6
|
-
const semver_1 = require("@nx/devkit/src/utils/semver");
|
|
7
|
-
const semver_2 = require("semver");
|
|
8
|
-
function updateCypressVersionIf10(tree) {
|
|
9
|
-
const installedVersion = (0, devkit_1.readJson)(tree, 'package.json').devDependencies?.['cypress'];
|
|
10
|
-
if (!installedVersion) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const normalizedInstalledCypressVersion = (0, semver_1.checkAndCleanWithSemver)('cypress', installedVersion);
|
|
14
|
-
// not using v10
|
|
15
|
-
if ((0, semver_2.lt)(normalizedInstalledCypressVersion, '10.0.0') ||
|
|
16
|
-
(0, semver_2.gte)(normalizedInstalledCypressVersion, '11.0.0')) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const ngComponentTestingVersion = '10.7.0';
|
|
20
|
-
if ((0, semver_2.lt)(normalizedInstalledCypressVersion, ngComponentTestingVersion)) {
|
|
21
|
-
(0, devkit_1.updateJson)(tree, 'package.json', (json) => {
|
|
22
|
-
json.devDependencies['cypress'] = `^${ngComponentTestingVersion}`;
|
|
23
|
-
return json;
|
|
24
|
-
});
|
|
25
|
-
return () => {
|
|
26
|
-
(0, devkit_1.installPackagesTask)(tree);
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.updateCypressVersionIf10 = updateCypressVersionIf10;
|
|
31
|
-
exports.default = updateCypressVersionIf10;
|