Skip to content

Commit

Permalink
fix(core): pass client through to init schematic
Browse files Browse the repository at this point in the history
Use the same client in the generator and schematic for test consistency
  • Loading branch information
Ben Callaghan committed May 18, 2021
1 parent 96082a1 commit 5908947
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions packages/core/src/generators/init/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
import { readJson, Tree } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet';

import { CONFIG_FILE_PATH, NxDotnetConfig } from '@nx-dotnet/utils';

import generator from './generator';

describe('init generator', () => {
let appTree: Tree;
let dotnetClient: DotNetClient;

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

it('should create config', async () => {
await generator(appTree);
await generator(appTree, dotnetClient);
const config = appTree.isFile(CONFIG_FILE_PATH);
expect(config).toBeTruthy();
});

it('should update gitignore', async () => {
appTree.write('.gitignore', '');
await generator(appTree);
await generator(appTree, dotnetClient);
const gitignoreValue = appTree.read('.gitignore')?.toString();
expect(gitignoreValue).toBeTruthy();
});

it('should put dependency array inside config', async () => {
await generator(appTree);
await generator(appTree, dotnetClient);
const config: NxDotnetConfig = readJson(appTree, CONFIG_FILE_PATH);
expect(config.nugetPackages).toBeDefined();
});

it('should create tool manifest', async () => {
const spy = spyOn(dotnetClient, 'new');
await generator(appTree, dotnetClient);
expect(spy).toHaveBeenCalledWith('tool-manifest');
});

it('should not create tool manifest if it exists', async () => {
appTree.write('.config/dotnet-tools.json', '');
const spy = spyOn(dotnetClient, 'new');
await generator(appTree, dotnetClient);
expect(spy).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('nx-dotnet project generator', () => {
});

afterEach(async () => {
await Promise.all([rimraf('apps'), rimraf('libs')]);
await Promise.all([rimraf('apps'), rimraf('libs'), rimraf('.config')]);
});

it('should run successfully for libraries', async () => {
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 @@ -176,7 +176,7 @@ export async function GenerateProject(
dotnetClient: DotNetClient,
projectType: ProjectType,
) {
await initSchematic(host);
await initSchematic(host, dotnetClient);

options.testTemplate = options.testTemplate ?? 'none';

Expand Down

0 comments on commit 5908947

Please sign in to comment.