1- /* eslint-disable max-nested-callbacks */
1+ /* eslint-disable max-nested-callbacks, ava/no-import-test-files */
22import process from 'process'
33
44import {
88import Chance from 'chance'
99
1010import { onBuild , onSuccess } from '../../src/index'
11+ import { enableGatsbyExcludeDatastoreFromBundle } from '../helpers'
1112
1213jest . mock ( 'node-fetch' , ( ) => ( {
1314 __esModule : true ,
@@ -158,7 +159,8 @@ describe('plugin', () => {
158159 } = require ( '../../src/helpers/config' )
159160
160161 it ( 'creates the metadata file for the Gatsby datastore when GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE is enabled' , async ( ) => {
161- process . env . GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE = 'true'
162+ enableGatsbyExcludeDatastoreFromBundle ( )
163+
162164 createMetadataFileAndCopyDatastore . mockImplementation ( ( ) =>
163165 Promise . resolve ( ) ,
164166 )
@@ -211,31 +213,30 @@ describe('plugin', () => {
211213
212214 beforeEach ( ( ) => {
213215 fetch . mockImplementation ( mockFetchMethod )
214- process . env . GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE = 'true'
215- process . env . URL = chance . url ( )
216+ enableGatsbyExcludeDatastoreFromBundle ( )
216217 } )
217218
218219 afterEach ( ( ) => {
219220 delete process . env . GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE
220- delete process . env . URL
221+ delete process . env . DEPLOY_PRIME_URL
221222 } )
222223
223224 it ( 'makes requests to pre-warm the lambdas if GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE is enabled' , async ( ) => {
224225 await onSuccess ( )
225226 const controller = new AbortController ( )
226227 expect ( fetch ) . toHaveBeenNthCalledWith (
227228 1 ,
228- `${ process . env . URL } /.netlify/functions/__api` ,
229+ `${ process . env . DEPLOY_PRIME_URL } /.netlify/functions/__api` ,
229230 { signal : controller . signal } ,
230231 )
231232 expect ( fetch ) . toHaveBeenNthCalledWith (
232233 2 ,
233- `${ process . env . URL } /.netlify/functions/__dsg` ,
234+ `${ process . env . DEPLOY_PRIME_URL } /.netlify/functions/__dsg` ,
234235 { signal : controller . signal } ,
235236 )
236237 expect ( fetch ) . toHaveBeenNthCalledWith (
237238 3 ,
238- `${ process . env . URL } /.netlify/functions/__ssr` ,
239+ `${ process . env . DEPLOY_PRIME_URL } /.netlify/functions/__ssr` ,
239240 { signal : controller . signal } ,
240241 )
241242 } )
@@ -255,6 +256,14 @@ describe('plugin', () => {
255256
256257 expect ( fetch ) . toBeCalledTimes ( 0 )
257258 } )
259+
260+ it ( 'does not make requests to pre-warm the lambdas if process.env.DEPLOY_PRIME_URL is not defined' , async ( ) => {
261+ delete process . env . DEPLOY_PRIME_URL
262+
263+ await onSuccess ( )
264+
265+ expect ( fetch ) . toBeCalledTimes ( 0 )
266+ } )
258267 } )
259268} )
260- /* eslint-enable max-nested-callbacks */
269+ /* eslint-enable max-nested-callbacks, ava/no-import-test-files */
0 commit comments