feat(nx-plugin): allow skipping the creation of an e2e project (#12129)

This commit is contained in:
Ashley Hunter 2022-09-23 01:11:38 +01:00 committed by GitHub
parent 8c2161cd96
commit e80c2ee010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 18 deletions

View File

@ -80,6 +80,12 @@
"default": false, "default": false,
"description": "Do not eslint configuration for plugin json files." "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": { "standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.", "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean" "type": "boolean"

View File

@ -3,9 +3,9 @@ import { <%= className %>ExecutorSchema } from './schema';
export default async function runExecutor( export default async function runExecutor(
options: <%= className %>ExecutorSchema, options: <%= className %>ExecutorSchema,
) { ) {
console.log('Executor ran for <%= className %>', options) console.log('Executor ran for <%= className %>', options);
return { return {
success: true success: true
} };
} }

View File

@ -16,5 +16,5 @@ describe('<%= name %> generator', () => {
await generator(appTree, options); await generator(appTree, options);
const config = readProjectConfiguration(appTree, 'test'); const config = readProjectConfiguration(appTree, 'test');
expect(config).toBeDefined(); expect(config).toBeDefined();
}) });
}); });

View File

@ -14,7 +14,7 @@ interface NormalizedSchema extends <%= className %>GeneratorSchema {
projectName: string; projectName: string;
projectRoot: string; projectRoot: string;
projectDirectory: string; projectDirectory: string;
parsedTags: string[] parsedTags: string[];
} }
function normalizeOptions(tree: Tree, options: <%= className %>GeneratorSchema): NormalizedSchema { function normalizeOptions(tree: Tree, options: <%= className %>GeneratorSchema): NormalizedSchema {

View File

@ -1,13 +1,14 @@
import { pluginGenerator } from './plugin';
import { import {
Tree, getProjects,
readProjectConfiguration,
readJson,
joinPathFragments, joinPathFragments,
readJson,
readProjectConfiguration,
Tree,
} from '@nrwl/devkit'; } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Schema } from './schema';
import { Linter } from '@nrwl/linter'; import { Linter } from '@nrwl/linter';
import { pluginGenerator } from './plugin';
import { Schema } from './schema';
const getSchema: (overrides?: Partial<Schema>) => Schema = ( const getSchema: (overrides?: Partial<Schema>) => Schema = (
overrides = {} overrides = {}
@ -267,4 +268,12 @@ describe('NxPlugin Plugin Generator', () => {
expect(name).toEqual('@my-company/my-plugin'); 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);
});
});
}); });

View File

@ -10,8 +10,8 @@ import {
updateProjectConfiguration, updateProjectConfiguration,
} from '@nrwl/devkit'; } from '@nrwl/devkit';
import { libraryGenerator } from '@nrwl/js'; import { libraryGenerator } from '@nrwl/js';
import { Linter } from '@nrwl/linter';
import { addSwcDependencies } from '@nrwl/js/src/utils/swc/add-swc-dependencies'; import { addSwcDependencies } from '@nrwl/js/src/utils/swc/add-swc-dependencies';
import { Linter } from '@nrwl/linter';
import { swcNodeVersion } from 'nx/src/utils/versions'; import { swcNodeVersion } from 'nx/src/utils/versions';
import * as path from 'path'; import * as path from 'path';
@ -115,14 +115,18 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
await addFiles(host, options); await addFiles(host, options);
updateWorkspaceJson(host, options); updateWorkspaceJson(host, options);
await e2eProjectGenerator(host, {
pluginName: options.name, if (options.e2eTestRunner !== 'none') {
projectDirectory: options.projectDirectory, await e2eProjectGenerator(host, {
pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`, pluginName: options.name,
npmPackageName: options.npmPackageName, projectDirectory: options.projectDirectory,
standaloneConfig: options.standaloneConfig ?? true, pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`,
minimal: options.minimal ?? false, npmPackageName: options.npmPackageName,
}); standaloneConfig: options.standaloneConfig ?? true,
minimal: options.minimal ?? false,
});
}
if (options.linter === Linter.EsLint && !options.skipLintChecks) { if (options.linter === Linter.EsLint && !options.skipLintChecks) {
await pluginLintCheckGenerator(host, { projectName: options.name }); await pluginLintCheckGenerator(host, { projectName: options.name });
} }

View File

@ -7,6 +7,7 @@ export interface Schema {
skipTsConfig: boolean; skipTsConfig: boolean;
skipFormat: boolean; skipFormat: boolean;
skipLintChecks: boolean; skipLintChecks: boolean;
e2eTestRunner?: 'jest' | 'none';
tags?: string; tags?: string;
unitTestRunner: 'jest' | 'none'; unitTestRunner: 'jest' | 'none';
linter: Linter; linter: Linter;

View File

@ -63,6 +63,12 @@
"default": false, "default": false,
"description": "Do not eslint configuration for plugin json files." "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": { "standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.", "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean" "type": "boolean"