1
- import { experimental , JsonObject , logging } from '@angular-devkit/core' ;
1
+ import { JsonObject , logging } from '@angular-devkit/core' ;
2
2
import { BuilderContext , BuilderRun , ScheduleOptions , Target } from '@angular-devkit/architect' ;
3
3
import { BuildTarget , FirebaseDeployConfig , FirebaseTools , FSHost } from '../interfaces' ;
4
4
import deploy , { deployToFunction } from './actions' ;
@@ -10,9 +10,12 @@ let fsHost: FSHost;
10
10
11
11
const FIREBASE_PROJECT = 'ikachu-aa3ef' ;
12
12
const PROJECT = 'pirojok-project' ;
13
- const BUILD_TARGET : BuildTarget = {
13
+ const STATIC_BUILD_TARGET : BuildTarget = {
14
14
name : `${ PROJECT } :build:production`
15
15
} ;
16
+ const SERVER_BUILD_TARGET : BuildTarget = {
17
+ name : `${ PROJECT } :server:production`
18
+ } ;
16
19
17
20
const initMocks = ( ) => {
18
21
fsHost = {
@@ -53,7 +56,13 @@ const initMocks = () => {
53
56
id : 1 ,
54
57
logger : new logging . NullLogger ( ) as any ,
55
58
workspaceRoot : 'cwd' ,
56
- getTargetOptions : ( _ : Target ) => Promise . resolve ( { } ) ,
59
+ getTargetOptions : async ( target : Target ) => {
60
+ if ( target . target === 'build' ) {
61
+ return { outputPath : 'dist/browser' } ;
62
+ } else if ( target . target === 'server' ) {
63
+ return { outputPath : 'dist/server' } ;
64
+ }
65
+ } ,
57
66
reportProgress : ( _ : number , __ ?: number , ___ ?: string ) => {
58
67
} ,
59
68
reportStatus : ( _ : string ) => {
@@ -65,32 +74,18 @@ const initMocks = () => {
65
74
} as any ) ;
66
75
} ;
67
76
68
-
69
- const projectTargets : experimental . workspace . WorkspaceTool = {
70
- build : {
71
- options : {
72
- outputPath : 'dist/browser'
73
- }
74
- } ,
75
- server : {
76
- options : {
77
- outputPath : 'dist/server'
78
- }
79
- }
80
- } ;
81
-
82
77
describe ( 'Deploy Angular apps' , ( ) => {
83
78
beforeEach ( ( ) => initMocks ( ) ) ;
84
79
85
80
it ( 'should call login' , async ( ) => {
86
81
const spy = spyOn ( firebaseMock , 'login' ) ;
87
- await deploy ( firebaseMock , context , projectTargets , [ BUILD_TARGET ] , FIREBASE_PROJECT , false , false ) ;
82
+ await deploy ( firebaseMock , context , STATIC_BUILD_TARGET , undefined , FIREBASE_PROJECT , false ) ;
88
83
expect ( spy ) . toHaveBeenCalled ( ) ;
89
84
} ) ;
90
85
91
86
it ( 'should invoke the builder' , async ( ) => {
92
87
const spy = spyOn ( context , 'scheduleTarget' ) . and . callThrough ( ) ;
93
- await deploy ( firebaseMock , context , projectTargets , [ BUILD_TARGET ] , FIREBASE_PROJECT , false , false ) ;
88
+ await deploy ( firebaseMock , context , STATIC_BUILD_TARGET , undefined , FIREBASE_PROJECT , false ) ;
94
89
expect ( spy ) . toHaveBeenCalled ( ) ;
95
90
expect ( spy ) . toHaveBeenCalledWith ( {
96
91
target : 'build' ,
@@ -105,14 +100,14 @@ describe('Deploy Angular apps', () => {
105
100
options : { }
106
101
} ;
107
102
const spy = spyOn ( context , 'scheduleTarget' ) . and . callThrough ( ) ;
108
- await deploy ( firebaseMock , context , projectTargets , [ buildTarget ] , FIREBASE_PROJECT , false , false ) ;
103
+ await deploy ( firebaseMock , context , buildTarget , undefined , FIREBASE_PROJECT , false ) ;
109
104
expect ( spy ) . toHaveBeenCalled ( ) ;
110
105
expect ( spy ) . toHaveBeenCalledWith ( { target : 'prerender' , project : PROJECT } , { } ) ;
111
106
} ) ;
112
107
113
108
it ( 'should invoke firebase.deploy' , async ( ) => {
114
109
const spy = spyOn ( firebaseMock , 'deploy' ) . and . callThrough ( ) ;
115
- await deploy ( firebaseMock , context , projectTargets , [ BUILD_TARGET ] , FIREBASE_PROJECT , false , false ) ;
110
+ await deploy ( firebaseMock , context , STATIC_BUILD_TARGET , undefined , FIREBASE_PROJECT , false ) ;
116
111
expect ( spy ) . toHaveBeenCalled ( ) ;
117
112
expect ( spy ) . toHaveBeenCalledWith ( {
118
113
cwd : 'cwd' ,
@@ -123,7 +118,7 @@ describe('Deploy Angular apps', () => {
123
118
describe ( 'error handling' , ( ) => {
124
119
it ( 'throws if there is no firebase project' , async ( ) => {
125
120
try {
126
- await deploy ( firebaseMock , context , projectTargets , [ BUILD_TARGET ] , undefined , false , false ) ;
121
+ await deploy ( firebaseMock , context , STATIC_BUILD_TARGET , undefined , undefined , false ) ;
127
122
} catch ( e ) {
128
123
console . log ( e ) ;
129
124
expect ( e . message ) . toMatch ( / C a n n o t f i n d f i r e b a s e p r o j e c t / ) ;
@@ -133,7 +128,7 @@ describe('Deploy Angular apps', () => {
133
128
it ( 'throws if there is no target project' , async ( ) => {
134
129
context . target = undefined ;
135
130
try {
136
- await deploy ( firebaseMock , context , projectTargets , [ BUILD_TARGET ] , FIREBASE_PROJECT , false , false ) ;
131
+ await deploy ( firebaseMock , context , STATIC_BUILD_TARGET , undefined , FIREBASE_PROJECT , false ) ;
137
132
} catch ( e ) {
138
133
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 / ) ;
139
134
}
@@ -146,7 +141,7 @@ describe('universal deployment', () => {
146
141
147
142
it ( 'should create a firebase function' , async ( ) => {
148
143
const spy = spyOn ( fsHost , 'writeFileSync' ) ;
149
- await deployToFunction ( firebaseMock , context , '/home/user' , projectTargets , false , fsHost ) ;
144
+ await deployToFunction ( firebaseMock , context , '/home/user' , STATIC_BUILD_TARGET , SERVER_BUILD_TARGET , false , fsHost ) ;
150
145
151
146
expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
152
147
@@ -159,7 +154,7 @@ describe('universal deployment', () => {
159
154
160
155
it ( 'should rename the index.html file in the nested dist' , async ( ) => {
161
156
const spy = spyOn ( fsHost , 'renameSync' ) ;
162
- await deployToFunction ( firebaseMock , context , '/home/user' , projectTargets , false , fsHost ) ;
157
+ await deployToFunction ( firebaseMock , context , '/home/user' , STATIC_BUILD_TARGET , SERVER_BUILD_TARGET , false , fsHost ) ;
163
158
164
159
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
165
160
@@ -173,7 +168,7 @@ describe('universal deployment', () => {
173
168
174
169
it ( 'should invoke firebase.deploy' , async ( ) => {
175
170
const spy = spyOn ( firebaseMock , 'deploy' ) ;
176
- await deployToFunction ( firebaseMock , context , '/home/user' , projectTargets , false , fsHost ) ;
171
+ await deployToFunction ( firebaseMock , context , '/home/user' , STATIC_BUILD_TARGET , SERVER_BUILD_TARGET , false , fsHost ) ;
177
172
178
173
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
179
174
} ) ;
0 commit comments