Skip to content

Commit

Permalink
fix(vue): application generator should add e2e-ci target defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Aug 2, 2024
1 parent 4ab91cd commit 7f1789a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/vue/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('application generator', () => {
...options,
unitTestRunner: 'vitest',
e2eTestRunner: 'playwright',
addPlugin: true,
});
expect(tree.read('.eslintrc.json', 'utf-8')).toMatchSnapshot();
expect(tree.read('test/vite.config.ts', 'utf-8')).toMatchSnapshot();
Expand All @@ -49,6 +50,14 @@ describe('application generator', () => {
tree.read('test-e2e/playwright.config.ts', 'utf-8')
).toMatchSnapshot();
expect(listFiles(tree)).toMatchSnapshot();
expect(readNxJson(tree).targetDefaults['e2e-ci--**/*'])
.toMatchInlineSnapshot(`
{
"dependsOn": [
"^build",
],
}
`);
});

it('should set up project correctly for cypress', async () => {
Expand Down
77 changes: 75 additions & 2 deletions packages/vue/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { webStaticServeGenerator } from '@nx/web';

import { nxVersion } from '../../../utils/versions';
import { NormalizedSchema } from '../schema';
import { findPluginForConfigFile } from '@nx/devkit/src/utils/find-plugin-for-config-file';
import { addE2eCiTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';

export async function addE2e(
tree: Tree,
Expand Down Expand Up @@ -52,7 +54,7 @@ export async function addE2e(
tags: [],
implicitDependencies: [options.projectName],
});
return await configurationGenerator(tree, {
const e2eTask = await configurationGenerator(tree, {
...options,
project: options.e2eProjectName,
directory: 'src',
Expand All @@ -70,6 +72,43 @@ export async function addE2e(
ciWebServerCommand: `nx run ${options.projectName}:${e2eCiWebServerTarget}`,
ciBaseUrl: 'http://localhost:4300',
});

if (
options.addPlugin ||
readNxJson(tree).plugins?.find((p) =>
typeof p === 'string'
? p === '@nx/cypress/plugin'
: p.plugin === '@nx/cypress/plugin'
)
) {
let buildTarget = '^build';
if (hasPlugin) {
const matchingPlugin = await findPluginForConfigFile(
tree,
`@nx/vite/plugin`,
joinPathFragments(
options.appProjectRoot,
`vite.config.${options.js ? 'js' : 'ts'}`
)
);
if (matchingPlugin && typeof matchingPlugin !== 'string') {
buildTarget = `^${
(matchingPlugin.options as any)?.buildTargetName ?? 'build'
}`;
}
}
await addE2eCiTargetDefaults(
tree,
'@nx/cypress/plugin',
buildTarget,
joinPathFragments(
options.e2eProjectRoot,
`cypress.config.${options.js ? 'js' : 'ts'}`
)
);
}

return e2eTask;
}
case 'playwright': {
const { configurationGenerator } = ensurePackage<
Expand All @@ -82,7 +121,7 @@ export async function addE2e(
targets: {},
implicitDependencies: [options.projectName],
});
return configurationGenerator(tree, {
const e2eTask = await configurationGenerator(tree, {
...options,
project: options.e2eProjectName,
skipFormat: true,
Expand All @@ -96,6 +135,40 @@ export async function addE2e(
}:${e2eCiWebServerTarget}`,
webServerAddress: 'http://localhost:4300',
});

if (
options.addPlugin ||
readNxJson(tree).plugins?.find((p) =>
typeof p === 'string'
? p === '@nx/playwright/plugin'
: p.plugin === '@nx/playwright/plugin'
)
) {
let buildTarget = '^build';
if (hasPlugin) {
const matchingPlugin = await findPluginForConfigFile(
tree,
`@nx/vite/plugin`,
joinPathFragments(
options.appProjectRoot,
`vite.config.${options.js ? 'js' : 'ts'}`
)
);
if (matchingPlugin && typeof matchingPlugin !== 'string') {
buildTarget = `^${
(matchingPlugin.options as any)?.buildTargetName ?? 'build'
}`;
}
}
await addE2eCiTargetDefaults(
tree,
'@nx/playwright/plugin',
buildTarget,
joinPathFragments(options.e2eProjectRoot, `playwright.config.ts`)
);
}

return e2eTask;
}
case 'none':
default:
Expand Down

0 comments on commit 7f1789a

Please sign in to comment.