Skip to content

Commit 4aa7282

Browse files
authored
fix(angular): warning logged when generating MF app with no e2e (#11911)
1 parent 81b5eeb commit 4aa7282

File tree

9 files changed

+63
-4
lines changed

9 files changed

+63
-4
lines changed

docs/generated/packages/angular.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,11 @@
19681968
"default": false,
19691969
"description": "Do not add dependencies to `package.json`."
19701970
},
1971+
"skipE2E": {
1972+
"type": "boolean",
1973+
"default": false,
1974+
"description": "Do not set up E2E related config."
1975+
},
19711976
"e2eProjectName": {
19721977
"type": "string",
19731978
"description": "The project name of the associated E2E project for the application. This is only required for Cypress E2E projects that do not follow the naming convention `<appName>-e2e`."

packages/angular/src/generators/host/host.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
22
import host from './host';
33
import remote from '../remote/remote';
4+
import { E2eTestRunner } from '../../utils/test-runners';
5+
import { getProjects } from 'nx/src/generators/utils/project-configuration';
46

57
describe('Host App Generator', () => {
68
it('should generate a host app with no remotes', async () => {
@@ -166,4 +168,21 @@ describe('Host App Generator', () => {
166168
tree.read(`apps/test/dashboard/src/app/app.component.spec.ts`, 'utf-8')
167169
).toMatchSnapshot();
168170
});
171+
172+
it('should not generate an e2e project when e2eTestRunner is none', async () => {
173+
// ARRANGE
174+
const tree = createTreeWithEmptyWorkspace();
175+
176+
// ACT
177+
await host(tree, {
178+
name: 'dashboard',
179+
remotes: ['remote1'],
180+
e2eTestRunner: E2eTestRunner.None,
181+
});
182+
183+
// ASSERT
184+
const projects = getProjects(tree);
185+
expect(projects.has('dashboard-e2e')).toBeFalsy();
186+
expect(projects.has('remote1-e2e')).toBeFalsy();
187+
});
169188
});

packages/angular/src/generators/host/host.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as ts from 'typescript';
1515
import { addRoute } from '../../utils/nx-devkit/ast-utils';
1616
import { addStandaloneRoute } from '../../utils/nx-devkit/standalone-utils';
1717
import { setupMf } from '../setup-mf/setup-mf';
18+
import { E2eTestRunner } from '../../utils/test-runners';
1819

1920
export default async function host(tree: Tree, options: Schema) {
2021
const projects = getProjects(tree);
@@ -41,6 +42,8 @@ export default async function host(tree: Tree, options: Schema) {
4142
skipFormat: true,
4243
});
4344

45+
const skipE2E =
46+
!options.e2eTestRunner || options.e2eTestRunner === E2eTestRunner.None;
4447
await setupMf(tree, {
4548
appName,
4649
mfType: 'host',
@@ -50,7 +53,8 @@ export default async function host(tree: Tree, options: Schema) {
5053
federationType: options.dynamic ? 'dynamic' : 'static',
5154
skipPackageJson: options.skipPackageJson,
5255
skipFormat: true,
53-
e2eProjectName: `${appName}-e2e`,
56+
skipE2E,
57+
e2eProjectName: skipE2E ? undefined : `${appName}-e2e`,
5458
});
5559

5660
for (const remote of remotesToGenerate) {

packages/angular/src/generators/remote/remote.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2+
getProjects,
23
readProjectConfiguration,
34
readWorkspaceConfiguration,
45
} from '@nrwl/devkit';
56
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
67
import host from '../host/host';
78
import remote from './remote';
9+
import { E2eTestRunner } from '@nrwl/angular/src/utils/test-runners';
810

911
describe('MF Remote App Generator', () => {
1012
it('should generate a remote mf app with no host', async () => {
@@ -132,4 +134,19 @@ describe('MF Remote App Generator', () => {
132134
tree.read(`apps/test/src/app/remote-entry/routes.ts`, 'utf-8')
133135
).toMatchSnapshot();
134136
});
137+
138+
it('should not generate an e2e project when e2eTestRunner is none', async () => {
139+
// ARRANGE
140+
const tree = createTreeWithEmptyWorkspace();
141+
142+
// ACT
143+
await remote(tree, {
144+
name: 'remote1',
145+
e2eTestRunner: E2eTestRunner.None,
146+
});
147+
148+
// ASSERT
149+
const projects = getProjects(tree);
150+
expect(projects.has('remote1-e2e')).toBeFalsy();
151+
});
135152
});

packages/angular/src/generators/remote/remote.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import applicationGenerator from '../application/application';
1010
import { getMFProjects } from '../../utils/get-mf-projects';
1111
import { normalizeProjectName } from '../utils/project';
1212
import { setupMf } from '../setup-mf/setup-mf';
13+
import { E2eTestRunner } from '../../utils/test-runners';
1314

1415
function findNextAvailablePort(tree: Tree) {
1516
const mfProjects = getMFProjects(tree);
@@ -44,6 +45,9 @@ export default async function remote(tree: Tree, options: Schema) {
4445
port,
4546
});
4647

48+
const skipE2E =
49+
!options.e2eTestRunner || options.e2eTestRunner === E2eTestRunner.None;
50+
4751
await setupMf(tree, {
4852
appName,
4953
mfType: 'remote',
@@ -52,7 +56,8 @@ export default async function remote(tree: Tree, options: Schema) {
5256
port,
5357
skipPackageJson: options.skipPackageJson,
5458
skipFormat: true,
55-
e2eProjectName: `${appName}-e2e`,
59+
skipE2E,
60+
e2eProjectName: skipE2E ? undefined : `${appName}-e2e`,
5661
standalone: options.standalone,
5762
});
5863

packages/angular/src/generators/setup-mf/lib/add-cypress-workaround.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
joinPathFragments,
88
logger,
99
readProjectConfiguration,
10+
stripIndents,
1011
} from '@nrwl/devkit';
1112
import type { Schema } from '../schema';
1213

@@ -21,7 +22,7 @@ export function addCypressOnErrorWorkaround(tree: Tree, schema: Schema) {
2122
try {
2223
e2eProject = readProjectConfiguration(tree, e2eProjectName);
2324
} catch {
24-
logger.warn(`Could not find an associated e2e project for ${schema.appName} with name ${e2eProjectName}.
25+
logger.warn(stripIndents`Could not find an associated e2e project for ${schema.appName} with name ${e2eProjectName}.
2526
If there is an associated e2e project for this application, and it uses Cypress, you will need to add a workaround to allow Cypress to test correctly.
2627
An error will be thrown in the console when you serve the application, coming from styles.js. It is an error that can be safely ignored and will not reach production due to how production builds of Angular are created.
2728
You can find how to implement that workaround here: https://docs.cypress.io/api/events/catalog-of-events#Uncaught-Exceptions

packages/angular/src/generators/setup-mf/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export interface Schema {
1111
e2eProjectName?: string;
1212
prefix?: string;
1313
standalone?: boolean;
14+
skipE2E?: boolean;
1415
}

packages/angular/src/generators/setup-mf/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"default": false,
5454
"description": "Do not add dependencies to `package.json`."
5555
},
56+
"skipE2E": {
57+
"type": "boolean",
58+
"default": false,
59+
"description": "Do not set up E2E related config."
60+
},
5661
"e2eProjectName": {
5762
"type": "string",
5863
"description": "The project name of the associated E2E project for the application. This is only required for Cypress E2E projects that do not follow the naming convention `<appName>-e2e`."

packages/angular/src/generators/setup-mf/setup-mf.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export async function setupMf(tree: Tree, options: Schema) {
3535

3636
fixBootstrap(tree, projectConfig.root, options);
3737

38-
addCypressOnErrorWorkaround(tree, options);
38+
if (!options.skipE2E) {
39+
addCypressOnErrorWorkaround(tree, options);
40+
}
3941

4042
// format files
4143
if (!options.skipFormat) {

0 commit comments

Comments
 (0)