Skip to content

Commit

Permalink
feat(core): added support for test project name suffix (#78)
Browse files Browse the repository at this point in the history
Closes #77
  • Loading branch information
photomoose authored Aug 10, 2021
1 parent fce17d1 commit 9f8f03c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 6 deletions.
20 changes: 20 additions & 0 deletions e2e/core-e2e/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ describe('nx-dotnet e2e', () => {

expect(projectReference).toBeDefined();
});

it('should create test project using suffix', async () => {
const app = uniq('app');
await runNxCommandAsync(
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi" --test-template="none"`,
);
await runNxCommandAsync(
`generate @nx-dotnet/core:test ${app} --language="C#" --template="nunit" --suffix="integration-tests"`,
);

const config = readFile(
joinPathFragments(
'apps',
`${app}-integration-tests`,
`Proj.${names(app).className}.IntegrationTests.csproj`,
),
);

expect(config).toBeDefined();
});
});

describe('nx g lib', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/generators/test/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function (

const projectGeneratorOptions: NxDotnetProjectGeneratorSchema = {
...options,
testProjectNameSuffix: options.suffix,
name,
language: options.language,
skipOutputPathManipulation: options.skipOutputPathManipulation,
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/generators/test/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
"items": ["C#", "F#", "VB"]
}
},
"suffix": {
"type": "string",
"description": "What suffix should be used for the tests project name?",
"default": "test",
"x-prompt": {
"message": "What suffix should be used for the tests project name?",
"type": "string"
}
},
"skipOutputPathManipulation": {
"type": "boolean",
"description": "Skip XML changes for default build path",
Expand Down
18 changes: 17 additions & 1 deletion packages/core/src/generators/utils/generate-test-project.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
addProjectConfiguration,
readJson,
readProjectConfiguration,
Tree,
writeJson,
Expand Down Expand Up @@ -101,11 +100,28 @@ describe('nx-dotnet test project generator', () => {
expect(config.root).toBe('apps/domain/existing-app-test');
});

xit('should determine directory from existing project and suffix', async () => {
options.testProjectNameSuffix = 'integration-tests';
testProjectName = options.name + '-' + options.testProjectNameSuffix;
await GenerateTestProject(appTree, options, dotnetClient);
const config = readProjectConfiguration(appTree, testProjectName);
expect(config.root).toBe('apps/domain/existing-app-integration-tests');
});

xit('should prepend directory name to project name', async () => {
const spy = jest.spyOn(dotnetClient, 'new');
await GenerateTestProject(appTree, options, dotnetClient);
const [, dotnetOptions] = spy.mock.calls[spy.mock.calls.length - 1];
const nameFlag = dotnetOptions?.find((flag) => flag.flag === 'name');
expect(nameFlag?.value).toBe('Proj.Domain.ExistingApp.Test');
});

xit('should prepend directory name with suffix to project name', async () => {
options.testProjectNameSuffix = 'integration-tests';
const spy = jest.spyOn(dotnetClient, 'new');
await GenerateTestProject(appTree, options, dotnetClient);
const [, dotnetOptions] = spy.mock.calls[spy.mock.calls.length - 1];
const nameFlag = dotnetOptions?.find((flag) => flag.flag === 'name');
expect(nameFlag?.value).toBe('Proj.Domain.ExistingApp.IntegrationTests');
});
});
11 changes: 6 additions & 5 deletions packages/core/src/generators/utils/generate-test-project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addProjectConfiguration, Tree } from '@nrwl/devkit';
import { addProjectConfiguration, names, Tree } from '@nrwl/devkit';

import { DotNetClient, dotnetNewOptions } from '@nx-dotnet/dotnet';
import { findProjectFileInPath, isDryRun } from '@nx-dotnet/utils';
Expand All @@ -25,8 +25,9 @@ export async function GenerateTestProject(
schema = normalizeOptions(host, schema);
}

const testRoot = schema.projectRoot + '-test';
const testProjectName = schema.projectName + '-test';
const suffix = schema.testProjectNameSuffix || 'test';
const testRoot = schema.projectRoot + '-' + suffix;
const testProjectName = schema.projectName + '-' + suffix;

addProjectConfiguration(
host,
Expand All @@ -52,11 +53,11 @@ export async function GenerateTestProject(
},
{
flag: 'name',
value: schema.namespaceName + '.Test',
value: schema.namespaceName + '.' + names(suffix).className,
},
{
flag: 'output',
value: schema.projectRoot + '-test',
value: schema.projectRoot + '-' + suffix,
},
];

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/models/project-generator-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface NxDotnetProjectGeneratorSchema {
template: string;
language: string;
testTemplate: 'nunit' | 'mstest' | 'xunit' | 'none';
testProjectNameSuffix?: string;
skipOutputPathManipulation: boolean;
standalone: boolean;
projectType?: ProjectType;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/models/test-generator-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface NxDotnetTestGeneratorSchema {
name: string;
testTemplate: 'xunit' | 'nunit' | 'mstest';
language: string;
suffix?: string;
skipOutputPathManipulation: boolean;
standalone: boolean;
}

0 comments on commit 9f8f03c

Please sign in to comment.