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,
"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 `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean"

View File

@ -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
}
};
}

View File

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

View File

@ -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 {

View File

@ -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>) => 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);
});
});
});

View File

@ -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,6 +115,8 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
await addFiles(host, options);
updateWorkspaceJson(host, options);
if (options.e2eTestRunner !== 'none') {
await e2eProjectGenerator(host, {
pluginName: options.name,
projectDirectory: options.projectDirectory,
@ -123,6 +125,8 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
standaloneConfig: options.standaloneConfig ?? true,
minimal: options.minimal ?? false,
});
}
if (options.linter === Linter.EsLint && !options.skipLintChecks) {
await pluginLintCheckGenerator(host, { projectName: options.name });
}

View File

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

View File

@ -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 `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean"