@nx/cypress 18.0.0-beta.0 → 18.0.0-beta.2
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/generators.json +3 -3
- package/index.d.ts +2 -2
- package/index.js +4 -4
- package/package.json +6 -6
- package/plugins/cypress-preset.d.ts +1 -0
- package/plugins/cypress-preset.js +1 -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 +19 -5
- package/src/generators/component-configuration/schema.d.ts +1 -0
- package/src/generators/component-configuration/schema.json +1 -1
- package/src/generators/configuration/configuration.d.ts +2 -0
- package/src/generators/configuration/configuration.js +18 -6
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/cypress-project/cypress-project.js +13 -2
- 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 +1 -0
- package/src/generators/init/init.js +10 -3
- package/src/generators/init/schema.d.ts +1 -0
- package/src/generators/init/schema.json +1 -1
- package/src/generators/migrate-to-cypress-11/schema.json +1 -1
- package/src/plugins/plugin.js +6 -49
- package/src/utils/config.d.ts +5 -4
- package/src/utils/config.js +32 -6
- /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
package/generators.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"version": "0.1",
|
|
4
4
|
"generators": {
|
|
5
5
|
"init": {
|
|
6
|
-
"factory": "./src/generators/init/init#
|
|
6
|
+
"factory": "./src/generators/init/init#cypressInitGeneratorInternal",
|
|
7
7
|
"schema": "./src/generators/init/schema.json",
|
|
8
8
|
"description": "Initialize the `@nrwl/cypress` plugin.",
|
|
9
9
|
"aliases": ["ng-add"],
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"configuration": {
|
|
19
19
|
"aliases": ["cypress-e2e-configuration", "e2e", "e2e-config"],
|
|
20
|
-
"factory": "./src/generators/configuration/configuration",
|
|
20
|
+
"factory": "./src/generators/configuration/configuration#configurationGeneratorInternal",
|
|
21
21
|
"schema": "./src/generators/configuration/schema.json",
|
|
22
22
|
"description": "Add a Cypress E2E Configuration to an existing project."
|
|
23
23
|
},
|
|
24
24
|
"component-configuration": {
|
|
25
25
|
"aliases": ["cypress-component-configuration"],
|
|
26
|
-
"factory": "./src/generators/component-configuration/component-configuration",
|
|
26
|
+
"factory": "./src/generators/component-configuration/component-configuration#componentConfigurationGeneratorInternal",
|
|
27
27
|
"schema": "./src/generators/component-configuration/schema.json",
|
|
28
28
|
"description": "Set up Cypress Component Test for a project",
|
|
29
29
|
"hidden": true
|
package/index.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { configurationGenerator } from './src/generators/configuration/configura
|
|
|
2
2
|
import { componentConfigurationGenerator } from './src/generators/component-configuration/component-configuration';
|
|
3
3
|
import { cypressProjectGenerator as _cypressProjectGenerator } from './src/generators/cypress-project/cypress-project';
|
|
4
4
|
export { configurationGenerator, componentConfigurationGenerator };
|
|
5
|
-
/** @deprecated Use `configurationGenerator` instead. It will be removed in Nx
|
|
5
|
+
/** @deprecated Use `configurationGenerator` instead. It will be removed in Nx 19. */
|
|
6
6
|
export declare const cypressComponentConfiguration: typeof componentConfigurationGenerator;
|
|
7
7
|
export { configurationGenerator as cypressE2EConfigurationGenerator };
|
|
8
|
-
/** @deprecated Add a new project and call `configurationGenerator` instead. It will be removed in Nx
|
|
8
|
+
/** @deprecated Add a new project and call `configurationGenerator` instead. It will be removed in Nx 19. */
|
|
9
9
|
export declare const cypressProjectGenerator: typeof _cypressProjectGenerator;
|
|
10
10
|
export { cypressInitGenerator } from './src/generators/init/init';
|
|
11
11
|
export { migrateCypressProject } from './src/generators/migrate-to-cypress-11/migrate-to-cypress-11';
|
package/index.js
CHANGED
|
@@ -8,11 +8,11 @@ const component_configuration_1 = require("./src/generators/component-configurat
|
|
|
8
8
|
Object.defineProperty(exports, "componentConfigurationGenerator", { enumerable: true, get: function () { return component_configuration_1.componentConfigurationGenerator; } });
|
|
9
9
|
const cypress_project_1 = require("./src/generators/cypress-project/cypress-project");
|
|
10
10
|
// Maintain backwards compatibility with the old names in case community plugins used them.
|
|
11
|
-
// TODO(
|
|
12
|
-
/** @deprecated Use `configurationGenerator` instead. It will be removed in Nx
|
|
11
|
+
// TODO(v19): Remove old name
|
|
12
|
+
/** @deprecated Use `configurationGenerator` instead. It will be removed in Nx 19. */
|
|
13
13
|
exports.cypressComponentConfiguration = component_configuration_1.componentConfigurationGenerator;
|
|
14
|
-
// TODO(
|
|
15
|
-
/** @deprecated Add a new project and call `configurationGenerator` instead. It will be removed in Nx
|
|
14
|
+
// TODO(v19): Remove project generator
|
|
15
|
+
/** @deprecated Add a new project and call `configurationGenerator` instead. It will be removed in Nx 19. */
|
|
16
16
|
exports.cypressProjectGenerator = cypress_project_1.cypressProjectGenerator;
|
|
17
17
|
var init_1 = require("./src/generators/init/init");
|
|
18
18
|
Object.defineProperty(exports, "cypressInitGenerator", { enumerable: true, get: function () { return init_1.cypressInitGenerator; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/cypress",
|
|
3
|
-
"version": "18.0.0-beta.
|
|
3
|
+
"version": "18.0.0-beta.2",
|
|
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": {
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"migrations": "./migrations.json"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nx/devkit": "18.0.0-beta.
|
|
38
|
-
"@nx/eslint": "18.0.0-beta.
|
|
39
|
-
"@nx/js": "18.0.0-beta.
|
|
37
|
+
"@nx/devkit": "18.0.0-beta.2",
|
|
38
|
+
"@nx/eslint": "18.0.0-beta.2",
|
|
39
|
+
"@nx/js": "18.0.0-beta.2",
|
|
40
40
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
41
41
|
"detect-port": "^1.5.1",
|
|
42
|
-
"semver": "7.5.3",
|
|
42
|
+
"semver": "^7.5.3",
|
|
43
43
|
"tslib": "^2.3.0",
|
|
44
|
-
"@nrwl/cypress": "18.0.0-beta.
|
|
44
|
+
"@nrwl/cypress": "18.0.0-beta.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"cypress": ">= 3 < 14"
|
|
@@ -61,7 +61,7 @@ function nxE2EPreset(pathToConfig, options) {
|
|
|
61
61
|
}*/ = {
|
|
62
62
|
...nxBaseCypressPreset(pathToConfig),
|
|
63
63
|
fileServerFolder: '.',
|
|
64
|
-
supportFile: `${basePath}/support/e2e.ts`,
|
|
64
|
+
supportFile: `${basePath}/support/e2e.{js,ts}`,
|
|
65
65
|
specPattern: `${basePath}/**/*.cy.{js,jsx,ts,tsx}`,
|
|
66
66
|
fixturesFolder: `${basePath}/fixtures`,
|
|
67
67
|
[symbols_1.NX_PLUGIN_OPTIONS]: {
|
|
@@ -6,11 +6,12 @@ const js_1 = require("@nx/js");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
function addBaseCypressSetup(tree, options) {
|
|
8
8
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
9
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts'))
|
|
9
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts')) ||
|
|
10
|
+
tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.js'))) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
const opts = normalizeOptions(tree, projectConfig, options);
|
|
13
|
-
|
|
14
|
+
const templateVars = {
|
|
14
15
|
...opts,
|
|
15
16
|
jsx: !!opts.jsx,
|
|
16
17
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(projectConfig.root),
|
|
@@ -19,7 +20,19 @@ function addBaseCypressSetup(tree, options) {
|
|
|
19
20
|
? `${opts.offsetFromProjectRoot}tsconfig.json`
|
|
20
21
|
: (0, js_1.getRelativePathToRootTsConfig)(tree, projectConfig.root),
|
|
21
22
|
ext: '',
|
|
22
|
-
}
|
|
23
|
+
};
|
|
24
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files/common'), projectConfig.root, templateVars);
|
|
25
|
+
if (options.js) {
|
|
26
|
+
if (isEsmProject(tree, projectConfig.root)) {
|
|
27
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files/config-js-esm'), projectConfig.root, templateVars);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files/config-js-cjs'), projectConfig.root, templateVars);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files/config-ts'), projectConfig.root, templateVars);
|
|
35
|
+
}
|
|
23
36
|
if (opts.hasTsConfig) {
|
|
24
37
|
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json'), (json) => {
|
|
25
38
|
// tsconfig doesn't have references so it shouldn't add them
|
|
@@ -55,3 +68,13 @@ function normalizeOptions(tree, projectConfig, options) {
|
|
|
55
68
|
hasTsConfig,
|
|
56
69
|
};
|
|
57
70
|
}
|
|
71
|
+
function isEsmProject(tree, projectRoot) {
|
|
72
|
+
let packageJson;
|
|
73
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'package.json'))) {
|
|
74
|
+
packageJson = (0, devkit_1.readJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
packageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
78
|
+
}
|
|
79
|
+
return packageJson.type === 'module';
|
|
80
|
+
}
|
package/src/generators/base-setup/files/config-js-cjs/__directory__/support/commands.js__ext__
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
// ***********************************************
|
|
4
|
+
// This example commands.ts shows you how to
|
|
5
|
+
// create various custom commands and overwrite
|
|
6
|
+
// existing commands.
|
|
7
|
+
//
|
|
8
|
+
// For more comprehensive examples of custom
|
|
9
|
+
// commands please read more here:
|
|
10
|
+
// https://on.cypress.io/custom-commands
|
|
11
|
+
// ***********************************************
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
14
|
+
declare namespace Cypress {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
interface Chainable<Subject> {
|
|
17
|
+
login(email: string, password: string): void;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// -- This is a parent command --
|
|
22
|
+
Cypress.Commands.add('login', (email, password) => {
|
|
23
|
+
console.log('Custom command example: Login', email, password);
|
|
24
|
+
});
|
|
25
|
+
//
|
|
26
|
+
// -- This is a child command --
|
|
27
|
+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
|
28
|
+
//
|
|
29
|
+
//
|
|
30
|
+
// -- This is a dual command --
|
|
31
|
+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
32
|
+
//
|
|
33
|
+
//
|
|
34
|
+
// -- This will overwrite an existing command --
|
|
35
|
+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
package/src/generators/base-setup/files/config-js-esm/__directory__/support/commands.js__ext__
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
// ***********************************************
|
|
4
|
+
// This example commands.ts shows you how to
|
|
5
|
+
// create various custom commands and overwrite
|
|
6
|
+
// existing commands.
|
|
7
|
+
//
|
|
8
|
+
// For more comprehensive examples of custom
|
|
9
|
+
// commands please read more here:
|
|
10
|
+
// https://on.cypress.io/custom-commands
|
|
11
|
+
// ***********************************************
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
14
|
+
declare namespace Cypress {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
interface Chainable<Subject> {
|
|
17
|
+
login(email: string, password: string): void;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// -- This is a parent command --
|
|
22
|
+
Cypress.Commands.add('login', (email, password) => {
|
|
23
|
+
console.log('Custom command example: Login', email, password);
|
|
24
|
+
});
|
|
25
|
+
//
|
|
26
|
+
// -- This is a child command --
|
|
27
|
+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
|
28
|
+
//
|
|
29
|
+
//
|
|
30
|
+
// -- This is a dual command --
|
|
31
|
+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
32
|
+
//
|
|
33
|
+
//
|
|
34
|
+
// -- This will overwrite an existing command --
|
|
35
|
+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
// ***********************************************
|
|
4
|
+
// This example commands.ts shows you how to
|
|
5
|
+
// create various custom commands and overwrite
|
|
6
|
+
// existing commands.
|
|
7
|
+
//
|
|
8
|
+
// For more comprehensive examples of custom
|
|
9
|
+
// commands please read more here:
|
|
10
|
+
// https://on.cypress.io/custom-commands
|
|
11
|
+
// ***********************************************
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
14
|
+
declare namespace Cypress {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
interface Chainable<Subject> {
|
|
17
|
+
login(email: string, password: string): void;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// -- This is a parent command --
|
|
22
|
+
Cypress.Commands.add('login', (email, password) => {
|
|
23
|
+
console.log('Custom command example: Login', email, password);
|
|
24
|
+
});
|
|
25
|
+
//
|
|
26
|
+
// -- This is a child command --
|
|
27
|
+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
|
28
|
+
//
|
|
29
|
+
//
|
|
30
|
+
// -- This is a dual command --
|
|
31
|
+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
32
|
+
//
|
|
33
|
+
//
|
|
34
|
+
// -- This will overwrite an existing command --
|
|
35
|
+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ProjectConfiguration, Tree } from '@nx/devkit';
|
|
1
|
+
import { ProjectConfiguration, Tree, GeneratorCallback } from '@nx/devkit';
|
|
2
2
|
import { CypressComponentConfigurationSchema } from './schema';
|
|
3
|
-
export declare function componentConfigurationGenerator(tree: Tree, options: CypressComponentConfigurationSchema): Promise<
|
|
3
|
+
export declare function componentConfigurationGenerator(tree: Tree, options: CypressComponentConfigurationSchema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function componentConfigurationGeneratorInternal(tree: Tree, options: CypressComponentConfigurationSchema): Promise<GeneratorCallback>;
|
|
4
5
|
export declare function updateTsConfigForComponentTesting(tree: Tree, projectConfig: ProjectConfiguration): void;
|
|
5
6
|
export default componentConfigurationGenerator;
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateTsConfigForComponentTesting = exports.componentConfigurationGenerator = void 0;
|
|
3
|
+
exports.updateTsConfigForComponentTesting = exports.componentConfigurationGeneratorInternal = exports.componentConfigurationGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const cypress_version_1 = require("../../utils/cypress-version");
|
|
6
6
|
const versions_1 = require("../../utils/versions");
|
|
7
7
|
const base_setup_1 = require("../base-setup/base-setup");
|
|
8
|
-
|
|
8
|
+
const init_1 = require("../init/init");
|
|
9
|
+
function componentConfigurationGenerator(tree, options) {
|
|
10
|
+
return componentConfigurationGeneratorInternal(tree, {
|
|
11
|
+
addPlugin: false,
|
|
12
|
+
...options,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.componentConfigurationGenerator = componentConfigurationGenerator;
|
|
16
|
+
async function componentConfigurationGeneratorInternal(tree, options) {
|
|
17
|
+
const tasks = [];
|
|
9
18
|
const opts = normalizeOptions(options);
|
|
19
|
+
tasks.push(await (0, init_1.default)(tree, {
|
|
20
|
+
...opts,
|
|
21
|
+
skipFormat: true,
|
|
22
|
+
}));
|
|
10
23
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
11
24
|
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
|
|
12
25
|
? p === '@nx/cypress/plugin'
|
|
13
26
|
: p.plugin === '@nx/cypress/plugin');
|
|
14
27
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, opts.project);
|
|
15
|
-
|
|
28
|
+
tasks.push(updateDeps(tree, opts));
|
|
16
29
|
addProjectFiles(tree, projectConfig, opts);
|
|
17
30
|
if (!hasPlugin) {
|
|
18
31
|
addTargetToProject(tree, projectConfig, opts);
|
|
@@ -22,15 +35,16 @@ async function componentConfigurationGenerator(tree, options) {
|
|
|
22
35
|
if (!opts.skipFormat) {
|
|
23
36
|
await (0, devkit_1.formatFiles)(tree);
|
|
24
37
|
}
|
|
25
|
-
return
|
|
38
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
26
39
|
}
|
|
27
|
-
exports.
|
|
40
|
+
exports.componentConfigurationGeneratorInternal = componentConfigurationGeneratorInternal;
|
|
28
41
|
function normalizeOptions(options) {
|
|
29
42
|
const cyVersion = (0, cypress_version_1.installedCypressVersion)();
|
|
30
43
|
if (cyVersion && cyVersion < 10) {
|
|
31
44
|
throw new Error('Cypress version of 10 or higher is required to use component testing. See the migration guide to upgrade. https://nx.dev/cypress/v11-migration-guide');
|
|
32
45
|
}
|
|
33
46
|
return {
|
|
47
|
+
addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
|
|
34
48
|
...options,
|
|
35
49
|
directory: options.directory ?? 'cypress',
|
|
36
50
|
};
|
|
@@ -16,6 +16,8 @@ export interface CypressE2EConfigSchema {
|
|
|
16
16
|
rootProject?: boolean;
|
|
17
17
|
webServerCommands?: Record<string, string>;
|
|
18
18
|
ciWebServerCommand?: string;
|
|
19
|
+
addPlugin?: boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare function configurationGenerator(tree: Tree, options: CypressE2EConfigSchema): Promise<GeneratorCallback>;
|
|
22
|
+
export declare function configurationGeneratorInternal(tree: Tree, options: CypressE2EConfigSchema): Promise<GeneratorCallback>;
|
|
21
23
|
export default configurationGenerator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configurationGenerator = void 0;
|
|
3
|
+
exports.configurationGeneratorInternal = exports.configurationGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const js_1 = require("@nx/js");
|
|
6
6
|
const eslint_1 = require("@nx/eslint");
|
|
@@ -11,12 +11,20 @@ const cypress_version_1 = require("../../utils/cypress-version");
|
|
|
11
11
|
const versions_1 = require("../../utils/versions");
|
|
12
12
|
const init_1 = require("../init/init");
|
|
13
13
|
const base_setup_1 = require("../base-setup/base-setup");
|
|
14
|
-
|
|
14
|
+
function configurationGenerator(tree, options) {
|
|
15
|
+
return configurationGeneratorInternal(tree, { addPlugin: false, ...options });
|
|
16
|
+
}
|
|
17
|
+
exports.configurationGenerator = configurationGenerator;
|
|
18
|
+
async function configurationGeneratorInternal(tree, options) {
|
|
15
19
|
const opts = normalizeOptions(tree, options);
|
|
16
20
|
const tasks = [];
|
|
17
21
|
if (!(0, cypress_version_1.installedCypressVersion)()) {
|
|
18
22
|
tasks.push(await (0, js_1.initGenerator)(tree, { ...options, skipFormat: true }));
|
|
19
|
-
tasks.push(await (0, init_1.default)(tree, {
|
|
23
|
+
tasks.push(await (0, init_1.default)(tree, {
|
|
24
|
+
...opts,
|
|
25
|
+
skipFormat: true,
|
|
26
|
+
addPlugin: options.addPlugin,
|
|
27
|
+
}));
|
|
20
28
|
}
|
|
21
29
|
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
22
30
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
@@ -40,7 +48,7 @@ async function configurationGenerator(tree, options) {
|
|
|
40
48
|
}
|
|
41
49
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
42
50
|
}
|
|
43
|
-
exports.
|
|
51
|
+
exports.configurationGeneratorInternal = configurationGeneratorInternal;
|
|
44
52
|
function ensureDependencies(tree, options) {
|
|
45
53
|
const devDependencies = {
|
|
46
54
|
'@types/node': versions_1.typesNodeVersion,
|
|
@@ -70,6 +78,7 @@ In this case you need to provide a devServerTarget,'<projectName>:<targetName>[:
|
|
|
70
78
|
}
|
|
71
79
|
return {
|
|
72
80
|
...options,
|
|
81
|
+
addPlugin: options.addPlugin ?? process.env.NX_ADD_PLUGINS !== 'false',
|
|
73
82
|
bundler: options.bundler ?? 'webpack',
|
|
74
83
|
rootProject: options.rootProject ?? projectConfig.root === '.',
|
|
75
84
|
linter: options.linter ?? eslint_1.Linter.EsLint,
|
|
@@ -103,8 +112,9 @@ async function addFiles(tree, options, projectGraph, hasPlugin) {
|
|
|
103
112
|
project: options.project,
|
|
104
113
|
directory: options.directory,
|
|
105
114
|
jsx: options.jsx,
|
|
115
|
+
js: options.js,
|
|
106
116
|
});
|
|
107
|
-
const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
|
|
117
|
+
const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, options.js ? 'cypress.config.js' : 'cypress.config.ts');
|
|
108
118
|
let webServerCommands;
|
|
109
119
|
let ciWebServerCommand;
|
|
110
120
|
if (hasPlugin && options.webServerCommands && options.ciWebServerCommand) {
|
|
@@ -158,7 +168,9 @@ function addTarget(tree, opts) {
|
|
|
158
168
|
projectConfig.targets.e2e = {
|
|
159
169
|
executor: '@nx/cypress:cypress',
|
|
160
170
|
options: {
|
|
161
|
-
cypressConfig: (0, devkit_1.joinPathFragments)(projectConfig.root, cyVersion && cyVersion < 10
|
|
171
|
+
cypressConfig: (0, devkit_1.joinPathFragments)(projectConfig.root, cyVersion && cyVersion < 10
|
|
172
|
+
? 'cypress.json'
|
|
173
|
+
: `cypress.config.${opts.js ? 'js' : 'ts'}`),
|
|
162
174
|
testingType: 'e2e',
|
|
163
175
|
},
|
|
164
176
|
};
|
|
@@ -12,6 +12,7 @@ const add_linter_1 = require("../../utils/add-linter");
|
|
|
12
12
|
const cypress_version_1 = require("../../utils/cypress-version");
|
|
13
13
|
const versions_1 = require("../../utils/versions");
|
|
14
14
|
const init_1 = require("../init/init");
|
|
15
|
+
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
15
16
|
function createFiles(tree, options) {
|
|
16
17
|
// if not installed or >v10 use v10 folder
|
|
17
18
|
// else use v9 folder
|
|
@@ -119,6 +120,7 @@ function addProject(tree, options) {
|
|
|
119
120
|
async function cypressProjectGenerator(host, schema) {
|
|
120
121
|
return await cypressProjectGeneratorInternal(host, {
|
|
121
122
|
projectNameAndRootFormat: 'derived',
|
|
123
|
+
addPlugin: false,
|
|
122
124
|
...schema,
|
|
123
125
|
});
|
|
124
126
|
}
|
|
@@ -134,7 +136,11 @@ async function cypressProjectGeneratorInternal(host, schema) {
|
|
|
134
136
|
// init since we want to keep the existing version that is installed
|
|
135
137
|
if (!cypressVersion) {
|
|
136
138
|
tasks.push(await (0, js_1.initGenerator)(host, { ...options, skipFormat: true }));
|
|
137
|
-
tasks.push(await (0, init_1.cypressInitGenerator)(host, {
|
|
139
|
+
tasks.push(await (0, init_1.cypressInitGenerator)(host, {
|
|
140
|
+
...options,
|
|
141
|
+
skipFormat: true,
|
|
142
|
+
addPlugin: options.addPlugin,
|
|
143
|
+
}));
|
|
138
144
|
}
|
|
139
145
|
createFiles(host, options);
|
|
140
146
|
addProject(host, options);
|
|
@@ -162,7 +168,12 @@ function ensureDependencies(tree, options) {
|
|
|
162
168
|
if (options.bundler === 'vite') {
|
|
163
169
|
devDependencies['vite'] = versions_1.viteVersion;
|
|
164
170
|
}
|
|
165
|
-
return (0, devkit_1.
|
|
171
|
+
return (0, devkit_1.runTasksInSerial)(...[
|
|
172
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies),
|
|
173
|
+
() => {
|
|
174
|
+
(0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
|
|
175
|
+
},
|
|
176
|
+
]);
|
|
166
177
|
}
|
|
167
178
|
async function normalizeOptions(host, options) {
|
|
168
179
|
let maybeRootProject;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
2
|
import { Schema } from './schema';
|
|
3
3
|
export declare function cypressInitGenerator(tree: Tree, options: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function cypressInitGeneratorInternal(tree: Tree, options: Schema): Promise<GeneratorCallback>;
|
|
4
5
|
export default cypressInitGenerator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cypressInitGenerator = void 0;
|
|
3
|
+
exports.cypressInitGeneratorInternal = exports.cypressInitGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
|
|
6
6
|
const plugin_1 = require("../../plugins/plugin");
|
|
@@ -63,8 +63,13 @@ function updateProductionFileset(tree) {
|
|
|
63
63
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
64
64
|
}
|
|
65
65
|
async function cypressInitGenerator(tree, options) {
|
|
66
|
+
return cypressInitGeneratorInternal(tree, { addPlugin: false, ...options });
|
|
67
|
+
}
|
|
68
|
+
exports.cypressInitGenerator = cypressInitGenerator;
|
|
69
|
+
async function cypressInitGeneratorInternal(tree, options) {
|
|
66
70
|
updateProductionFileset(tree);
|
|
67
|
-
|
|
71
|
+
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
|
|
72
|
+
if (options.addPlugin) {
|
|
68
73
|
addPlugin(tree);
|
|
69
74
|
}
|
|
70
75
|
else {
|
|
@@ -75,12 +80,14 @@ async function cypressInitGenerator(tree, options) {
|
|
|
75
80
|
installTask = updateDependencies(tree, options);
|
|
76
81
|
}
|
|
77
82
|
if (options.updatePackageScripts) {
|
|
83
|
+
global.NX_CYPRESS_INIT_GENERATOR_RUNNING = true;
|
|
78
84
|
await (0, update_package_scripts_1.updatePackageScripts)(tree, plugin_1.createNodes);
|
|
85
|
+
global.NX_CYPRESS_INIT_GENERATOR_RUNNING = false;
|
|
79
86
|
}
|
|
80
87
|
if (!options.skipFormat) {
|
|
81
88
|
await (0, devkit_1.formatFiles)(tree);
|
|
82
89
|
}
|
|
83
90
|
return installTask;
|
|
84
91
|
}
|
|
85
|
-
exports.
|
|
92
|
+
exports.cypressInitGeneratorInternal = cypressInitGeneratorInternal;
|
|
86
93
|
exports.default = cypressInitGenerator;
|
package/src/plugins/plugin.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createNodes = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const internal_1 = require("@nx/js/src/internal");
|
|
7
6
|
const js_1 = require("@nx/js");
|
|
8
7
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
9
8
|
const fs_1 = require("fs");
|
|
@@ -11,6 +10,7 @@ const workspace_context_1 = require("nx/src/utils/workspace-context");
|
|
|
11
10
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
12
11
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
13
12
|
const symbols_1 = require("../utils/symbols");
|
|
13
|
+
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
14
14
|
const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'cypress.hash');
|
|
15
15
|
const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
|
|
16
16
|
const calculatedTargets = {};
|
|
@@ -27,7 +27,7 @@ const createDependencies = () => {
|
|
|
27
27
|
exports.createDependencies = createDependencies;
|
|
28
28
|
exports.createNodes = [
|
|
29
29
|
'**/cypress.config.{js,ts,mjs,cjs}',
|
|
30
|
-
(configFilePath, options, context) => {
|
|
30
|
+
async (configFilePath, options, context) => {
|
|
31
31
|
options = normalizeOptions(options);
|
|
32
32
|
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
33
33
|
// Do not create a project if package.json and project.json isn't there.
|
|
@@ -41,7 +41,7 @@ exports.createNodes = [
|
|
|
41
41
|
]);
|
|
42
42
|
const targets = targetsCache[hash]
|
|
43
43
|
? targetsCache[hash]
|
|
44
|
-
: buildCypressTargets(configFilePath, projectRoot, options, context);
|
|
44
|
+
: await buildCypressTargets(configFilePath, projectRoot, options, context);
|
|
45
45
|
calculatedTargets[hash] = targets;
|
|
46
46
|
return {
|
|
47
47
|
projects: {
|
|
@@ -92,8 +92,8 @@ function getOutputs(projectRoot, cypressConfig, testingType) {
|
|
|
92
92
|
}
|
|
93
93
|
return outputs;
|
|
94
94
|
}
|
|
95
|
-
function buildCypressTargets(configFilePath, projectRoot, options, context) {
|
|
96
|
-
const cypressConfig =
|
|
95
|
+
async function buildCypressTargets(configFilePath, projectRoot, options, context) {
|
|
96
|
+
const cypressConfig = await (0, config_utils_1.loadConfigFile)((0, path_1.join)(context.workspaceRoot, configFilePath));
|
|
97
97
|
const pluginPresetOptions = {
|
|
98
98
|
...cypressConfig.e2e?.[symbols_1.NX_PLUGIN_OPTIONS],
|
|
99
99
|
...cypressConfig.env,
|
|
@@ -167,7 +167,7 @@ function buildCypressTargets(configFilePath, projectRoot, options, context) {
|
|
|
167
167
|
if ('component' in cypressConfig) {
|
|
168
168
|
// This will not override the e2e target if it is the same
|
|
169
169
|
targets[options.componentTestingTargetName] ??= {
|
|
170
|
-
command: `cypress
|
|
170
|
+
command: `cypress run --component`,
|
|
171
171
|
options: { cwd: projectRoot },
|
|
172
172
|
cache: true,
|
|
173
173
|
inputs: getInputs(namedInputs),
|
|
@@ -176,29 +176,6 @@ function buildCypressTargets(configFilePath, projectRoot, options, context) {
|
|
|
176
176
|
}
|
|
177
177
|
return targets;
|
|
178
178
|
}
|
|
179
|
-
function getCypressConfig(configFilePath, context) {
|
|
180
|
-
const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
|
|
181
|
-
let module;
|
|
182
|
-
if ((0, path_1.extname)(configFilePath) === '.ts') {
|
|
183
|
-
const tsConfigPath = (0, js_1.getRootTsConfigPath)();
|
|
184
|
-
if (tsConfigPath) {
|
|
185
|
-
const unregisterTsProject = (0, internal_1.registerTsProject)(tsConfigPath);
|
|
186
|
-
try {
|
|
187
|
-
module = load(resolvedPath);
|
|
188
|
-
}
|
|
189
|
-
finally {
|
|
190
|
-
unregisterTsProject();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
module = load(resolvedPath);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
module = load(resolvedPath);
|
|
199
|
-
}
|
|
200
|
-
return module.default ?? module;
|
|
201
|
-
}
|
|
202
179
|
function normalizeOptions(options) {
|
|
203
180
|
options ??= {};
|
|
204
181
|
options.targetName ??= 'e2e';
|
|
@@ -216,23 +193,3 @@ function getInputs(namedInputs) {
|
|
|
216
193
|
},
|
|
217
194
|
];
|
|
218
195
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Load the module after ensuring that the require cache is cleared.
|
|
221
|
-
*/
|
|
222
|
-
const packageInstallationDirectories = ['node_modules', '.yarn'];
|
|
223
|
-
function load(path) {
|
|
224
|
-
// Clear cache if the path is in the cache
|
|
225
|
-
if (require.cache[path]) {
|
|
226
|
-
for (const k of Object.keys(require.cache)) {
|
|
227
|
-
// We don't want to clear the require cache of installed packages.
|
|
228
|
-
// Clearing them can cause some issues when running Nx without the daemon
|
|
229
|
-
// and may cause issues for other packages that use the module state
|
|
230
|
-
// in some to store cached information.
|
|
231
|
-
if (!packageInstallationDirectories.some((dir) => k.includes(dir))) {
|
|
232
|
-
delete require.cache[k];
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
// Then require
|
|
237
|
-
return require(path);
|
|
238
|
-
}
|
package/src/utils/config.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import type { NxComponentTestingOptions, NxCypressE2EPresetOptions } from '../../plugins/cypress-preset';
|
|
3
|
+
export declare const CYPRESS_CONFIG_FILE_NAME_PATTERN = "cypress.config.{js,ts,mjs,cjs}";
|
|
2
4
|
export declare function addDefaultE2EConfig(cyConfigContents: string, options: NxCypressE2EPresetOptions, baseUrl: string): Promise<string>;
|
|
3
5
|
/**
|
|
4
6
|
* Adds the nxComponentTestingPreset to the cypress config file
|
|
5
7
|
* Make sure after calling this the correct import statement is addeda
|
|
6
8
|
* to bring in the nxComponentTestingPreset function
|
|
7
9
|
**/
|
|
8
|
-
export declare function addDefaultCTConfig(cyConfigContents: string, options?:
|
|
9
|
-
bundler?: string;
|
|
10
|
-
}): Promise<string>;
|
|
10
|
+
export declare function addDefaultCTConfig(cyConfigContents: string, options?: NxComponentTestingOptions): Promise<string>;
|
|
11
11
|
/**
|
|
12
12
|
* Adds the mount command for Cypress
|
|
13
13
|
* Make sure after calling this the correct import statement is added
|
|
14
14
|
* to bring in the correct mount from cypress.
|
|
15
15
|
**/
|
|
16
16
|
export declare function addMountDefinition(cmpCommandFileContents: string): Promise<string>;
|
|
17
|
+
export declare function getProjectCypressConfigPath(tree: Tree, projectRoot: string): string;
|
package/src/utils/config.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addMountDefinition = exports.addDefaultCTConfig = exports.addDefaultE2EConfig = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.getProjectCypressConfigPath = exports.addMountDefinition = exports.addDefaultCTConfig = exports.addDefaultE2EConfig = exports.CYPRESS_CONFIG_FILE_NAME_PATTERN = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
exports.CYPRESS_CONFIG_FILE_NAME_PATTERN = 'cypress.config.{js,ts,mjs,cjs}';
|
|
6
|
+
const TS_QUERY_COMMON_JS_EXPORT_SELECTOR = 'BinaryExpression:has(Identifier[name="module"]):has(Identifier[name="exports"])';
|
|
7
|
+
const TS_QUERY_EXPORT_CONFIG_PREFIX = `:matches(ExportAssignment, ${TS_QUERY_COMMON_JS_EXPORT_SELECTOR}) `;
|
|
5
8
|
async function addDefaultE2EConfig(cyConfigContents, options, baseUrl) {
|
|
6
9
|
if (!cyConfigContents) {
|
|
7
10
|
throw new Error('The passed in cypress config file is empty!');
|
|
8
11
|
}
|
|
9
12
|
const { tsquery } = await Promise.resolve().then(() => require('@phenomnomnominal/tsquery'));
|
|
13
|
+
const isCommonJS = tsquery.query(cyConfigContents, TS_QUERY_COMMON_JS_EXPORT_SELECTOR).length >
|
|
14
|
+
0;
|
|
10
15
|
const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name="e2e"])`);
|
|
11
16
|
let updatedConfigContents = cyConfigContents;
|
|
12
17
|
if (testingTypeConfig.length === 0) {
|
|
@@ -23,7 +28,11 @@ async function addDefaultE2EConfig(cyConfigContents, options, baseUrl) {
|
|
|
23
28
|
e2e: { ...${configValue}${baseUrlContents} }
|
|
24
29
|
}`;
|
|
25
30
|
});
|
|
26
|
-
return
|
|
31
|
+
return isCommonJS
|
|
32
|
+
? `const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset');
|
|
33
|
+
|
|
34
|
+
${updatedConfigContents}`
|
|
35
|
+
: `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
|
|
27
36
|
|
|
28
37
|
${updatedConfigContents}`;
|
|
29
38
|
}
|
|
@@ -43,9 +52,16 @@ async function addDefaultCTConfig(cyConfigContents, options = {}) {
|
|
|
43
52
|
const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name="component"])`);
|
|
44
53
|
let updatedConfigContents = cyConfigContents;
|
|
45
54
|
if (testingTypeConfig.length === 0) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
let configValue = 'nxComponentTestingPreset(__filename)';
|
|
56
|
+
if (options) {
|
|
57
|
+
if (options.bundler !== 'vite') {
|
|
58
|
+
// vite is the default bundler, so we don't need to set it
|
|
59
|
+
delete options.bundler;
|
|
60
|
+
}
|
|
61
|
+
if (Object.keys(options).length) {
|
|
62
|
+
configValue = `nxComponentTestingPreset(__filename, ${JSON.stringify(options)})`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
49
65
|
updatedConfigContents = tsquery.replace(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node) => {
|
|
50
66
|
if (node.properties.length > 0) {
|
|
51
67
|
return `{
|
|
@@ -87,3 +103,13 @@ async function addMountDefinition(cmpCommandFileContents) {
|
|
|
87
103
|
return `${updatedInterface}\n${mountCommand}`;
|
|
88
104
|
}
|
|
89
105
|
exports.addMountDefinition = addMountDefinition;
|
|
106
|
+
function getProjectCypressConfigPath(tree, projectRoot) {
|
|
107
|
+
const cypressConfigPaths = (0, devkit_1.glob)(tree, [
|
|
108
|
+
`${projectRoot}/${exports.CYPRESS_CONFIG_FILE_NAME_PATTERN}`,
|
|
109
|
+
]);
|
|
110
|
+
if (cypressConfigPaths.length === 0) {
|
|
111
|
+
throw new Error(`Could not find a cypress config file in ${projectRoot}.`);
|
|
112
|
+
}
|
|
113
|
+
return cypressConfigPaths[0];
|
|
114
|
+
}
|
|
115
|
+
exports.getProjectCypressConfigPath = getProjectCypressConfigPath;
|
|
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
|