Skip to content

Commit 9f8f03c

Browse files
authored
feat(core): added support for test project name suffix (#78)
Closes #77
1 parent fce17d1 commit 9f8f03c

File tree

7 files changed

+55
-6
lines changed

7 files changed

+55
-6
lines changed

e2e/core-e2e/tests/nx-dotnet.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ describe('nx-dotnet e2e', () => {
147147

148148
expect(projectReference).toBeDefined();
149149
});
150+
151+
it('should create test project using suffix', async () => {
152+
const app = uniq('app');
153+
await runNxCommandAsync(
154+
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi" --test-template="none"`,
155+
);
156+
await runNxCommandAsync(
157+
`generate @nx-dotnet/core:test ${app} --language="C#" --template="nunit" --suffix="integration-tests"`,
158+
);
159+
160+
const config = readFile(
161+
joinPathFragments(
162+
'apps',
163+
`${app}-integration-tests`,
164+
`Proj.${names(app).className}.IntegrationTests.csproj`,
165+
),
166+
);
167+
168+
expect(config).toBeDefined();
169+
});
150170
});
151171

152172
describe('nx g lib', () => {

packages/core/src/generators/test/generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default function (
2222

2323
const projectGeneratorOptions: NxDotnetProjectGeneratorSchema = {
2424
...options,
25+
testProjectNameSuffix: options.suffix,
2526
name,
2627
language: options.language,
2728
skipOutputPathManipulation: options.skipOutputPathManipulation,

packages/core/src/generators/test/schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
"items": ["C#", "F#", "VB"]
4141
}
4242
},
43+
"suffix": {
44+
"type": "string",
45+
"description": "What suffix should be used for the tests project name?",
46+
"default": "test",
47+
"x-prompt": {
48+
"message": "What suffix should be used for the tests project name?",
49+
"type": "string"
50+
}
51+
},
4352
"skipOutputPathManipulation": {
4453
"type": "boolean",
4554
"description": "Skip XML changes for default build path",

packages/core/src/generators/utils/generate-test-project.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
addProjectConfiguration,
3-
readJson,
43
readProjectConfiguration,
54
Tree,
65
writeJson,
@@ -101,11 +100,28 @@ describe('nx-dotnet test project generator', () => {
101100
expect(config.root).toBe('apps/domain/existing-app-test');
102101
});
103102

103+
xit('should determine directory from existing project and suffix', async () => {
104+
options.testProjectNameSuffix = 'integration-tests';
105+
testProjectName = options.name + '-' + options.testProjectNameSuffix;
106+
await GenerateTestProject(appTree, options, dotnetClient);
107+
const config = readProjectConfiguration(appTree, testProjectName);
108+
expect(config.root).toBe('apps/domain/existing-app-integration-tests');
109+
});
110+
104111
xit('should prepend directory name to project name', async () => {
105112
const spy = jest.spyOn(dotnetClient, 'new');
106113
await GenerateTestProject(appTree, options, dotnetClient);
107114
const [, dotnetOptions] = spy.mock.calls[spy.mock.calls.length - 1];
108115
const nameFlag = dotnetOptions?.find((flag) => flag.flag === 'name');
109116
expect(nameFlag?.value).toBe('Proj.Domain.ExistingApp.Test');
110117
});
118+
119+
xit('should prepend directory name with suffix to project name', async () => {
120+
options.testProjectNameSuffix = 'integration-tests';
121+
const spy = jest.spyOn(dotnetClient, 'new');
122+
await GenerateTestProject(appTree, options, dotnetClient);
123+
const [, dotnetOptions] = spy.mock.calls[spy.mock.calls.length - 1];
124+
const nameFlag = dotnetOptions?.find((flag) => flag.flag === 'name');
125+
expect(nameFlag?.value).toBe('Proj.Domain.ExistingApp.IntegrationTests');
126+
});
111127
});

packages/core/src/generators/utils/generate-test-project.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addProjectConfiguration, Tree } from '@nrwl/devkit';
1+
import { addProjectConfiguration, names, Tree } from '@nrwl/devkit';
22

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

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

3132
addProjectConfiguration(
3233
host,
@@ -52,11 +53,11 @@ export async function GenerateTestProject(
5253
},
5354
{
5455
flag: 'name',
55-
value: schema.namespaceName + '.Test',
56+
value: schema.namespaceName + '.' + names(suffix).className,
5657
},
5758
{
5859
flag: 'output',
59-
value: schema.projectRoot + '-test',
60+
value: schema.projectRoot + '-' + suffix,
6061
},
6162
];
6263

packages/core/src/models/project-generator-schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface NxDotnetProjectGeneratorSchema {
1010
template: string;
1111
language: string;
1212
testTemplate: 'nunit' | 'mstest' | 'xunit' | 'none';
13+
testProjectNameSuffix?: string;
1314
skipOutputPathManipulation: boolean;
1415
standalone: boolean;
1516
projectType?: ProjectType;

packages/core/src/models/test-generator-schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export interface NxDotnetTestGeneratorSchema {
22
name: string;
33
testTemplate: 'xunit' | 'nunit' | 'mstest';
44
language: string;
5+
suffix?: string;
56
skipOutputPathManipulation: boolean;
67
standalone: boolean;
78
}

0 commit comments

Comments
 (0)