Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit e9e47e0

Browse files
author
Craigory Coppola
committed
fix(core): #20 test template arg cannot be passed from command line
1 parent 9273001 commit e9e47e0

12 files changed

Lines changed: 134 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# [0.3.0-dev.1](https://github.com/nx-dotnet/nx-dotnet/compare/v0.2.1-dev.1...v0.3.0-dev.1) (2021-04-28)
2+
3+
4+
### Bug Fixes
5+
6+
* **core:** [#20](https://github.com/nx-dotnet/nx-dotnet/issues/20) test template arg cannot be passed from command line ([f74900a](https://github.com/nx-dotnet/nx-dotnet/commit/f74900a1eac1d323813fda3f571112137b67c8ef))
7+
* **repo:** semantic-release not updating package.json ([de9fcd9](https://github.com/nx-dotnet/nx-dotnet/commit/de9fcd9cf5accfe99f602a04cbfd9a44f72f1deb))
8+
9+
10+
### Features
11+
12+
* **core:** dotnet test support ([adbb532](https://github.com/nx-dotnet/nx-dotnet/commit/adbb5328b7d80e02418d7b5fbf3aed54b3a0ee33))
13+
114
## [0.2.1-dev.1](https://github.com/nx-dotnet/nx-dotnet/compare/v0.2.0...v0.2.1-dev.1) (2021-04-27)
215

316

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,58 @@
1+
import { ExecutorContext } from '@nrwl/devkit';
2+
3+
import { mkdirSync, writeFileSync } from 'fs';
4+
5+
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet';
6+
import { rimraf } from '@nx-dotnet/utils';
7+
18
import executor from './executor';
29
import { TestExecutorSchema } from './schema';
310

411
const options: TestExecutorSchema = {};
12+
const root = process.cwd() + '/tmp';
13+
14+
jest.mock('../../../../dotnet/src/lib/core/dotnet.client');
515

616
describe('Test Executor', () => {
7-
it('can run', async () => {
8-
const output = await executor(options);
17+
let context: ExecutorContext;
18+
let dotnetClient: DotNetClient;
19+
20+
beforeEach(() => {
21+
context = {
22+
root: root,
23+
cwd: root,
24+
projectName: 'my-app',
25+
targetName: 'build',
26+
workspace: {
27+
version: 2,
28+
projects: {
29+
'my-app': {
30+
root: `${root}/apps/my-app`,
31+
sourceRoot: `${root}/apps/my-app`,
32+
targets: {
33+
build: {
34+
executor: '@nx-dotnet/core:build',
35+
},
36+
},
37+
},
38+
},
39+
},
40+
isVerbose: false,
41+
};
42+
dotnetClient = new DotNetClient(mockDotnetFactory());
43+
});
44+
45+
afterEach(async () => {
46+
await rimraf(root);
47+
});
48+
49+
it('runs dotnet test', async () => {
50+
const srcRoot = context.workspace.projects['my-app'].sourceRoot as string;
51+
mkdirSync(srcRoot, { recursive: true });
52+
writeFileSync(srcRoot + '/test.csproj', '');
53+
const output = await executor(options, context, dotnetClient);
954
expect(output.success).toBe(true);
55+
const mock = dotnetClient as jest.Mocked<DotNetClient>;
56+
expect(mock.test).toHaveBeenCalledTimes(1);
1057
});
1158
});

packages/core/src/executors/test/executor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ExecutorContext } from '@nrwl/devkit';
2+
23
import {
34
DotNetClient,
45
dotnetFactory,
@@ -8,6 +9,7 @@ import {
89
getExecutedProjectConfiguration,
910
getProjectFileForNxProject,
1011
} from '@nx-dotnet/utils';
12+
1113
import { TestExecutorSchema } from './schema';
1214

1315
export default async function runExecutor(

packages/core/src/generators/app/generator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('nx-dotnet library generator', () => {
1717
name: 'test',
1818
language: 'C#',
1919
template: 'webapi',
20-
'test-template': 'none',
20+
testTemplate: 'none',
2121
skipOutputPathManipulation: true,
2222
};
2323

packages/core/src/generators/lib/generator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('nx-dotnet library generator', () => {
1717
name: 'test',
1818
language: 'C#',
1919
template: 'classlib',
20-
'test-template': 'none',
20+
testTemplate: 'none',
2121
skipOutputPathManipulation: true,
2222
};
2323

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('nx-dotnet project generator', () => {
2323
name: 'test',
2424
language: 'C#',
2525
template: 'classlib',
26-
'test-template': 'none',
26+
testTemplate: 'none',
2727
skipOutputPathManipulation: true,
2828
};
2929

@@ -46,7 +46,7 @@ describe('nx-dotnet project generator', () => {
4646
await GenerateProject(appTree, options, dotnetClient, 'library');
4747
const config = readProjectConfiguration(appTree, 'test');
4848
expect(config.targets.serve).not.toBeDefined();
49-
})
49+
});
5050

5151
it('should tag generated projects', async () => {
5252
await GenerateProject(appTree, options, dotnetClient, 'library');
@@ -76,7 +76,14 @@ describe('nx-dotnet project generator', () => {
7676
await GenerateProject(appTree, options, dotnetClient, 'application');
7777
const config = readProjectConfiguration(appTree, 'test');
7878
expect(config.targets.serve).toBeDefined();
79-
})
79+
});
80+
81+
it('should generate test project', async () => {
82+
options.testTemplate = 'nunit';
83+
await GenerateProject(appTree, options, dotnetClient, 'application');
84+
const config = readProjectConfiguration(appTree, 'test');
85+
expect(config.targets.serve).toBeDefined();
86+
});
8087

8188
/**
8289
* This test requires a live dotnet client.
@@ -101,7 +108,6 @@ describe('nx-dotnet project generator', () => {
101108
?.childNamed('OutputPath')?.val as string;
102109
expect(outputPath).toBeTruthy();
103110

104-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
105111
const absoluteDistPath = resolve(config.root, outputPath);
106112
const expectedDistPath = resolve('./dist/libs/test');
107113

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ async function GenerateTestProject(
8383
dotnetClient: DotNetClient,
8484
projectType: ProjectType
8585
) {
86-
const testName = schema.name + '-test';
8786
const testRoot = schema.projectRoot + '-test';
8887
const testProjectName = schema.projectName + '-test';
8988

@@ -115,11 +114,11 @@ async function GenerateTestProject(
115114

116115
if (isDryRun()) {
117116
newParams.push({
118-
flag: 'dry-run',
117+
flag: 'dryRun',
119118
});
120119
}
121120

122-
dotnetClient.new(schema['test-template'], newParams);
121+
dotnetClient.new(schema.testTemplate, newParams);
123122

124123
if (!isDryRun() && !schema.skipOutputPathManipulation) {
125124
const testCsProj = await findProjectFileInPath(testRoot);
@@ -177,7 +176,7 @@ export async function GenerateProject(
177176
) {
178177
initSchematic(host);
179178

180-
options['test-template'] = options['test-template'] ?? 'none';
179+
options.testTemplate = options.testTemplate ?? 'none';
181180

182181
const normalizedOptions = normalizeOptions(host, options, projectType);
183182

@@ -218,13 +217,13 @@ export async function GenerateProject(
218217

219218
if (isDryRun()) {
220219
newParams.push({
221-
flag: 'dry-run',
220+
flag: 'dryRun',
222221
});
223222
}
224223

225224
dotnetClient.new(normalizedOptions.template, newParams);
226225

227-
if (options['test-template'] !== 'none') {
226+
if (options['testTemplate'] !== 'none') {
228227
await GenerateTestProject(
229228
normalizedOptions,
230229
host,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export interface NxDotnetProjectGeneratorSchema {
77
directory?: string;
88
template: string;
99
language: string;
10-
'test-template': 'nunit' | 'mstest' | 'xunit' | 'none';
10+
testTemplate: 'nunit' | 'mstest' | 'xunit' | 'none';
1111
skipOutputPathManipulation: boolean;
1212
}

packages/dotnet/src/lib/core/dotnet.client.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '@nx-dotnet/utils';
77

88
import {
9+
buildKeyMap,
910
dotnetBuildOptions,
1011
dotnetNewOptions,
1112
dotnetRunOptions,
@@ -19,20 +20,32 @@ export class DotNetClient {
1920
constructor(private cliCommand: LoadedCLI) {}
2021

2122
new(template: dotnetTemplate, parameters?: dotnetNewOptions): Buffer {
22-
const paramString = parameters ? getParameterString(parameters) : '';
23-
const cmd = `${this.cliCommand.command} new ${template} ${paramString}`;
23+
let cmd = `${this.cliCommand.command} new ${template}`;
24+
if (parameters) {
25+
parameters = swapArrayFieldValueUsingMap(parameters, 'flag', testKeyMap);
26+
const paramString = parameters ? getParameterString(parameters) : '';
27+
cmd = `${cmd} ${paramString}`;
28+
}
2429
return this.logAndExecute(cmd);
2530
}
2631

2732
build(project: string, parameters?: dotnetBuildOptions): Buffer {
28-
const paramString = parameters ? getParameterString(parameters) : '';
29-
const cmd = `${this.cliCommand.command} build ${project} ${paramString}`;
33+
let cmd = `${this.cliCommand.command} build ${project}`;
34+
if (parameters) {
35+
parameters = swapArrayFieldValueUsingMap(parameters, 'flag', buildKeyMap);
36+
const paramString = parameters ? getParameterString(parameters) : '';
37+
cmd = `${cmd} ${paramString}`;
38+
}
3039
return this.logAndExecute(cmd);
3140
}
3241

3342
run(project: string, parameters?: dotnetRunOptions): ChildProcess {
34-
const paramString = parameters ? getParameterString(parameters) : '';
35-
const cmd = `run --project ${project} ${paramString}`;
43+
let cmd = `run --project ${project} `;
44+
if (parameters) {
45+
parameters = swapArrayFieldValueUsingMap(parameters, 'flag', testKeyMap);
46+
const paramString = parameters ? getParameterString(parameters) : '';
47+
cmd = `${cmd} ${paramString}`;
48+
}
3649
console.log(`Executing Command: ${cmd}`);
3750
return spawn(this.cliCommand.command, cmd.split(' '), { stdio: 'inherit' });
3851
}

packages/dotnet/src/lib/models/dotnet-build/dotnet-build-flags.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ export type dotnetBuildFlags =
22
| 'configuration'
33
| 'framework'
44
| 'force'
5-
| 'no-dependencies'
6-
| 'no-incremental'
7-
| 'no-restore'
5+
| 'noDependencies'
6+
| 'noIncremental'
7+
| 'noRestore'
88
| 'nologo'
99
| 'output'
1010
| 'source'
1111
| 'verbosity'
12-
| 'version-suffix'
12+
| 'versionSuffix'
1313
| 'runtime';
14+
15+
export const buildKeyMap: Partial<{ [key in dotnetBuildFlags]: string }> = {
16+
noRestore: 'no-restore',
17+
noIncremental: 'no-incremental',
18+
noDependencies: 'no-dependencies',
19+
versionSuffix: 'version-suffix',
20+
};

0 commit comments

Comments
 (0)