Skip to content

Commit

Permalink
fix(testing): adding e2e projects should register e2e-ci targetDefaul…
Browse files Browse the repository at this point in the history
…ts (nrwl#27185)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->



## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
Coly010 authored and ZackDeRose committed Aug 8, 2024
1 parent 7aa69d8 commit fcddc09
Show file tree
Hide file tree
Showing 44 changed files with 2,425 additions and 82 deletions.
10 changes: 9 additions & 1 deletion packages/angular/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ describe('app', () => {
it('should add eslint plugin and no lint target to e2e project', async () => {
await generateApp(appTree, 'my-app', { linter: Linter.EsLint });

expect(readNxJson(appTree).plugins).toMatchInlineSnapshot(`
const nxJson = readNxJson(appTree);
expect(nxJson.plugins).toMatchInlineSnapshot(`
[
{
"options": {
Expand All @@ -588,6 +589,13 @@ describe('app', () => {
},
]
`);
expect(nxJson.targetDefaults['e2e-ci--**/*']).toMatchInlineSnapshot(`
{
"dependsOn": [
"^build",
],
}
`);
expect(
readProjectConfiguration(appTree, 'my-app-e2e').targets.lint
).toBeUndefined();
Expand Down
17 changes: 17 additions & 0 deletions packages/angular/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { nxVersion } from '../../../utils/versions';
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
import type { NormalizedSchema } from './normalized-schema';
import { addE2eCiTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';

export async function addE2e(tree: Tree, options: NormalizedSchema) {
// since e2e are separate projects, default to adding plugins
Expand Down Expand Up @@ -45,6 +46,14 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) {
rootProject: options.rootProject,
addPlugin,
});
if (addPlugin) {
await addE2eCiTargetDefaults(
tree,
'@nx/cypress/plugin',
'^build',
joinPathFragments(options.e2eProjectRoot, 'cypress.config.ts')
);
}
} else if (options.e2eTestRunner === 'playwright') {
const { configurationGenerator } = ensurePackage<
typeof import('@nx/playwright')
Expand All @@ -71,6 +80,14 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) {
rootProject: options.rootProject,
addPlugin,
});
if (addPlugin) {
await addE2eCiTargetDefaults(
tree,
'@nx/playwright/plugin',
'^build',
joinPathFragments(options.e2eProjectRoot, 'playwright.config.ts')
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addProjectConfiguration, joinPathFragments, Tree } from '@nx/devkit';
import type { AngularProjectConfiguration } from '../../../utils/types';
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
import type { NormalizedSchema } from './normalized-schema';
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/add-build-target-defaults';
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';

export function createProject(tree: Tree, options: NormalizedSchema) {
const { major: angularMajorVersion } = getInstalledAngularVersionInfo(tree);
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/library/lib/add-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Tree } from '@nx/devkit';
import { addProjectConfiguration, joinPathFragments } from '@nx/devkit';
import type { AngularProjectConfiguration } from '../../../utils/types';
import type { NormalizedSchema } from './normalized-schema';
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/add-build-target-defaults';
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';

export function addProject(
tree: Tree,
Expand Down
6 changes: 6 additions & 0 deletions packages/cypress/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
"version": "19.6.0-beta.0",
"description": "Update ciWebServerCommand to use previewTargetName if Vite is detected for the application.",
"implementation": "./src/migrations/update-19-6-0/update-ci-webserver-for-vite"
},
"update-19-6-0-add-e2e-ci-target-defaults": {
"cli": "nx",
"version": "19.6.0-beta.0",
"description": "Add inferred ciTargetNames to targetDefaults with dependsOn to ensure dependent application builds are scheduled before atomized tasks.",
"implementation": "./src/migrations/update-19-6-0/add-e2e-ci-target-defaults"
}
},
"packageJsonUpdates": {
Expand Down
Loading

0 comments on commit fcddc09

Please sign in to comment.