Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(misc): make sure to add e2e crystal plugin #22041

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: { default: 'nx run app1:serve' },
}),
baseUrl: 'http://localhost:4200',
},
});
Expand Down Expand Up @@ -100,7 +103,10 @@ import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: { default: 'nx run app1:serve' },
}),
baseUrl: 'http://localhost:4200',
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,22 @@ describe('Cypress e2e configuration', () => {
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: { ...nxE2EPreset(__filename, { cypressDir: 'src' }) },
e2e: {
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: {
default: 'nx run my-app:serve',
production: 'nx run my-app:serve:production',
},
ciWebServerCommand: 'nx run my-app:serve-static',
}),
},
});
"
`);
expect(readProjectConfiguration(tree, 'my-app').targets.e2e)
.toMatchInlineSnapshot(`
{
"configurations": {
"ci": {
"devServerTarget": "my-app:serve-static",
},
"production": {
"devServerTarget": "my-app:serve:production",
},
},
"executor": "@nx/cypress:cypress",
"options": {
"cypressConfig": "apps/my-app/cypress.config.ts",
"devServerTarget": "my-app:serve",
"testingType": "e2e",
},
}
`);
expect(
readProjectConfiguration(tree, 'my-app').targets.e2e
).toMatchInlineSnapshot(`undefined`);

expect(readJson(tree, 'apps/my-app/tsconfig.json'))
.toMatchInlineSnapshot(`
Expand Down Expand Up @@ -185,7 +178,16 @@ describe('Cypress e2e configuration', () => {
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: { ...nxE2EPreset(__filename, { cypressDir: 'cypress' }) },
e2e: {
...nxE2EPreset(__filename, {
cypressDir: 'cypress',
webServerCommands: {
default: 'nx run my-app:serve',
production: 'nx run my-app:serve:production',
},
ciWebServerCommand: 'nx run my-app:serve-static',
}),
},
});
"
`);
Expand All @@ -208,7 +210,14 @@ describe('Cypress e2e configuration', () => {

export default defineConfig({
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: {
default: 'nx run my-app:serve',
production: 'nx run my-app:serve:production',
},
ciWebServerCommand: 'nx run my-app:serve-static',
}),
baseUrl: 'http://localhost:4200',
},
});
Expand Down Expand Up @@ -318,15 +327,6 @@ describe('Cypress e2e configuration', () => {
addPlugin: true,
});
assertCypressFiles(tree, 'libs/my-lib/src/e2e', 'js');

expect(readProjectConfiguration(tree, 'my-lib').targets['e2e'].options)
.toMatchInlineSnapshot(`
{
"baseUrl": "http://localhost:4200",
"cypressConfig": "libs/my-lib/cypress.config.js",
"testingType": "e2e",
}
`);
});

it('should not override eslint settings if preset', async () => {
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('Cypress e2e configuration', () => {
project: 'my-lib',
devServerTarget: 'my-app:serve',
directory: 'cypress',
addPlugin: true,
addPlugin: false,
});
assertCypressFiles(tree, 'libs/my-lib/cypress');
expect(
Expand All @@ -412,7 +412,7 @@ describe('Cypress e2e configuration', () => {
await cypressE2EConfigurationGenerator(tree, {
project: 'my-app',
port: 0,
addPlugin: true,
addPlugin: false,
});

expect(readProjectConfiguration(tree, 'my-app').targets['e2e'].options)
Expand Down
10 changes: 5 additions & 5 deletions packages/cypress/src/generators/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { addLinterToCyProject } from '../../utils/add-linter';
import { addDefaultE2EConfig } from '../../utils/config';
import { installedCypressVersion } from '../../utils/cypress-version';
import { typesNodeVersion, viteVersion } from '../../utils/versions';
import cypressInitGenerator from '../init/init';
import cypressInitGenerator, { addPlugin } from '../init/init';
import { addBaseCypressSetup } from '../base-setup/base-setup';

export interface CypressE2EConfigSchema {
Expand Down Expand Up @@ -67,7 +67,7 @@ export async function configurationGeneratorInternal(
options: CypressE2EConfigSchema
) {
const opts = normalizeOptions(tree, options);

opts.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const tasks: GeneratorCallback[] = [];

if (!installedCypressVersion()) {
Expand All @@ -76,10 +76,12 @@ export async function configurationGeneratorInternal(
await cypressInitGenerator(tree, {
...opts,
skipFormat: true,
addPlugin: options.addPlugin,
})
);
} else if (opts.addPlugin) {
addPlugin(tree);
}

const projectGraph = await createProjectGraphAsync();
const nxJson = readNxJson(tree);
const hasPlugin = nxJson.plugins?.some((p) =>
Expand All @@ -96,7 +98,6 @@ export async function configurationGeneratorInternal(
const linterTask = await addLinterToCyProject(tree, {
...opts,
cypressDir: opts.directory,
addPlugin: opts.addPlugin,
});
tasks.push(linterTask);

Expand Down Expand Up @@ -151,7 +152,6 @@ In this case you need to provide a devServerTarget,'<projectName>:<targetName>[:

return {
...options,
addPlugin: options.addPlugin ?? process.env.NX_ADD_PLUGINS !== 'false',
bundler: options.bundler ?? 'webpack',
rootProject: options.rootProject ?? projectConfig.root === '.',
linter: options.linter ?? Linter.EsLint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ async function normalizeOptions(

options.linter = options.linter || Linter.EsLint;
options.bundler = options.bundler || 'webpack';
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';

return {
...options,
// other generators depend on the rootProject flag down stream
Expand Down
3 changes: 1 addition & 2 deletions packages/cypress/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function updateDependencies(tree: Tree, options: Schema) {
return runTasksInSerial(...tasks);
}

function addPlugin(tree: Tree) {
export function addPlugin(tree: Tree) {
const nxJson = readNxJson(tree);
nxJson.plugins ??= [];

Expand Down Expand Up @@ -105,7 +105,6 @@ export async function cypressInitGeneratorInternal(
options: Schema
) {
updateProductionFileset(tree);

options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';

if (options.addPlugin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: { default: 'nx run test:serve:development' },
ciWebServerCommand: 'nx run test:serve-static',
}),
baseUrl: 'http://localhost:4200',
},
});
Expand Down Expand Up @@ -661,7 +665,11 @@ import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: { default: 'nx run test:serve:development' },
ciWebServerCommand: 'nx run test:serve-static',
}),
baseUrl: 'http://localhost:4200',
},
});
Expand Down Expand Up @@ -1027,7 +1035,11 @@ import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: { default: 'nx run test:serve:development' },
ciWebServerCommand: 'nx run test:serve-static',
}),
baseUrl: 'http://localhost:4200',
},
});
Expand Down
2 changes: 2 additions & 0 deletions packages/vue/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export async function applicationGeneratorInternal(
_options: Schema
): Promise<GeneratorCallback> {
const options = await normalizeOptions(tree, _options);
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';

const tasks: GeneratorCallback[] = [];

addProjectConfiguration(tree, options.name, {
Expand Down
1 change: 1 addition & 0 deletions packages/vue/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function addE2e(
implicitDependencies: [options.projectName],
});
return configurationGenerator(tree, {
...options,
project: options.e2eProjectName,
skipFormat: true,
skipPackageJson: options.skipPackageJson,
Expand Down