Skip to content

Commit 7b6ffca

Browse files
chore: add edge functions file watcher tests (#4581)
* chore: add edge functions watcher tests
1 parent b844274 commit 7b6ffca

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

tests/integration/100.command.dev.test.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { Response } = require('node-fetch')
1111

1212
const { withDevServer } = require('./utils/dev-server')
1313
const got = require('./utils/got')
14+
const { pause } = require('./utils/pause')
1415
const { withSiteBuilder } = require('./utils/site-builder')
1516

1617
const test = isCI ? avaTest.serial.bind(avaTest) : avaTest
@@ -377,4 +378,98 @@ test(`catches invalid function names`, async (t) => {
377378
})
378379
})
379380
})
381+
382+
test('should detect content changes in edge functions', async (t) => {
383+
await withSiteBuilder('site-with-edge-functions', async (builder) => {
384+
const publicDir = 'public'
385+
await builder
386+
.withNetlifyToml({
387+
config: {
388+
build: {
389+
publish: publicDir,
390+
edge_functions: 'netlify/edge-functions',
391+
},
392+
edge_functions: [
393+
{
394+
function: 'hello',
395+
path: '/hello',
396+
},
397+
],
398+
},
399+
})
400+
.withEdgeFunction({
401+
handler: () => new Response('Hello world'),
402+
name: 'hello',
403+
})
404+
405+
await builder.buildAsync()
406+
407+
await withDevServer({ cwd: builder.directory }, async ({ port }) => {
408+
const helloWorldMessage = await got(`http://localhost:${port}/hello`).then((response) => response.body)
409+
410+
await builder
411+
.withEdgeFunction({
412+
handler: () => new Response('Hello builder'),
413+
name: 'hello',
414+
})
415+
.buildAsync()
416+
417+
const DETECT_FILE_CHANGE_DELAY = 500
418+
await pause(DETECT_FILE_CHANGE_DELAY)
419+
420+
const helloBuilderMessage = await got(`http://localhost:${port}/hello`).then((response) => response.body)
421+
422+
t.is(helloWorldMessage, 'Hello world')
423+
t.is(helloBuilderMessage, 'Hello builder')
424+
})
425+
})
426+
})
427+
428+
test('should detect deleted edge functions', async (t) => {
429+
await withSiteBuilder('site-with-edge-functions', async (builder) => {
430+
const publicDir = 'public'
431+
builder
432+
.withNetlifyToml({
433+
config: {
434+
build: {
435+
publish: publicDir,
436+
edge_functions: 'netlify/edge-functions',
437+
},
438+
edge_functions: [
439+
{
440+
function: 'auth',
441+
path: '/auth',
442+
},
443+
],
444+
},
445+
})
446+
.withEdgeFunction({
447+
handler: () => new Response('Auth response'),
448+
name: 'auth',
449+
})
450+
451+
await builder.buildAsync()
452+
453+
await withDevServer({ cwd: builder.directory }, async ({ port }) => {
454+
const authResponseMessage = await got(`http://localhost:${port}/auth`).then((response) => response.body)
455+
456+
await builder
457+
.withoutFile({
458+
path: 'netlify/edge-functions/auth.js',
459+
})
460+
.buildAsync()
461+
462+
const DETECT_FILE_CHANGE_DELAY = 500
463+
await pause(DETECT_FILE_CHANGE_DELAY)
464+
465+
const authNotFoundMessage = await got(`http://localhost:${port}/auth`, { throwHttpErrors: false }).then(
466+
(response) => response.body,
467+
)
468+
469+
t.is(authResponseMessage, 'Auth response')
470+
t.is(authNotFoundMessage, 'Not Found')
471+
})
472+
})
473+
})
474+
380475
/* eslint-enable require-await */

0 commit comments

Comments
 (0)