@@ -3,8 +3,10 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
33
44import * as fs from 'fs' ;
55
6+ import { DotNetClient , mockDotnetFactory } from '@nx-dotnet/dotnet' ;
67import * as utils from '@nx-dotnet/utils' ;
78
9+ import * as mockedInitGenerator from '../init/generator' ;
810import generator from './generator' ;
911
1012jest . mock ( '@nx-dotnet/utils' , ( ) => ( {
@@ -34,20 +36,28 @@ const MOCK_TEST_PROJECT = `
3436 </ItemGroup>
3537</Project>` ;
3638
39+ jest . mock ( '../init/generator' , ( ) => ( {
40+ initGenerator : jest . fn ( ( ) => {
41+ return Promise . resolve ( jest . fn ( ( ) => Promise . resolve ( ) ) ) ;
42+ } ) ,
43+ } ) ) ;
44+
3745describe ( 'import-projects generator' , ( ) => {
3846 let appTree : Tree ;
47+ let dotnetClient : DotNetClient ;
3948
4049 beforeEach ( ( ) => {
4150 appTree = createTreeWithEmptyWorkspace ( ) ;
51+ dotnetClient = new DotNetClient ( mockDotnetFactory ( ) ) ;
4252 } ) ;
4353
4454 afterEach ( ( ) => {
45- jest . resetAllMocks ( ) ;
55+ jest . clearAllMocks ( ) ;
4656 } ) ;
4757
4858 it ( 'should run successfully if no new projects are found' , async ( ) => {
4959 jest . spyOn ( utils , 'glob' ) . mockResolvedValue ( [ ] ) ;
50- const promise = generator ( appTree ) ;
60+ const promise = generator ( appTree , dotnetClient ) ;
5161 const oldProjects = getProjects ( appTree ) ;
5262 await expect ( promise ) . resolves . not . toThrow ( ) ;
5363 const newProjects = getProjects ( appTree ) ;
@@ -72,7 +82,7 @@ describe('import-projects generator', () => {
7282 jest . spyOn ( fs , 'readFileSync' ) . mockReturnValue ( MOCK_TEST_PROJECT ) ;
7383 jest . spyOn ( fs , 'writeFileSync' ) . mockImplementation ( ( ) => null ) ;
7484 appTree . write ( 'apps/my-api/my-api.csproj' , MOCK_API_PROJECT ) ;
75- const promise = generator ( appTree ) ;
85+ const promise = generator ( appTree , dotnetClient ) ;
7686 await expect ( promise ) . resolves . not . toThrow ( ) ;
7787 expect ( readProjectConfiguration ( appTree , 'my-test-api' ) ) . toBeDefined ( ) ;
7888 } ) ;
@@ -95,7 +105,7 @@ describe('import-projects generator', () => {
95105 jest . spyOn ( fs , 'readFileSync' ) . mockReturnValue ( MOCK_TEST_PROJECT ) ;
96106 jest . spyOn ( fs , 'writeFileSync' ) . mockImplementation ( ( ) => null ) ;
97107 appTree . write ( 'apps/my-api-test/my-api-test.csproj' , MOCK_TEST_PROJECT ) ;
98- const promise = generator ( appTree ) ;
108+ const promise = generator ( appTree , dotnetClient ) ;
99109 await expect ( promise ) . resolves . not . toThrow ( ) ;
100110 expect ( readProjectConfiguration ( appTree , 'my-test-api-test' ) ) . toBeDefined ( ) ;
101111 expect (
@@ -105,4 +115,14 @@ describe('import-projects generator', () => {
105115 readProjectConfiguration ( appTree , 'my-test-api-test' ) . targets ?. serve ,
106116 ) . not . toBeDefined ( ) ;
107117 } ) ;
118+
119+ it ( 'should call init generator' , async ( ) => {
120+ const initGenerator = (
121+ mockedInitGenerator as jest . Mocked < typeof mockedInitGenerator >
122+ ) . initGenerator ;
123+
124+ jest . spyOn ( utils , 'glob' ) . mockResolvedValue ( [ ] ) ;
125+ await generator ( appTree , dotnetClient ) ;
126+ expect ( initGenerator ) . toHaveBeenCalledWith ( appTree , null , dotnetClient ) ;
127+ } ) ;
108128} ) ;
0 commit comments