1- import { experimental , JsonObject , logging } from '@angular-devkit/core' ;
1+ import { JsonObject , logging } from '@angular-devkit/core' ;
22import { BuilderContext , BuilderRun , ScheduleOptions , Target } from '@angular-devkit/architect' ;
33import { BuildTarget , FirebaseDeployConfig , FirebaseTools , FSHost } from '../interfaces' ;
44import deploy , { deployToFunction } from './actions' ;
@@ -10,9 +10,12 @@ let fsHost: FSHost;
1010
1111const FIREBASE_PROJECT = 'ikachu-aa3ef' ;
1212const PROJECT = 'pirojok-project' ;
13- const BUILD_TARGET : BuildTarget = {
13+ const STATIC_BUILD_TARGET : BuildTarget = {
1414 name : `${ PROJECT } :build:production`
1515} ;
16+ const SERVER_BUILD_TARGET : BuildTarget = {
17+ name : `${ PROJECT } :server:production`
18+ } ;
1619
1720const initMocks = ( ) => {
1821 fsHost = {
@@ -53,7 +56,13 @@ const initMocks = () => {
5356 id : 1 ,
5457 logger : new logging . NullLogger ( ) as any ,
5558 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+ } ,
5766 reportProgress : ( _ : number , __ ?: number , ___ ?: string ) => {
5867 } ,
5968 reportStatus : ( _ : string ) => {
@@ -65,32 +74,18 @@ const initMocks = () => {
6574 } as any ) ;
6675} ;
6776
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-
8277describe ( 'Deploy Angular apps' , ( ) => {
8378 beforeEach ( ( ) => initMocks ( ) ) ;
8479
8580 it ( 'should call login' , async ( ) => {
8681 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 ) ;
8883 expect ( spy ) . toHaveBeenCalled ( ) ;
8984 } ) ;
9085
9186 it ( 'should invoke the builder' , async ( ) => {
9287 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 ) ;
9489 expect ( spy ) . toHaveBeenCalled ( ) ;
9590 expect ( spy ) . toHaveBeenCalledWith ( {
9691 target : 'build' ,
@@ -105,14 +100,14 @@ describe('Deploy Angular apps', () => {
105100 options : { }
106101 } ;
107102 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 ) ;
109104 expect ( spy ) . toHaveBeenCalled ( ) ;
110105 expect ( spy ) . toHaveBeenCalledWith ( { target : 'prerender' , project : PROJECT } , { } ) ;
111106 } ) ;
112107
113108 it ( 'should invoke firebase.deploy' , async ( ) => {
114109 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 ) ;
116111 expect ( spy ) . toHaveBeenCalled ( ) ;
117112 expect ( spy ) . toHaveBeenCalledWith ( {
118113 cwd : 'cwd' ,
@@ -123,7 +118,7 @@ describe('Deploy Angular apps', () => {
123118 describe ( 'error handling' , ( ) => {
124119 it ( 'throws if there is no firebase project' , async ( ) => {
125120 try {
126- await deploy ( firebaseMock , context , projectTargets , [ BUILD_TARGET ] , undefined , false , false ) ;
121+ await deploy ( firebaseMock , context , STATIC_BUILD_TARGET , undefined , undefined , false ) ;
127122 } catch ( e ) {
128123 console . log ( e ) ;
129124 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', () => {
133128 it ( 'throws if there is no target project' , async ( ) => {
134129 context . target = undefined ;
135130 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 ) ;
137132 } catch ( e ) {
138133 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 / ) ;
139134 }
@@ -146,7 +141,7 @@ describe('universal deployment', () => {
146141
147142 it ( 'should create a firebase function' , async ( ) => {
148143 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 ) ;
150145
151146 expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
152147
@@ -159,7 +154,7 @@ describe('universal deployment', () => {
159154
160155 it ( 'should rename the index.html file in the nested dist' , async ( ) => {
161156 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 ) ;
163158
164159 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
165160
@@ -173,7 +168,7 @@ describe('universal deployment', () => {
173168
174169 it ( 'should invoke firebase.deploy' , async ( ) => {
175170 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 ) ;
177172
178173 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
179174 } ) ;
0 commit comments