@@ -58,76 +58,104 @@ function responseToSnapshotJson(response: InternalResponse) {
5858describe ( 'with an express app' , ( ) => {
5959 let app : Express ;
6060
61- beforeAll ( async ( ) => {
62- app = await createServer ( 9000 , {
63- baseDir : TEST_DIR ,
64- env : TEST_ENV ,
65- logs : false ,
66- } as StartCliConfig ) ;
67- } ) ;
61+ describe ( 'with inline function handling' , ( ) => {
62+ beforeAll ( async ( ) => {
63+ app = await createServer ( 9000 , {
64+ baseDir : TEST_DIR ,
65+ env : TEST_ENV ,
66+ logs : false ,
67+ } as StartCliConfig ) ;
68+ } ) ;
69+
70+ describe ( 'Function integration tests' , ( ) => {
71+ for ( const testFnCode of availableFunctions ) {
72+ test ( `${ testFnCode . name } should match snapshot` , async ( ) => {
73+ const response = await request ( app ) . get ( testFnCode . url ) ;
74+ if ( response . status === 500 ) {
75+ expect ( response . text ) . toMatch ( / E r r o r / ) ;
76+ } else {
77+ const result = responseToSnapshotJson ( response as InternalResponse ) ;
78+ expect ( result ) . toMatchSnapshot ( ) ;
79+ }
80+ } ) ;
81+ }
82+ } ) ;
6883
69- describe ( 'Function integration tests' , ( ) => {
70- for ( const testFnCode of availableFunctions ) {
71- test ( `${ testFnCode . name } should match snapshot` , async ( ) => {
72- const response = await request ( app ) . get ( testFnCode . url ) ;
73- if ( response . status === 500 ) {
74- expect ( response . text ) . toMatch ( / E r r o r / ) ;
75- } else {
84+ describe ( 'Assets integration tests' , ( ) => {
85+ for ( const testAsset of availableAssets ) {
86+ test ( `${ testAsset . name } should match snapshot` , async ( ) => {
87+ const response = await request ( app ) . get ( testAsset . url ) ;
7688 const result = responseToSnapshotJson ( response as InternalResponse ) ;
7789 expect ( result ) . toMatchSnapshot ( ) ;
78- }
79- } ) ;
80- }
81- } ) ;
90+ } ) ;
8291
83- describe ( 'Assets integration tests' , ( ) => {
84- for ( const testAsset of availableAssets ) {
85- test ( `${ testAsset . name } should match snapshot` , async ( ) => {
86- const response = await request ( app ) . get ( testAsset . url ) ;
87- const result = responseToSnapshotJson ( response as InternalResponse ) ;
88- expect ( result ) . toMatchSnapshot ( ) ;
89- } ) ;
92+ test ( `OPTIONS request to ${ testAsset . name } should return CORS headers and no body` , async ( ) => {
93+ const response = ( await request ( app ) . options (
94+ testAsset . url
95+ ) ) as InternalResponse ;
96+ expect ( response . headers [ 'access-control-allow-origin' ] ) . toEqual ( '*' ) ;
97+ expect ( response . headers [ 'access-control-allow-headers' ] ) . toEqual (
98+ 'Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since'
99+ ) ;
100+ expect ( response . headers [ 'access-control-allow-methods' ] ) . toEqual (
101+ 'GET, POST, OPTIONS'
102+ ) ;
103+ expect ( response . headers [ 'access-control-expose-headers' ] ) . toEqual (
104+ 'ETag'
105+ ) ;
106+ expect ( response . headers [ 'access-control-max-age' ] ) . toEqual ( '86400' ) ;
107+ expect ( response . headers [ 'access-control-allow-credentials' ] ) . toEqual (
108+ 'true'
109+ ) ;
110+ expect ( response . text ) . toEqual ( '' ) ;
111+ } ) ;
90112
91- test ( `OPTIONS request to ${ testAsset . name } should return CORS headers and no body` , async ( ) => {
92- const response = ( await request ( app ) . options (
93- testAsset . url
94- ) ) as InternalResponse ;
95- expect ( response . headers [ 'access-control-allow-origin' ] ) . toEqual ( '*' ) ;
96- expect ( response . headers [ 'access-control-allow-headers' ] ) . toEqual (
97- 'Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since'
98- ) ;
99- expect ( response . headers [ 'access-control-allow-methods' ] ) . toEqual (
100- 'GET, POST, OPTIONS'
101- ) ;
102- expect ( response . headers [ 'access-control-expose-headers' ] ) . toEqual (
103- 'ETag'
104- ) ;
105- expect ( response . headers [ 'access-control-max-age' ] ) . toEqual ( '86400' ) ;
106- expect ( response . headers [ 'access-control-allow-credentials' ] ) . toEqual (
107- 'true'
108- ) ;
109- expect ( response . text ) . toEqual ( '' ) ;
110- } ) ;
113+ test ( `GET request to ${ testAsset . name } should not return CORS headers` , async ( ) => {
114+ const response = ( await request ( app ) . get (
115+ testAsset . url
116+ ) ) as InternalResponse ;
117+ expect (
118+ response . headers [ 'access-control-allow-origin' ]
119+ ) . toBeUndefined ( ) ;
120+ expect (
121+ response . headers [ 'access-control-allow-headers' ]
122+ ) . toBeUndefined ( ) ;
123+ expect (
124+ response . headers [ 'access-control-allow-methods' ]
125+ ) . toBeUndefined ( ) ;
126+ expect (
127+ response . headers [ 'access-control-expose-headers' ]
128+ ) . toBeUndefined ( ) ;
129+ expect ( response . headers [ 'access-control-max-age' ] ) . toBeUndefined ( ) ;
130+ expect (
131+ response . headers [ 'access-control-allow-credentials' ]
132+ ) . toBeUndefined ( ) ;
133+ } ) ;
134+ }
135+ } ) ;
136+ } ) ;
137+ xdescribe ( 'with forked process function handling' , ( ) => {
138+ beforeAll ( async ( ) => {
139+ app = await createServer ( 9000 , {
140+ baseDir : TEST_DIR ,
141+ env : TEST_ENV ,
142+ logs : false ,
143+ forkProcess : true ,
144+ } as StartCliConfig ) ;
145+ } ) ;
111146
112- test ( `GET request to ${ testAsset . name } should not return CORS headers` , async ( ) => {
113- const response = ( await request ( app ) . get (
114- testAsset . url
115- ) ) as InternalResponse ;
116- expect ( response . headers [ 'access-control-allow-origin' ] ) . toBeUndefined ( ) ;
117- expect (
118- response . headers [ 'access-control-allow-headers' ]
119- ) . toBeUndefined ( ) ;
120- expect (
121- response . headers [ 'access-control-allow-methods' ]
122- ) . toBeUndefined ( ) ;
123- expect (
124- response . headers [ 'access-control-expose-headers' ]
125- ) . toBeUndefined ( ) ;
126- expect ( response . headers [ 'access-control-max-age' ] ) . toBeUndefined ( ) ;
127- expect (
128- response . headers [ 'access-control-allow-credentials' ]
129- ) . toBeUndefined ( ) ;
130- } ) ;
131- }
147+ describe ( 'Function integration tests' , ( ) => {
148+ for ( const testFnCode of availableFunctions ) {
149+ test ( `${ testFnCode . name } should match snapshot` , async ( ) => {
150+ const response = await request ( app ) . get ( testFnCode . url ) ;
151+ if ( response . status === 500 ) {
152+ expect ( response . text ) . toMatch ( / E r r o r / ) ;
153+ } else {
154+ const result = responseToSnapshotJson ( response as InternalResponse ) ;
155+ expect ( result ) . toMatchSnapshot ( ) ;
156+ }
157+ } ) ;
158+ }
159+ } ) ;
132160 } ) ;
133161} ) ;
0 commit comments