Skip to content

Commit 5908947

Browse files
author
Ben Callaghan
committed
fix(core): pass client through to init schematic
Use the same client in the generator and schematic for test consistency
1 parent 96082a1 commit 5908947

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
import { readJson, Tree } from '@nrwl/devkit';
22
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
3+
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet';
34

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

67
import generator from './generator';
78

89
describe('init generator', () => {
910
let appTree: Tree;
11+
let dotnetClient: DotNetClient;
1012

1113
beforeEach(() => {
1214
appTree = createTreeWithEmptyWorkspace();
15+
dotnetClient = new DotNetClient(mockDotnetFactory());
1316
});
1417

1518
it('should create config', async () => {
16-
await generator(appTree);
19+
await generator(appTree, dotnetClient);
1720
const config = appTree.isFile(CONFIG_FILE_PATH);
1821
expect(config).toBeTruthy();
1922
});
2023

2124
it('should update gitignore', async () => {
2225
appTree.write('.gitignore', '');
23-
await generator(appTree);
26+
await generator(appTree, dotnetClient);
2427
const gitignoreValue = appTree.read('.gitignore')?.toString();
2528
expect(gitignoreValue).toBeTruthy();
2629
});
2730

2831
it('should put dependency array inside config', async () => {
29-
await generator(appTree);
32+
await generator(appTree, dotnetClient);
3033
const config: NxDotnetConfig = readJson(appTree, CONFIG_FILE_PATH);
3134
expect(config.nugetPackages).toBeDefined();
3235
});
36+
37+
it('should create tool manifest', async () => {
38+
const spy = spyOn(dotnetClient, 'new');
39+
await generator(appTree, dotnetClient);
40+
expect(spy).toHaveBeenCalledWith('tool-manifest');
41+
});
42+
43+
it('should not create tool manifest if it exists', async () => {
44+
appTree.write('.config/dotnet-tools.json', '');
45+
const spy = spyOn(dotnetClient, 'new');
46+
await generator(appTree, dotnetClient);
47+
expect(spy).not.toHaveBeenCalled();
48+
});
3349
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('nx-dotnet project generator', () => {
3333
});
3434

3535
afterEach(async () => {
36-
await Promise.all([rimraf('apps'), rimraf('libs')]);
36+
await Promise.all([rimraf('apps'), rimraf('libs'), rimraf('.config')]);
3737
});
3838

3939
it('should run successfully for libraries', async () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export async function GenerateProject(
176176
dotnetClient: DotNetClient,
177177
projectType: ProjectType,
178178
) {
179-
await initSchematic(host);
179+
await initSchematic(host, dotnetClient);
180180

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

0 commit comments

Comments
 (0)