Skip to content

Commit

Permalink
fix(core): Remove extra separator from project names (#61)
Browse files Browse the repository at this point in the history
* fix(core): remove extra separator from project names

Remove capturing parentheses to keep separator out of the project's name

Fixes #60

* test(core): reset options object before each test

Reset the options object to improve test isolation and repeatability

Co-authored-by: Ben Callaghan <bcallaghan@selectbankcard.com>
  • Loading branch information
bcallaghan-et and Ben Callaghan authored May 27, 2021
1 parent 6d09f31 commit 049367c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions packages/core/src/generators/utils/generate-project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { XmlDocument } from 'xmldoc';
import {
DotNetClient,
dotnetFactory,
dotnetNewOptions,
mockDotnetFactory,
} from '@nx-dotnet/dotnet';
import { findProjectFileInPath, NXDOTNET_TAG, rimraf } from '@nx-dotnet/utils';
Expand All @@ -18,21 +19,22 @@ import { GenerateProject } from './generate-project';
describe('nx-dotnet project generator', () => {
let appTree: Tree;
let dotnetClient: DotNetClient;

const options: NxDotnetProjectGeneratorSchema = {
name: 'test',
language: 'C#',
template: 'classlib',
testTemplate: 'none',
skipOutputPathManipulation: true,
};
let options: NxDotnetProjectGeneratorSchema;

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace();
dotnetClient = new DotNetClient(mockDotnetFactory());

const packageJson = { scripts: {} };
writeJson(appTree, 'package.json', packageJson);

options = {
name: 'test',
language: 'C#',
template: 'classlib',
testTemplate: 'none',
skipOutputPathManipulation: true,
};
});

afterEach(async () => {
Expand Down Expand Up @@ -107,6 +109,15 @@ describe('nx-dotnet project generator', () => {
expect(config.targets.lint).toBeDefined();
});

it('should prepend directory name to project name', async () => {
options.directory = 'sub-dir';
const spy = spyOn(dotnetClient, 'new');
await GenerateProject(appTree, options, dotnetClient, 'library');
const dotnetOptions: dotnetNewOptions = spy.calls.mostRecent().args[1];
const nameFlag = dotnetOptions.find((flag) => flag.flag === 'name');
expect(nameFlag?.value).toBe('Proj.SubDir.Test');
});

/**
* This test requires a live dotnet client.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/generators/utils/generate-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function normalizeOptions(

const npmScope = names(readWorkspaceConfiguration(host).npmScope).className;
const featureScope = projectDirectory
.split(/(\/|\\)/gm)
.split(/\/|\\/gm) // Without the unnecessary parentheses, the separator is excluded from the result array.
.map((part) => names(part).className);
const namespaceName = [npmScope, ...featureScope].join('.');

Expand Down

0 comments on commit 049367c

Please sign in to comment.