@@ -14,16 +14,18 @@ describe("export", () => {
1414
1515 const mockDelegate = {
1616 language : "nodejs" ,
17- runtime : "nodejs18" ,
17+ runtime : supported . latest ( "nodejs" ) ,
1818 validate : sinon . stub ( ) ,
1919 build : sinon . stub ( ) ,
2020 discoverBuild : sinon . stub ( ) ,
21- } ;
21+ bin : "node" ,
22+ watch : sinon . stub ( ) ,
23+ } as const ;
2224
2325 beforeEach ( ( ) => {
2426 sinon . stub ( functionsConfig , "getFirebaseConfig" ) . resolves ( { projectId : "my-project" } ) ;
2527 sinon . stub ( functionsEnv , "loadFirebaseEnvs" ) . returns ( { } ) ;
26- sinon . stub ( runtimes , "getRuntimeDelegate" ) . resolves ( mockDelegate as any ) ;
28+ sinon . stub ( runtimes , "getRuntimeDelegate" ) . resolves ( mockDelegate ) ;
2729 sinon . stub ( supported , "guardVersionSupport" ) ;
2830 needProjectIdStub = sinon . stub ( projectUtils , "needProjectId" ) . returns ( "my-project" ) ;
2931 } ) ;
@@ -44,7 +46,7 @@ describe("export", () => {
4446 const codebase : projectConfig . ValidatedSingle = {
4547 source : "src" ,
4648 codebase : "default" ,
47- runtime : "nodejs18" ,
49+ runtime : supported . latest ( "nodejs" ) as supported . ActiveRuntime ,
4850 } ;
4951
5052 const result = await exportIac . getInternalIac ( options , codebase ) ;
@@ -57,5 +59,32 @@ describe("export", () => {
5759 "functions.yaml" : yaml . dump ( mockBuild ) ,
5860 } ) ;
5961 } ) ;
62+
63+ it ( "should throw if codebase has no source" , async ( ) => {
64+ const options = { config : { path : ( s : string ) => s , projectDir : "dir" } } ;
65+ const codebase : projectConfig . ValidatedSingle = {
66+ codebase : "default" ,
67+ runtime : supported . latest ( "nodejs" ) as supported . ActiveRuntime ,
68+ } as unknown as projectConfig . ValidatedSingle ;
69+
70+ await expect ( exportIac . getInternalIac ( options , codebase ) ) . to . be . rejectedWith (
71+ "Cannot export a codebase with no source" ,
72+ ) ;
73+ } ) ;
74+
75+ it ( "should throw an error if discoverBuild fails" , async ( ) => {
76+ mockDelegate . discoverBuild . rejects ( new Error ( "Failed to discover build" ) ) ;
77+
78+ const options = { config : { path : ( s : string ) => s , projectDir : "dir" } } ;
79+ const codebase : projectConfig . ValidatedSingle = {
80+ source : "src" ,
81+ codebase : "default" ,
82+ runtime : supported . latest ( "nodejs" ) as supported . ActiveRuntime ,
83+ } ;
84+
85+ await expect ( exportIac . getInternalIac ( options , codebase ) ) . to . be . rejectedWith (
86+ "Failed to discover build" ,
87+ ) ;
88+ } ) ;
6089 } ) ;
6190} ) ;
0 commit comments