@@ -35,10 +35,28 @@ function initializeContext(): Context {
3535 ignore : [ ] ,
3636 } ,
3737 ] ,
38+ [
39+ "foo-local-build" ,
40+ {
41+ backendId : "foo-local-build" ,
42+ rootDir : "/" ,
43+ ignore : [ ] ,
44+ localBuild : true ,
45+ } ,
46+ ] ,
47+ ] ) ,
48+ backendLocations : new Map < string , string > ( [
49+ [ "foo" , "us-central1" ] ,
50+ [ "foo-local-build" , "us-central1" ] ,
3851 ] ) ,
39- backendLocations : new Map < string , string > ( [ [ "foo" , "us-central1" ] ] ) ,
4052 backendStorageUris : new Map < string , string > ( ) ,
41- backendLocalBuilds : { } ,
53+ backendLocalBuilds : {
54+ "foo-local-build" : {
55+ buildDir : "./nextjs/standalone" ,
56+ buildConfig : { } ,
57+ annotations : { } ,
58+ } ,
59+ } ,
4260 } ;
4361}
4462
@@ -67,17 +85,25 @@ describe("apphosting", () => {
6785 sinon . verifyAndRestore ( ) ;
6886 } ) ;
6987
70- describe ( "deploy" , ( ) => {
88+ describe ( "deploy local source " , ( ) => {
7189 const opts = {
7290 ...BASE_OPTS ,
7391 projectId : "my-project" ,
7492 only : "apphosting" ,
7593 config : new Config ( {
76- apphosting : {
77- backendId : "foo" ,
78- rootDir : "/" ,
79- ignore : [ ] ,
80- } ,
94+ apphosting : [
95+ {
96+ backendId : "foo" ,
97+ rootDir : "/" ,
98+ ignore : [ ] ,
99+ } ,
100+ {
101+ backendId : "foo-local-build" ,
102+ rootDir : "/" ,
103+ ignore : [ ] ,
104+ localBuild : true ,
105+ } ,
106+ ] ,
81107 } ) ,
82108 } ;
83109
@@ -89,36 +115,87 @@ describe("apphosting", () => {
89115 original : new FirebaseError ( "original error" , { status : 404 } ) ,
90116 } ) ,
91117 ) ;
118+ getBucketStub . onSecondCall ( ) . rejects (
119+ new FirebaseError ( "error" , {
120+ original : new FirebaseError ( "original error" , { status : 404 } ) ,
121+ } ) ,
122+ ) ;
92123 createBucketStub . resolves ( ) ;
93- createArchiveStub . resolves ( "path/to/foo-1234.zip" ) ;
94- uploadObjectStub . resolves ( {
124+ createArchiveStub . onFirstCall ( ) . resolves ( "path/to/foo-1234.zip" ) ;
125+ createArchiveStub . onSecondCall ( ) . resolves ( "path/to/foo-local-build-1234.zip" ) ;
126+ uploadObjectStub . onFirstCall ( ) . resolves ( {
95127 bucket : "firebaseapphosting-sources-12345678-us-central1" ,
96128 object : "foo-1234" ,
97129 } ) ;
130+ uploadObjectStub . onSecondCall ( ) . resolves ( {
131+ bucket : "firebaseapphosting-build-12345678-us-central1" ,
132+ object : "foo-local-build-1234" ,
133+ } ) ;
134+
98135 createReadStreamStub . resolves ( ) ;
99136
100137 await deploy ( context , opts ) ;
101138
102- expect ( createBucketStub ) . to . be . calledOnce ;
139+ // assert backend foo calls
140+ expect ( createBucketStub ) . to . be . calledWithMatch ( "my-project" , {
141+ name : "firebaseapphosting-sources-000000000000-us-central1" ,
142+ location : "us-central1" ,
143+ lifecycle : sinon . match . any ,
144+ } ) ;
145+ expect ( createArchiveStub ) . to . be . calledWithExactly (
146+ context . backendConfigs . get ( "foo" ) ,
147+ process . cwd ( ) ,
148+ undefined ,
149+ ) ;
150+ expect ( uploadObjectStub ) . to . be . calledWithMatch (
151+ sinon . match . any ,
152+ "firebaseapphosting-sources-000000000000-us-central1" ,
153+ ) ;
154+
155+ // assert backend foo-local-build calls
156+ expect ( createBucketStub ) . to . be . calledWithMatch ( "my-project" , {
157+ name : "firebaseapphosting-build-000000000000-us-central1" ,
158+ location : "us-central1" ,
159+ lifecycle : sinon . match . any ,
160+ } ) ;
161+ expect ( createArchiveStub ) . to . be . calledWithExactly (
162+ context . backendConfigs . get ( "foo-local-build" ) ,
163+ process . cwd ( ) ,
164+ "./nextjs/standalone" ,
165+ ) ;
166+ expect ( uploadObjectStub ) . to . be . calledWithMatch (
167+ sinon . match . any ,
168+ "firebaseapphosting-build-000000000000-us-central1" ,
169+ ) ;
103170 } ) ;
104171
105172 it ( "correctly creates and sets storage URIs" , async ( ) => {
106173 const context = initializeContext ( ) ;
107174 getProjectNumberStub . resolves ( "000000000000" ) ;
108175 getBucketStub . resolves ( ) ;
109176 createBucketStub . resolves ( ) ;
110- createArchiveStub . resolves ( "path/to/foo-1234.zip" ) ;
111- uploadObjectStub . resolves ( {
112- bucket : "firebaseapphosting-sources-12345678-us-central1" ,
177+ createArchiveStub . onFirstCall ( ) . resolves ( "path/to/foo-1234.zip" ) ;
178+ createArchiveStub . onSecondCall ( ) . resolves ( "path/to/foo-local-build-1234.zip" ) ;
179+
180+ uploadObjectStub . onFirstCall ( ) . resolves ( {
181+ bucket : "firebaseapphosting-sources-000000000000-us-central1" ,
113182 object : "foo-1234" ,
114183 } ) ;
184+
185+ uploadObjectStub . onSecondCall ( ) . resolves ( {
186+ bucket : "firebaseapphosting-build-000000000000-us-central1" ,
187+ object : "foo-local-build-1234" ,
188+ } ) ;
115189 createReadStreamStub . resolves ( ) ;
116190
117191 await deploy ( context , opts ) ;
118192
119193 expect ( context . backendStorageUris . get ( "foo" ) ) . to . equal (
120194 "gs://firebaseapphosting-sources-000000000000-us-central1/foo-1234.zip" ,
121195 ) ;
196+ expect ( context . backendStorageUris . get ( "foo-local-build" ) ) . to . equal (
197+ "gs://firebaseapphosting-build-000000000000-us-central1/foo-local-build-1234.zip" ,
198+ ) ;
122199 } ) ;
123200 } ) ;
124201} ) ;
0 commit comments