@nx/cypress 17.0.3 → 17.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +9 -4
- package/generators.json +3 -3
- package/index.d.ts +2 -2
- package/index.js +4 -4
- package/migrations.json +24 -0
- package/package.json +6 -6
- package/plugin.d.ts +1 -0
- package/plugin.js +6 -0
- package/plugins/cypress-preset.d.ts +27 -19
- package/plugins/cypress-preset.js +102 -11
- package/src/executors/cypress/cypress.impl.d.ts +1 -1
- package/src/executors/cypress/cypress.impl.js +6 -152
- package/src/executors/cypress/schema.json +11 -1
- package/src/generators/base-setup/base-setup.d.ts +1 -0
- package/src/generators/base-setup/base-setup.js +26 -3
- package/src/generators/base-setup/files/config-js-cjs/__directory__/support/commands.js__ext__ +35 -0
- package/src/generators/base-setup/files/config-js-cjs/cypress.config.js__ext__ +3 -0
- package/src/generators/base-setup/files/config-js-esm/__directory__/support/commands.js__ext__ +35 -0
- package/src/generators/base-setup/files/config-ts/__directory__/support/commands.ts__ext__ +35 -0
- package/src/generators/base-setup/files/config-ts/cypress.config.ts__ext__ +3 -0
- package/src/generators/component-configuration/component-configuration.d.ts +3 -2
- package/src/generators/component-configuration/component-configuration.js +50 -27
- package/src/generators/component-configuration/files/__directory__/support/component-index.html +4 -1
- package/src/generators/component-configuration/schema.d.ts +7 -0
- package/src/generators/component-configuration/schema.json +1 -1
- package/src/generators/configuration/configuration.d.ts +4 -0
- package/src/generators/configuration/configuration.js +90 -26
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/cypress-project/cypress-project.js +25 -5
- package/src/generators/cypress-project/schema.d.ts +1 -0
- package/src/generators/cypress-project/schema.json +1 -1
- package/src/generators/init/init.d.ts +2 -0
- package/src/generators/init/init.js +71 -15
- package/src/generators/init/schema.d.ts +4 -2
- package/src/generators/init/schema.json +19 -1
- package/src/generators/migrate-to-cypress-11/schema.json +1 -1
- package/src/migrations/update-18-1-0/update-cypress-version-13-6-6.d.ts +2 -0
- package/src/migrations/update-18-1-0/update-cypress-version-13-6-6.js +12 -0
- package/src/plugins/plugin.d.ts +9 -0
- package/src/plugins/plugin.js +215 -0
- package/src/utils/add-linter.d.ts +1 -0
- package/src/utils/add-linter.js +4 -4
- package/src/utils/config.d.ts +6 -7
- package/src/utils/config.js +39 -12
- package/src/utils/constants.d.ts +4 -0
- package/src/utils/constants.js +7 -0
- package/src/utils/ct-helpers.d.ts +1 -1
- package/src/utils/ct-helpers.js +6 -2
- package/src/utils/start-dev-server.d.ts +9 -0
- package/src/utils/start-dev-server.js +157 -0
- package/src/utils/versions.d.ts +3 -3
- package/src/utils/versions.js +3 -3
- /package/src/generators/base-setup/files/{__directory__ → common/__directory__}/fixtures/example.json +0 -0
- /package/src/generators/base-setup/files/{__directory__ → common/__directory__}/support/commands.ts__ext__ +0 -0
- /package/src/generators/base-setup/files/{__directory__ → common/__directory__}/tsconfig.json__ext__ +0 -0
- /package/src/generators/base-setup/files/{cypress.config.ts__ext__ → config-js-esm/cypress.config.js__ext__} +0 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startDevServer = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const detectPort = require("detect-port");
|
|
7
|
+
const executor_utils_1 = require("nx/src/command-line/run/executor-utils");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
async function* startDevServer(opts, context) {
|
|
10
|
+
// no dev server, return the provisioned base url
|
|
11
|
+
if (!opts.devServerTarget || opts.skipServe) {
|
|
12
|
+
yield { baseUrl: opts.baseUrl };
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const parsedDevServerTarget = (0, devkit_1.parseTargetString)(opts.devServerTarget, context);
|
|
16
|
+
const [targetSupportsWatchOpt] = getValueFromSchema(context, parsedDevServerTarget, 'watch');
|
|
17
|
+
const overrides = {
|
|
18
|
+
// @NOTE: Do not forward watch option if not supported by the target dev server,
|
|
19
|
+
// this is relevant for running Cypress against dev server target that does not support this option,
|
|
20
|
+
// for instance @nguniversal/builders:ssr-dev-server.
|
|
21
|
+
...(targetSupportsWatchOpt ? { watch: opts.watch } : {}),
|
|
22
|
+
};
|
|
23
|
+
if (opts.port === 'cypress-auto') {
|
|
24
|
+
const freePort = await getPortForProject(context, parsedDevServerTarget);
|
|
25
|
+
overrides['port'] = freePort;
|
|
26
|
+
}
|
|
27
|
+
else if (opts.port !== undefined) {
|
|
28
|
+
overrides['port'] = opts.port;
|
|
29
|
+
// zero is a special case that means any valid port so there is no reason to try to 'lock it'
|
|
30
|
+
if (opts.port !== 0) {
|
|
31
|
+
const didLock = attemptToLockPort(opts.port);
|
|
32
|
+
if (!didLock) {
|
|
33
|
+
devkit_1.logger.warn((0, devkit_1.stripIndents) `${opts.port} is potentially already in use by another cypress run.
|
|
34
|
+
If the port is in use, try using a different port value or passing --port='cypress-auto' to find a free port.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for await (const output of await (0, devkit_1.runExecutor)(parsedDevServerTarget, overrides, context)) {
|
|
39
|
+
if (!output.success && !opts.watch)
|
|
40
|
+
throw new Error('Could not compile application files');
|
|
41
|
+
if (!opts.baseUrl &&
|
|
42
|
+
!output.baseUrl &&
|
|
43
|
+
!output.info?.baseUrl &&
|
|
44
|
+
(output.port || output.info?.port)) {
|
|
45
|
+
output.baseUrl = `http://localhost:${output.info.port}`;
|
|
46
|
+
}
|
|
47
|
+
yield {
|
|
48
|
+
baseUrl: opts.baseUrl || output.baseUrl || output.info?.baseUrl,
|
|
49
|
+
portLockFilePath: overrides.port && (0, path_1.join)(__dirname, `${overrides.port}.txt`),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.startDevServer = startDevServer;
|
|
54
|
+
/**
|
|
55
|
+
* try to find a free port for the project to run on
|
|
56
|
+
* will return undefined if no port is found or the project doesn't have a port option
|
|
57
|
+
**/
|
|
58
|
+
async function getPortForProject(context, target, defaultPort = 4200) {
|
|
59
|
+
const fmtTarget = (0, devkit_1.targetToTargetString)(target);
|
|
60
|
+
const [hasPortOpt, schemaPortValue] = getValueFromSchema(context, target, 'port');
|
|
61
|
+
let freePort;
|
|
62
|
+
if (hasPortOpt) {
|
|
63
|
+
let normalizedPortValue;
|
|
64
|
+
if (!schemaPortValue) {
|
|
65
|
+
devkit_1.logger.info(`NX ${fmtTarget} did not have a defined port value, checking for free port with the default value of ${defaultPort}`);
|
|
66
|
+
normalizedPortValue = defaultPort;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
normalizedPortValue = Number(schemaPortValue);
|
|
70
|
+
}
|
|
71
|
+
if (isNaN(normalizedPortValue)) {
|
|
72
|
+
devkit_1.output.warn({
|
|
73
|
+
title: `Port Not a Number`,
|
|
74
|
+
bodyLines: [
|
|
75
|
+
`The port value found was not a number or can't be parsed to a number`,
|
|
76
|
+
`When reading the devServerTarget (${fmtTarget}) schema, expected ${schemaPortValue} to be a number but got NaN.`,
|
|
77
|
+
`Nx will use the default value of ${defaultPort} instead.`,
|
|
78
|
+
`You can manually specify a port by setting the 'port' option`,
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
normalizedPortValue = defaultPort;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
let attempts = 0;
|
|
85
|
+
// make sure when this check happens in parallel,
|
|
86
|
+
// we don't let the same port be used by multiple projects
|
|
87
|
+
do {
|
|
88
|
+
freePort = await detectPort(freePort || normalizedPortValue);
|
|
89
|
+
if (attemptToLockPort(freePort)) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
attempts++;
|
|
93
|
+
// increment port in case the lock file isn't cleaned up
|
|
94
|
+
freePort++;
|
|
95
|
+
} while (attempts < 20);
|
|
96
|
+
devkit_1.logger.info(`NX Using port ${freePort} for ${fmtTarget}`);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
throw new Error((0, devkit_1.stripIndents) `Unable to find a free port for the dev server, ${fmtTarget}.
|
|
100
|
+
You can disable auto port detection by specifing a port or not passing a value to --port`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
devkit_1.output.warn({
|
|
105
|
+
title: `No Port Option Found`,
|
|
106
|
+
bodyLines: [
|
|
107
|
+
`The 'port' option is set to 'cypress-auto', but the devServerTarget (${fmtTarget}) does not have a port option.`,
|
|
108
|
+
`Because of this, Nx is unable to verify the port is free before starting the dev server.`,
|
|
109
|
+
`This might cause issues if the devServerTarget is trying to use a port that is already in use.`,
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return freePort;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Check if the given target has the given property in it's options.
|
|
117
|
+
* if the property is does not have a default value or is not in the actual executor options,
|
|
118
|
+
* the value will be undefined even if it's in the executor schema.
|
|
119
|
+
**/
|
|
120
|
+
function getValueFromSchema(context, target, property) {
|
|
121
|
+
let targetOpts;
|
|
122
|
+
try {
|
|
123
|
+
targetOpts = (0, devkit_1.readTargetOptions)(target, context);
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
throw new Error(`Unable to read the target options for ${(0, devkit_1.targetToTargetString)(target)}.
|
|
127
|
+
Are you sure this is a valid target?
|
|
128
|
+
Was trying to read the target for the property: '${property}', but got the following error:
|
|
129
|
+
${e.message || e}`);
|
|
130
|
+
}
|
|
131
|
+
let targetHasOpt = Object.keys(targetOpts).includes(property);
|
|
132
|
+
if (!targetHasOpt) {
|
|
133
|
+
// NOTE: readTargetOptions doesn't apply non defaulted values, i.e. @nx/vite has a port options but is optional
|
|
134
|
+
// so we double check the schema if readTargetOptions didn't return a value for the property
|
|
135
|
+
const projectConfig = context.projectsConfigurations?.projects?.[target.project];
|
|
136
|
+
const targetConfig = projectConfig.targets[target.target];
|
|
137
|
+
const [collection, executor] = targetConfig.executor.split(':');
|
|
138
|
+
const { schema } = (0, executor_utils_1.getExecutorInformation)(collection, executor, context.root, context.projectsConfigurations.projects);
|
|
139
|
+
// NOTE: schema won't have a default since readTargetOptions would have
|
|
140
|
+
// already set that and this check wouldn't need to be made
|
|
141
|
+
targetHasOpt = Object.keys(schema.properties).includes(property);
|
|
142
|
+
}
|
|
143
|
+
return [targetHasOpt, targetOpts[property]];
|
|
144
|
+
}
|
|
145
|
+
function attemptToLockPort(port) {
|
|
146
|
+
const portLockFilePath = (0, path_1.join)(__dirname, `${port}.txt`);
|
|
147
|
+
try {
|
|
148
|
+
if ((0, fs_1.existsSync)(portLockFilePath)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
(0, fs_1.writeFileSync)(portLockFilePath, 'locked');
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
2
|
export declare const eslintPluginCypressVersion = "^2.13.4";
|
|
3
|
-
export declare const typesNodeVersion = "16.
|
|
3
|
+
export declare const typesNodeVersion = "18.16.9";
|
|
4
4
|
export declare const cypressViteDevServerVersion = "^2.2.1";
|
|
5
|
-
export declare const cypressVersion = "^13.
|
|
5
|
+
export declare const cypressVersion = "^13.6.6";
|
|
6
6
|
export declare const cypressWebpackVersion = "^2.0.0";
|
|
7
7
|
export declare const webpackHttpPluginVersion = "^5.5.0";
|
|
8
|
-
export declare const viteVersion = "~
|
|
8
|
+
export declare const viteVersion = "~5.0.0";
|
|
9
9
|
export declare const htmlWebpackPluginVersion = "^5.5.0";
|
package/src/utils/versions.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.htmlWebpackPluginVersion = exports.viteVersion = exports.webpackHttpPluginVersion = exports.cypressWebpackVersion = exports.cypressVersion = exports.cypressViteDevServerVersion = exports.typesNodeVersion = exports.eslintPluginCypressVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.eslintPluginCypressVersion = '^2.13.4';
|
|
6
|
-
exports.typesNodeVersion = '16.
|
|
6
|
+
exports.typesNodeVersion = '18.16.9';
|
|
7
7
|
exports.cypressViteDevServerVersion = '^2.2.1';
|
|
8
|
-
exports.cypressVersion = '^13.
|
|
8
|
+
exports.cypressVersion = '^13.6.6';
|
|
9
9
|
exports.cypressWebpackVersion = '^2.0.0';
|
|
10
10
|
exports.webpackHttpPluginVersion = '^5.5.0';
|
|
11
|
-
exports.viteVersion = '~
|
|
11
|
+
exports.viteVersion = '~5.0.0';
|
|
12
12
|
exports.htmlWebpackPluginVersion = '^5.5.0';
|
|
File without changes
|
|
File without changes
|
/package/src/generators/base-setup/files/{__directory__ → common/__directory__}/tsconfig.json__ext__
RENAMED
|
File without changes
|
|
File without changes
|