@@ -30,9 +30,22 @@ function initializeContext(): Context {
3030 rootDir : "/" ,
3131 ignore : [ ] ,
3232 } ,
33+ fooLocalBuild : {
34+ backendId : "fooLocalBuild" ,
35+ rootDir : "/" ,
36+ ignore : [ ] ,
37+ localBuild : true ,
38+ } ,
3339 } ,
34- backendLocations : { foo : "us-central1" } ,
40+ backendLocations : { foo : "us-central1" , fooLocalBuild : "us-central1" } ,
3541 backendStorageUris : { } ,
42+ backendLocalBuilds : {
43+ fooLocalBuild : {
44+ buildDir : "./nextjs/standalone" ,
45+ buildConfig : { } ,
46+ annotations : { } ,
47+ } ,
48+ } ,
3649 } ;
3750}
3851
@@ -59,17 +72,25 @@ describe("apphosting", () => {
5972 sinon . verifyAndRestore ( ) ;
6073 } ) ;
6174
62- describe ( "deploy" , ( ) => {
75+ describe ( "deploy local source " , ( ) => {
6376 const opts = {
6477 ...BASE_OPTS ,
6578 projectId : "my-project" ,
6679 only : "apphosting" ,
6780 config : new Config ( {
68- apphosting : {
69- backendId : "foo" ,
70- rootDir : "/" ,
71- ignore : [ ] ,
72- } ,
81+ apphosting : [
82+ {
83+ backendId : "foo" ,
84+ rootDir : "/" ,
85+ ignore : [ ] ,
86+ } ,
87+ {
88+ backendId : "fooLocalBuild" ,
89+ rootDir : "/" ,
90+ ignore : [ ] ,
91+ localBuild : true ,
92+ } ,
93+ ] ,
7394 } ) ,
7495 } ;
7596
@@ -78,18 +99,26 @@ describe("apphosting", () => {
7899 const projectNumber = "000000000000" ;
79100 const location = "us-central1" ;
80101 const bucketName = `firebaseapphosting-sources-${ projectNumber } -${ location } ` ;
81-
82102 getProjectNumberStub . resolves ( projectNumber ) ;
83103 upsertBucketStub . resolves ( bucketName ) ;
84- createArchiveStub . resolves ( "path/to/foo-1234.zip" ) ;
85- uploadObjectStub . resolves ( {
104+ createArchiveStub . onFirstCall ( ) . resolves ( "path/to/foo-1234.zip" ) ;
105+ createArchiveStub . onSecondCall ( ) . resolves ( "path/to/foo-local-build-1234.zip" ) ;
106+
107+ uploadObjectStub . onFirstCall ( ) . resolves ( {
86108 bucket : bucketName ,
87109 object : "foo-1234" ,
88110 } ) ;
111+ uploadObjectStub . onSecondCall ( ) . resolves ( {
112+ bucket : bucketName ,
113+ object : "foo-local-build-1234" ,
114+ } ) ;
115+
89116 createReadStreamStub . returns ( "stream" as any ) ;
90117
91118 await deploy ( context , opts ) ;
92119
120+ // assert backend foo calls
121+
93122 expect ( upsertBucketStub ) . to . be . calledWith ( {
94123 product : "apphosting" ,
95124 createMessage : `Creating Cloud Storage bucket in ${ location } to store App Hosting source code uploads at ${ bucketName } ...` ,
@@ -108,26 +137,65 @@ describe("apphosting", () => {
108137 } ,
109138 } ,
110139 } ) ;
140+
141+ // assert backend fooLocalBuild calls
142+ expect ( upsertBucketStub ) . to . be . calledWith ( {
143+ product : "apphosting" ,
144+ createMessage :
145+ "Creating Cloud Storage bucket in us-central1 to store App Hosting source code uploads at firebaseapphosting-sources-000000000000-us-central1..." ,
146+ projectId : "my-project" ,
147+ req : {
148+ baseName : "firebaseapphosting-sources-000000000000-us-central1" ,
149+ purposeLabel : `apphosting-source-${ location } ` ,
150+ location : "us-central1" ,
151+ lifecycle : {
152+ rule : [
153+ {
154+ action : { type : "Delete" } ,
155+ condition : { age : 30 } ,
156+ } ,
157+ ] ,
158+ } ,
159+ } ,
160+ } ) ;
161+ expect ( createArchiveStub ) . to . be . calledWithExactly (
162+ context . backendConfigs [ "fooLocalBuild" ] ,
163+ process . cwd ( ) ,
164+ "./nextjs/standalone" ,
165+ ) ;
166+ expect ( uploadObjectStub ) . to . be . calledWithMatch (
167+ sinon . match . any ,
168+ "firebaseapphosting-sources-000000000000-us-central1" ,
169+ ) ;
111170 } ) ;
112171
113172 it ( "correctly creates and sets storage URIs" , async ( ) => {
114173 const context = initializeContext ( ) ;
115174 const projectNumber = "000000000000" ;
116175 const location = "us-central1" ;
117176 const bucketName = `firebaseapphosting-sources-${ projectNumber } -${ location } ` ;
118-
119177 getProjectNumberStub . resolves ( projectNumber ) ;
120178 upsertBucketStub . resolves ( bucketName ) ;
121- createArchiveStub . resolves ( "path/to/foo-1234.zip" ) ;
122- uploadObjectStub . resolves ( {
179+ createArchiveStub . onFirstCall ( ) . resolves ( "path/to/foo-1234.zip" ) ;
180+ createArchiveStub . onSecondCall ( ) . resolves ( "path/to/foo-local-build-1234.zip" ) ;
181+
182+ uploadObjectStub . onFirstCall ( ) . resolves ( {
123183 bucket : bucketName ,
124184 object : "foo-1234" ,
125185 } ) ;
186+
187+ uploadObjectStub . onSecondCall ( ) . resolves ( {
188+ bucket : bucketName ,
189+ object : "foo-local-build-1234" ,
190+ } ) ;
126191 createReadStreamStub . returns ( "stream" as any ) ;
127192
128193 await deploy ( context , opts ) ;
129194
130195 expect ( context . backendStorageUris [ "foo" ] ) . to . equal ( `gs://${ bucketName } /foo-1234.zip` ) ;
196+ expect ( context . backendStorageUris [ "fooLocalBuild" ] ) . to . equal (
197+ `gs://${ bucketName } /foo-local-build-1234.zip` ,
198+ ) ;
131199 } ) ;
132200 } ) ;
133201} ) ;
0 commit comments