@@ -6,6 +6,19 @@ const PROJECT_NAME = 'THEPROJECT';
66const PROJECT_ROOT = 'PROJECTROOT' ;
77const OTHER_PROJECT_NAME = 'OTHERPROJECT' ;
88
9+ // Mock context with logger - only the methods we actually use
10+ const mockLogger = {
11+ info : jest . fn ( ) ,
12+ warn : jest . fn ( ) ,
13+ error : jest . fn ( ) ,
14+ debug : jest . fn ( ) ,
15+ fatal : jest . fn ( ) ,
16+ log : jest . fn ( ) ,
17+ createChild : jest . fn ( )
18+ } ;
19+
20+ const mockContext = { logger : mockLogger } as unknown as SchematicContext ;
21+
922describe ( 'ng-add' , ( ) => {
1023 describe ( 'generating files' , ( ) => {
1124 let tree : Tree ;
@@ -18,7 +31,7 @@ describe('ng-add', () => {
1831 it ( 'generates new files if starting from scratch' , async ( ) => {
1932 const result = await ngAdd ( {
2033 project : PROJECT_NAME
21- } ) ( tree , { } as SchematicContext ) ;
34+ } ) ( tree , mockContext ) ;
2235
2336 const actual = result . read ( 'angular.json' ) ! . toString ( ) ;
2437 expect ( prettifyJSON ( actual ) ) . toMatchSnapshot ( ) ;
@@ -27,11 +40,11 @@ describe('ng-add', () => {
2740 it ( 'overrides existing files' , async ( ) => {
2841 const tempTree = await ngAdd ( {
2942 project : PROJECT_NAME
30- } ) ( tree , { } as SchematicContext ) ;
43+ } ) ( tree , mockContext ) ;
3144
3245 const result = await ngAdd ( {
3346 project : OTHER_PROJECT_NAME
34- } ) ( tempTree , { } as SchematicContext ) ;
47+ } ) ( tempTree , mockContext ) ;
3548
3649 const actual = result . read ( 'angular.json' ) ! . toString ( ) ;
3750
@@ -49,7 +62,7 @@ describe('ng-add', () => {
4962
5063 const resultTree = await ngAdd ( { project : '' } ) (
5164 tree ,
52- { } as SchematicContext
65+ mockContext
5366 ) ;
5467
5568 const resultConfig = readJSONFromTree ( resultTree , 'angular.json' ) ;
@@ -65,15 +78,15 @@ describe('ng-add', () => {
6578 tree . create ( 'angular.json' , JSON . stringify ( angularJSON ) ) ;
6679
6780 await expect (
68- ngAdd ( { project : '' } ) ( tree , { } as SchematicContext )
81+ ngAdd ( { project : '' } ) ( tree , mockContext )
6982 ) . rejects . toThrowError (
7083 'There is more than one project in your workspace. Please select it manually by using the --project argument.'
7184 ) ;
7285 } ) ;
7386
7487 it ( 'should throw if angular.json not found' , async ( ) => {
7588 await expect (
76- ngAdd ( { project : PROJECT_NAME } ) ( Tree . empty ( ) , { } as SchematicContext )
89+ ngAdd ( { project : PROJECT_NAME } ) ( Tree . empty ( ) , mockContext )
7790 ) . rejects . toThrowError ( 'Unable to determine format for workspace path.' ) ;
7891 } ) ;
7992
@@ -82,7 +95,7 @@ describe('ng-add', () => {
8295 tree . create ( 'angular.json' , 'hi' ) ;
8396
8497 await expect (
85- ngAdd ( { project : PROJECT_NAME } ) ( tree , { } as SchematicContext )
98+ ngAdd ( { project : PROJECT_NAME } ) ( tree , mockContext )
8699 ) . rejects . toThrowError ( 'Invalid workspace file - expected JSON object.' ) ;
87100 } ) ;
88101
@@ -91,7 +104,7 @@ describe('ng-add', () => {
91104 tree . create ( 'angular.json' , JSON . stringify ( { version : 1 , projects : { } } ) ) ;
92105
93106 await expect (
94- ngAdd ( { project : PROJECT_NAME } ) ( tree , { } as SchematicContext )
107+ ngAdd ( { project : PROJECT_NAME } ) ( tree , mockContext )
95108 ) . rejects . toThrowError (
96109 'The specified Angular project is not defined in this workspace'
97110 ) ;
@@ -110,7 +123,7 @@ describe('ng-add', () => {
110123 ) ;
111124
112125 await expect (
113- ngAdd ( { project : PROJECT_NAME } ) ( tree , { } as SchematicContext )
126+ ngAdd ( { project : PROJECT_NAME } ) ( tree , mockContext )
114127 ) . rejects . toThrowError (
115128 'Deploy requires an Angular project type of "application" in angular.json'
116129 ) ;
@@ -135,7 +148,7 @@ describe('ng-add', () => {
135148 await expect (
136149 ngAdd ( {
137150 project : PROJECT_NAME
138- } ) ( tree , { } as SchematicContext )
151+ } ) ( tree , mockContext )
139152 ) . rejects . toThrowError (
140153 / C a n n o t f i n d b u i l d t a r g e t f o r t h e A n g u l a r p r o j e c t /
141154 ) ;
@@ -168,7 +181,7 @@ describe('ng-add', () => {
168181
169182 const result = await ngAdd ( { project : PROJECT_NAME } ) (
170183 tree ,
171- { } as SchematicContext
184+ mockContext
172185 ) ;
173186
174187 const resultConfig = readJSONFromTree ( result , 'angular.json' ) ;
@@ -200,7 +213,7 @@ describe('ng-add', () => {
200213
201214 const result = await ngAdd ( { project : PROJECT_NAME } ) (
202215 tree ,
203- { } as SchematicContext
216+ mockContext
204217 ) ;
205218
206219 const resultConfig = readJSONFromTree ( result , 'angular.json' ) ;
@@ -232,7 +245,7 @@ describe('ng-add', () => {
232245
233246 const result = await ngAdd ( { project : PROJECT_NAME } ) (
234247 tree ,
235- { } as SchematicContext
248+ mockContext
236249 ) ;
237250
238251 const resultConfig = readJSONFromTree ( result , 'angular.json' ) ;
@@ -263,12 +276,31 @@ describe('ng-add', () => {
263276 ) ;
264277
265278 await expect (
266- ngAdd ( { project : PROJECT_NAME } ) ( tree , { } as SchematicContext )
279+ ngAdd ( { project : PROJECT_NAME } ) ( tree , mockContext )
267280 ) . rejects . toThrowError (
268281 / I n v a l i d o u t p u t P a t h c o n f i g u r a t i o n .* E x p e c t e d u n d e f i n e d .* a s t r i n g .* a n o b j e c t w i t h a " b a s e " p r o p e r t y /
269282 ) ;
270283 } ) ;
271284 } ) ;
285+
286+ describe ( 'console output' , ( ) => {
287+ beforeEach ( ( ) => {
288+ jest . clearAllMocks ( ) ;
289+ } ) ;
290+
291+ it ( 'should display next steps after successful installation' , async ( ) => {
292+ const tree = Tree . empty ( ) ;
293+ tree . create ( 'angular.json' , JSON . stringify ( generateAngularJson ( ) ) ) ;
294+
295+ await ngAdd ( { project : PROJECT_NAME } ) ( tree , mockContext ) ;
296+
297+ expect ( mockLogger . info ) . toHaveBeenCalledWith ( '🚀 angular-cli-ghpages is ready!' ) ;
298+ expect ( mockLogger . info ) . toHaveBeenCalledWith ( 'Next steps:' ) ;
299+ expect ( mockLogger . info ) . toHaveBeenCalledWith ( ' 1. Read the docs: https://github.com/angular-schule/angular-cli-ghpages' ) ;
300+ expect ( mockLogger . info ) . toHaveBeenCalledWith ( ' 2. Deploy via: ng deploy' ) ;
301+ expect ( mockLogger . info ) . toHaveBeenCalledWith ( ' 3. Have a nice day!' ) ;
302+ } ) ;
303+ } ) ;
272304} ) ;
273305
274306function prettifyJSON ( json : string ) {
0 commit comments