|
1 | 1 | import { readJson, Tree } from '@nrwl/devkit'; |
2 | 2 | import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; |
| 3 | +import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet'; |
3 | 4 |
|
4 | 5 | import { CONFIG_FILE_PATH, NxDotnetConfig } from '@nx-dotnet/utils'; |
5 | 6 |
|
6 | 7 | import generator from './generator'; |
7 | 8 |
|
8 | 9 | describe('init generator', () => { |
9 | 10 | let appTree: Tree; |
| 11 | + let dotnetClient: DotNetClient; |
10 | 12 |
|
11 | 13 | beforeEach(() => { |
12 | 14 | appTree = createTreeWithEmptyWorkspace(); |
| 15 | + dotnetClient = new DotNetClient(mockDotnetFactory()); |
13 | 16 | }); |
14 | 17 |
|
15 | 18 | it('should create config', async () => { |
16 | | - await generator(appTree); |
| 19 | + await generator(appTree, dotnetClient); |
17 | 20 | const config = appTree.isFile(CONFIG_FILE_PATH); |
18 | 21 | expect(config).toBeTruthy(); |
19 | 22 | }); |
20 | 23 |
|
21 | 24 | it('should update gitignore', async () => { |
22 | 25 | appTree.write('.gitignore', ''); |
23 | | - await generator(appTree); |
| 26 | + await generator(appTree, dotnetClient); |
24 | 27 | const gitignoreValue = appTree.read('.gitignore')?.toString(); |
25 | 28 | expect(gitignoreValue).toBeTruthy(); |
26 | 29 | }); |
27 | 30 |
|
28 | 31 | it('should put dependency array inside config', async () => { |
29 | | - await generator(appTree); |
| 32 | + await generator(appTree, dotnetClient); |
30 | 33 | const config: NxDotnetConfig = readJson(appTree, CONFIG_FILE_PATH); |
31 | 34 | expect(config.nugetPackages).toBeDefined(); |
32 | 35 | }); |
| 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 | + }); |
33 | 49 | }); |
0 commit comments