11import { expect } from "chai" ;
2+ import * as glob from "glob" ;
23
34import * as cli from "./cli" ;
45import { requireAuth } from "../../src/requireAuth" ;
6+ import { getBuildId } from "../../src/frameworks/next/utils" ;
7+ import { relative } from "path" ;
58
6- const FIREBASE_PROJECT = process . env . GCLOUD_PROJECT || "" ;
9+ const FIREBASE_PROJECT = process . env . FBTOOLS_TARGET_PROJECT || "" ;
710const FIREBASE_DEBUG = process . env . FIREBASE_DEBUG || "" ;
811
912function genRandomId ( n = 10 ) : string {
@@ -15,37 +18,109 @@ function genRandomId(n = 10): string {
1518 return id ;
1619}
1720
18- describe ( "webframeworks deploy" , function ( this ) {
21+ async function getFilesListFromDir ( dir : string ) : Promise < string [ ] > {
22+ const files = await new Promise < string [ ] > ( ( resolve , reject ) => {
23+ glob ( `${ dir } /**/*` , ( err , matches ) => {
24+ if ( err ) reject ( err ) ;
25+ resolve ( matches ) ;
26+ } ) ;
27+ } ) ;
28+ return files . map ( ( path ) => relative ( dir , path ) ) ;
29+ }
30+
31+ describe ( "webframeworks deploy build" , function ( this ) {
1932 this . timeout ( 1000_000 ) ;
2033
34+ let result : cli . Result ;
35+
2136 const RUN_ID = genRandomId ( ) ;
2237 console . log ( `TEST RUN: ${ RUN_ID } ` ) ;
2338
24- async function setOptsAndDeploy ( ) : Promise < cli . Result > {
25- const args = [ ] ;
39+ async function setOptsAndBuild ( ) : Promise < cli . Result > {
40+ const args = [ "exit 0" ] ;
2641 if ( FIREBASE_DEBUG ) {
2742 args . push ( "--debug" ) ;
2843 }
29- return await cli . exec ( "deploy" , FIREBASE_PROJECT , args , __dirname , false ) ;
44+
45+ return await cli . exec ( "emulators:exec" , FIREBASE_PROJECT , args , __dirname , false ) ;
3046 }
3147
3248 before ( async ( ) => {
3349 expect ( FIREBASE_PROJECT ) . to . not . be . empty ;
3450
3551 await requireAuth ( { } ) ;
52+ process . env . FIREBASE_CLI_EXPERIMENTS = "webframeworks" ;
53+ result = await setOptsAndBuild ( ) ;
3654 } ) ;
3755
3856 after ( ( ) => {
3957 // This is not an empty block.
4058 } ) ;
4159
42- it ( "deploys functions with runtime options" , async ( ) => {
60+ it ( "should log reasons for backend" , ( ) => {
4361 process . env . FIREBASE_CLI_EXPERIMENTS = "webframeworks" ;
4462
45- const result = await setOptsAndDeploy ( ) ;
63+ expect ( result . stdout , "build result" ) . to . match (
64+ / B u i l d i n g a C l o u d F u n c t i o n t o r u n t h i s a p p l i c a t i o n . T h i s i s n e e d e d d u e t o : /
65+ ) ;
66+ expect ( result . stdout , "build result" ) . to . match ( / m i d d l e w a r e / ) ;
67+ expect ( result . stdout , "build result" ) . to . match ( / I m a g e O p t i m i z a t i o n / ) ;
68+ expect ( result . stdout , "build result" ) . to . match ( / u s e o f r e v a l i d a t e \/ b a r / ) ;
69+ expect ( result . stdout , "build result" ) . to . match ( / n o n - s t a t i c r o u t e \/ a p i \/ h e l l o / ) ;
70+ } ) ;
71+
72+ it ( "should have the expected static files to be deployed" , async ( ) => {
73+ const buildId = await getBuildId ( `${ __dirname } /hosting/.next` ) ;
74+
75+ const DOT_FIREBASE_FOLDER_PATH = `${ __dirname } /.firebase/${ FIREBASE_PROJECT } ` ;
76+
77+ const EXPECTED_FILES = [
78+ `_next` ,
79+ `_next/static` ,
80+ `_next/static/chunks` ,
81+ `_next/static/chunks/app` ,
82+ `_next/static/chunks/app/bar` ,
83+ `_next/static/chunks/app/foo` ,
84+ `_next/static/chunks/pages` ,
85+ `_next/static/chunks/pages/about` ,
86+ `_next/static/css` ,
87+ `_next/static/${ buildId } ` ,
88+ `_next/static/${ buildId } /_buildManifest.js` ,
89+ `_next/static/${ buildId } /_ssgManifest.js` ,
90+ `404.html` ,
91+ `500.html` ,
92+ `foo.html` ,
93+ `index.html` ,
94+ ] ;
95+
96+ const EXPECTED_PATTERNS = [
97+ `_next\/static\/chunks\/[0-9]+-[^\.]+\.js` ,
98+ `_next\/static\/chunks\/app-internals-[^\.]+\.js` ,
99+ `_next\/static\/chunks\/app\/bar\/page-[^\.]+\.js` ,
100+ `_next\/static\/chunks\/app\/foo\/page-[^\.]+\.js` ,
101+ `_next\/static\/chunks\/app\/layout-[^\.]+\.js` ,
102+ `_next\/static\/chunks\/main-[^\.]+\.js` ,
103+ `_next\/static\/chunks\/main-app-[^\.]+\.js` ,
104+ `_next\/static\/chunks\/pages\/_app-[^\.]+\.js` ,
105+ `_next\/static\/chunks\/pages\/_error-[^\.]+\.js` ,
106+ `_next\/static\/chunks\/pages\/about\/me-[^\.]+\.js` ,
107+ `_next\/static\/chunks\/pages\/index-[^\.]+\.js` ,
108+ `_next\/static\/chunks\/polyfills-[^\.]+\.js` ,
109+ `_next\/static\/chunks\/webpack-[^\.]+\.js` ,
110+ `_next\/static\/css\/[^\.]+\.css` ,
111+ ] . map ( ( it ) => new RegExp ( it ) ) ;
112+
113+ const files = await getFilesListFromDir ( `${ DOT_FIREBASE_FOLDER_PATH } /hosting` ) ;
114+ const unmatchedFiles = files . filter (
115+ ( it ) =>
116+ ! ( EXPECTED_FILES . includes ( it ) || EXPECTED_PATTERNS . some ( ( pattern ) => ! ! it . match ( pattern ) ) )
117+ ) ;
118+ const unmatchedExpectations = [
119+ ...EXPECTED_FILES . filter ( ( it ) => ! files . includes ( it ) ) ,
120+ ...EXPECTED_PATTERNS . filter ( ( it ) => ! files . some ( ( file ) => ! ! file . match ( it ) ) ) ,
121+ ] ;
46122
47- expect ( result . stdout , "deploy result" ) . to . match ( / f i l e u p l o a d c o m p l e t e / ) ;
48- expect ( result . stdout , "deploy result" ) . to . match ( / f o u n d 2 0 f i l e s / ) ;
49- expect ( result . stdout , "deploy result" ) . to . match ( / D e p l o y c o m p l e t e ! / ) ;
123+ expect ( unmatchedFiles ) . to . be . empty ;
124+ expect ( unmatchedExpectations ) . to . be . empty ;
50125 } ) ;
51126} ) ;
0 commit comments