1
1
import { JsonObject , logging } from '@angular-devkit/core' ;
2
- import {
3
- BuilderContext ,
4
- BuilderRun ,
5
- ScheduleOptions ,
6
- Target
7
- } from '@angular-devkit/architect/src/index' ;
2
+ import { BuilderContext , BuilderRun , ScheduleOptions , Target } from '@angular-devkit/architect/src/index' ;
8
3
import deploy from './actions' ;
9
4
10
5
let context : BuilderContext ;
6
+ const mockEngine = { run : ( _ : string , __ : any , __2 : any ) => Promise . resolve ( ) }
11
7
12
8
const PROJECT = 'pirojok-project' ;
13
9
@@ -16,17 +12,10 @@ describe('Deploy Angular apps', () => {
16
12
17
13
it ( 'should invoke the builder' , async ( ) => {
18
14
const spy = spyOn ( context , 'scheduleTarget' ) . and . callThrough ( ) ;
19
- await deploy (
20
- {
21
- publish : ( _ : string , __ : any ) => Promise . resolve ( )
22
- } ,
23
- context ,
24
- 'host' ,
25
- { }
26
- ) ;
15
+ await deploy ( mockEngine , context , 'host' , { } ) ;
16
+
27
17
expect ( spy ) . toHaveBeenCalled ( ) ;
28
- expect ( spy ) . toHaveBeenCalledWith (
29
- {
18
+ expect ( spy ) . toHaveBeenCalledWith ( {
30
19
target : 'build' ,
31
20
configuration : 'production' ,
32
21
project : PROJECT
@@ -35,28 +24,19 @@ describe('Deploy Angular apps', () => {
35
24
) ;
36
25
} ) ;
37
26
38
- it ( 'should invoke ghpages.publish' , async ( ) => {
39
- const mock = {
40
- publish : ( _ : string , __ : any ) => Promise . resolve ( )
41
- } ;
42
- const spy = spyOn ( mock , 'publish' ) . and . callThrough ( ) ;
43
- await deploy ( mock , context , 'host' , { } ) ;
27
+ it ( 'should invoke engine.run' , async ( ) => {
28
+ const spy = spyOn ( mockEngine , 'run' ) . and . callThrough ( ) ;
29
+ await deploy ( mockEngine , context , 'host' , { } ) ;
30
+
44
31
expect ( spy ) . toHaveBeenCalled ( ) ;
45
- expect ( spy ) . toHaveBeenCalledWith ( 'host' , { } ) ;
32
+ expect ( spy ) . toHaveBeenCalledWith ( 'host' , { } , context . logger ) ;
46
33
} ) ;
47
34
48
35
describe ( 'error handling' , ( ) => {
49
36
it ( 'throws if there is no target project' , async ( ) => {
50
37
context . target = undefined ;
51
38
try {
52
- await deploy (
53
- {
54
- publish : ( _ : string , __ : any ) => Promise . resolve ( )
55
- } ,
56
- context ,
57
- 'host' ,
58
- { }
59
- ) ;
39
+ await deploy ( mockEngine , context , 'host' , { } ) ;
60
40
fail ( ) ;
61
41
} catch ( e ) {
62
42
expect ( e . message ) . toMatch ( / C a n n o t e x e c u t e t h e b u i l d t a r g e t / ) ;
@@ -81,17 +61,15 @@ const initMocks = () => {
81
61
id : 1 ,
82
62
logger : new logging . NullLogger ( ) as any ,
83
63
workspaceRoot : 'cwd' ,
84
- addTeardown : _ => { } ,
64
+ addTeardown : _ => { } ,
85
65
validateOptions : _ => Promise . resolve ( { } as any ) ,
86
66
getBuilderNameForTarget : ( ) => Promise . resolve ( '' ) ,
87
67
analytics : null as any ,
88
68
getTargetOptions : ( _ : Target ) => Promise . resolve ( { } ) ,
89
- reportProgress : ( _ : number , __ ?: number , ___ ?: string ) => { } ,
90
- reportStatus : ( _ : string ) => { } ,
91
- reportRunning : ( ) => { } ,
92
- scheduleBuilder : ( _ : string , __ ?: JsonObject , ___ ?: ScheduleOptions ) =>
93
- Promise . resolve ( { } as BuilderRun ) ,
94
- scheduleTarget : ( _ : Target , __ ?: JsonObject , ___ ?: ScheduleOptions ) =>
95
- Promise . resolve ( { } as BuilderRun )
69
+ reportProgress : ( _ : number , __ ?: number , ___ ?: string ) => { } ,
70
+ reportStatus : ( _ : string ) => { } ,
71
+ reportRunning : ( ) => { } ,
72
+ scheduleBuilder : ( _ : string , __ ?: JsonObject , ___ ?: ScheduleOptions ) => Promise . resolve ( { } as BuilderRun ) ,
73
+ scheduleTarget : ( _ : Target , __ ?: JsonObject , ___ ?: ScheduleOptions ) => Promise . resolve ( { } as BuilderRun )
96
74
} ;
97
75
} ;
0 commit comments