Skip to content

Commit

Permalink
feat(nx-plugin): allow skipping the creation of an e2e project (#12129)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashley-hunter committed Sep 23, 2022
1 parent 8c2161c commit e80c2ee
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 18 deletions.
6 changes: 6 additions & 0 deletions docs/generated/packages/nx-plugin.json
Expand Up @@ -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"
Expand Down
Expand Up @@ -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
}
};
}

Expand Up @@ -16,5 +16,5 @@ describe('<%= name %> generator', () => {
await generator(appTree, options);
const config = readProjectConfiguration(appTree, 'test');
expect(config).toBeDefined();
})
});
});
Expand Up @@ -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 {
Expand Down
19 changes: 14 additions & 5 deletions 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>) => Schema = (
overrides = {}
Expand Down Expand Up @@ -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);
});
});
});
22 changes: 13 additions & 9 deletions packages/nx-plugin/src/generators/plugin/plugin.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -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 });
}
Expand Down
1 change: 1 addition & 0 deletions packages/nx-plugin/src/generators/plugin/schema.d.ts
Expand Up @@ -7,6 +7,7 @@ export interface Schema {
skipTsConfig: boolean;
skipFormat: boolean;
skipLintChecks: boolean;
e2eTestRunner?: 'jest' | 'none';
tags?: string;
unitTestRunner: 'jest' | 'none';
linter: Linter;
Expand Down
6 changes: 6 additions & 0 deletions packages/nx-plugin/src/generators/plugin/schema.json
Expand Up @@ -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"
Expand Down

0 comments on commit e80c2ee

Please sign in to comment.