From e80c2ee010d3bc9cca31ad7672976fefb3f9fb5c Mon Sep 17 00:00:00 2001 From: Ashley Hunter Date: Fri, 23 Sep 2022 01:11:38 +0100 Subject: [PATCH] feat(nx-plugin): allow skipping the creation of an e2e project (#12129) --- docs/generated/packages/nx-plugin.json | 6 +++++ .../executor/__fileName__/executor.ts__tmpl__ | 4 ++-- .../__fileName__/generator.spec.ts__tmpl__ | 2 +- .../__fileName__/generator.ts__tmpl__ | 2 +- .../src/generators/plugin/plugin.spec.ts | 19 +++++++++++----- .../nx-plugin/src/generators/plugin/plugin.ts | 22 +++++++++++-------- .../src/generators/plugin/schema.d.ts | 1 + .../src/generators/plugin/schema.json | 6 +++++ 8 files changed, 44 insertions(+), 18 deletions(-) diff --git a/docs/generated/packages/nx-plugin.json b/docs/generated/packages/nx-plugin.json index b832a146034c5..28a2b04ac6cf2 100644 --- a/docs/generated/packages/nx-plugin.json +++ b/docs/generated/packages/nx-plugin.json @@ -80,6 +80,12 @@ "default": false, "description": "Do not eslint configuration for plugin json files." }, + "e2eTestRunner": { + "type": "string", + "enum": ["jest", "none"], + "description": "Test runner to use for end to end (E2E) tests.", + "default": "jest" + }, "standaloneConfig": { "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`.", "type": "boolean" diff --git a/packages/nx-plugin/src/generators/executor/files/executor/__fileName__/executor.ts__tmpl__ b/packages/nx-plugin/src/generators/executor/files/executor/__fileName__/executor.ts__tmpl__ index 7d2bb28d58129..e6799fce8d45f 100644 --- a/packages/nx-plugin/src/generators/executor/files/executor/__fileName__/executor.ts__tmpl__ +++ b/packages/nx-plugin/src/generators/executor/files/executor/__fileName__/executor.ts__tmpl__ @@ -3,9 +3,9 @@ import { <%= className %>ExecutorSchema } from './schema'; export default async function runExecutor( options: <%= className %>ExecutorSchema, ) { - console.log('Executor ran for <%= className %>', options) + console.log('Executor ran for <%= className %>', options); return { success: true - } + }; } diff --git a/packages/nx-plugin/src/generators/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ b/packages/nx-plugin/src/generators/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ index a1756cee998e7..51db7a17458ae 100644 --- a/packages/nx-plugin/src/generators/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ +++ b/packages/nx-plugin/src/generators/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ @@ -16,5 +16,5 @@ describe('<%= name %> generator', () => { await generator(appTree, options); const config = readProjectConfiguration(appTree, 'test'); expect(config).toBeDefined(); - }) + }); }); diff --git a/packages/nx-plugin/src/generators/generator/files/generator/__fileName__/generator.ts__tmpl__ b/packages/nx-plugin/src/generators/generator/files/generator/__fileName__/generator.ts__tmpl__ index 6ec01c3e27d52..afe33d1e0303d 100644 --- a/packages/nx-plugin/src/generators/generator/files/generator/__fileName__/generator.ts__tmpl__ +++ b/packages/nx-plugin/src/generators/generator/files/generator/__fileName__/generator.ts__tmpl__ @@ -14,7 +14,7 @@ interface NormalizedSchema extends <%= className %>GeneratorSchema { projectName: string; projectRoot: string; projectDirectory: string; - parsedTags: string[] + parsedTags: string[]; } function normalizeOptions(tree: Tree, options: <%= className %>GeneratorSchema): NormalizedSchema { diff --git a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts index fe73cc1312695..900dfb0c7f990 100644 --- a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts +++ b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts @@ -1,13 +1,14 @@ -import { pluginGenerator } from './plugin'; import { - Tree, - readProjectConfiguration, - readJson, + getProjects, joinPathFragments, + readJson, + readProjectConfiguration, + Tree, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { Schema } from './schema'; import { Linter } from '@nrwl/linter'; +import { pluginGenerator } from './plugin'; +import { Schema } from './schema'; const getSchema: (overrides?: Partial) => Schema = ( overrides = {} @@ -267,4 +268,12 @@ describe('NxPlugin Plugin Generator', () => { expect(name).toEqual('@my-company/my-plugin'); }); }); + + describe('--e2eTestRunner', () => { + it('should allow the e2e project to be skipped', async () => { + await pluginGenerator(tree, getSchema({ e2eTestRunner: 'none' })); + const projects = getProjects(tree); + expect(projects.has('plugins-my-plugin-e2e')).toBe(false); + }); + }); }); diff --git a/packages/nx-plugin/src/generators/plugin/plugin.ts b/packages/nx-plugin/src/generators/plugin/plugin.ts index 82ca999556f8e..15376234cd111 100644 --- a/packages/nx-plugin/src/generators/plugin/plugin.ts +++ b/packages/nx-plugin/src/generators/plugin/plugin.ts @@ -10,8 +10,8 @@ import { updateProjectConfiguration, } from '@nrwl/devkit'; import { libraryGenerator } from '@nrwl/js'; -import { Linter } from '@nrwl/linter'; import { addSwcDependencies } from '@nrwl/js/src/utils/swc/add-swc-dependencies'; +import { Linter } from '@nrwl/linter'; import { swcNodeVersion } from 'nx/src/utils/versions'; import * as path from 'path'; @@ -115,14 +115,18 @@ export async function pluginGenerator(host: Tree, schema: Schema) { await addFiles(host, options); updateWorkspaceJson(host, options); - await e2eProjectGenerator(host, { - pluginName: options.name, - projectDirectory: options.projectDirectory, - pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`, - npmPackageName: options.npmPackageName, - standaloneConfig: options.standaloneConfig ?? true, - minimal: options.minimal ?? false, - }); + + if (options.e2eTestRunner !== 'none') { + await e2eProjectGenerator(host, { + pluginName: options.name, + projectDirectory: options.projectDirectory, + pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`, + npmPackageName: options.npmPackageName, + standaloneConfig: options.standaloneConfig ?? true, + minimal: options.minimal ?? false, + }); + } + if (options.linter === Linter.EsLint && !options.skipLintChecks) { await pluginLintCheckGenerator(host, { projectName: options.name }); } diff --git a/packages/nx-plugin/src/generators/plugin/schema.d.ts b/packages/nx-plugin/src/generators/plugin/schema.d.ts index ee83483a68066..1e921359349f7 100644 --- a/packages/nx-plugin/src/generators/plugin/schema.d.ts +++ b/packages/nx-plugin/src/generators/plugin/schema.d.ts @@ -7,6 +7,7 @@ export interface Schema { skipTsConfig: boolean; skipFormat: boolean; skipLintChecks: boolean; + e2eTestRunner?: 'jest' | 'none'; tags?: string; unitTestRunner: 'jest' | 'none'; linter: Linter; diff --git a/packages/nx-plugin/src/generators/plugin/schema.json b/packages/nx-plugin/src/generators/plugin/schema.json index afaa8282e2a81..600c785657a19 100644 --- a/packages/nx-plugin/src/generators/plugin/schema.json +++ b/packages/nx-plugin/src/generators/plugin/schema.json @@ -63,6 +63,12 @@ "default": false, "description": "Do not eslint configuration for plugin json files." }, + "e2eTestRunner": { + "type": "string", + "enum": ["jest", "none"], + "description": "Test runner to use for end to end (E2E) tests.", + "default": "jest" + }, "standaloneConfig": { "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`.", "type": "boolean"