Skip to content

Commit dabc560

Browse files
committed
test: adjust EF deploy tests to not add netlifyConfig configuration and use inline config, also add cases for internal and framework functions
1 parent 882b3ee commit dabc560

File tree

1 file changed

+155
-42
lines changed

1 file changed

+155
-42
lines changed

tests/integration/commands/deploy/deploy.test.ts

Lines changed: 155 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -167,69 +167,182 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
167167
})
168168
})
169169

170-
test('should deploy Edge Functions when directory exists', async (t) => {
171-
await withSiteBuilder(t, async (builder) => {
172-
const content = 'Edge Function works NOT'
173-
builder
174-
.withContentFile({
175-
path: 'public/index.html',
176-
content,
177-
})
178-
.withNetlifyToml({
179-
config: {
180-
build: { publish: 'public', command: 'echo "no op"' },
181-
edge_functions: [{ function: 'edge', path: '/*' }],
182-
},
170+
for (const { variant, shouldRunBuildBeforeDeploy } of [
171+
{
172+
variant: 'after running a build',
173+
shouldRunBuildBeforeDeploy: true,
174+
},
175+
{
176+
variant: 'without running a build',
177+
shouldRunBuildBeforeDeploy: false,
178+
},
179+
]) {
180+
test(`should deploy Edge Functions when directory exists ${variant}`, async (t) => {
181+
await withSiteBuilder(t, async (builder) => {
182+
const content = 'Edge Function works NOT'
183+
builder
184+
.withContentFile({
185+
path: 'public/index.html',
186+
content,
187+
})
188+
.withNetlifyToml({
189+
config: {
190+
build: { publish: 'public', command: 'echo "no op"' },
191+
},
192+
})
193+
.withEdgeFunction({
194+
handler: async () => new Response('Edge Function works'),
195+
config: {
196+
path: '/*',
197+
},
198+
name: 'edge',
199+
})
200+
201+
await builder.build()
202+
203+
const options = {
204+
cwd: builder.directory,
205+
env: { NETLIFY_SITE_ID: context.siteId },
206+
}
207+
208+
if (shouldRunBuildBeforeDeploy) {
209+
await callCli(['build'], options)
210+
}
211+
const deploy = await callCli(['deploy', '--json', '--no-build'], options).then((output: string) =>
212+
JSON.parse(output),
213+
)
214+
215+
// give edge functions manifest a couple ticks to propagate
216+
await pause(500)
217+
218+
await validateDeploy({
219+
deploy,
220+
siteName: SITE_NAME,
221+
content: 'Edge Function works',
222+
contentMessage: 'Edge function did not execute correctly or was not deployed correctly',
183223
})
184-
.withEdgeFunction({
185-
handler: async () => new Response('Edge Function works'),
186-
name: 'edge',
224+
})
225+
})
226+
227+
test(`should deploy Edge Functions with custom cwd when directory exists ${variant}`, async (t) => {
228+
await withSiteBuilder(t, async (builder) => {
229+
const content = 'Edge Function works NOT'
230+
const pathPrefix = 'app/cool'
231+
builder
232+
.withContentFile({
233+
path: 'app/cool/public/index.html',
234+
content,
235+
})
236+
.withNetlifyToml({
237+
config: {
238+
build: { publish: 'public', command: 'echo "no op"' },
239+
},
240+
pathPrefix,
241+
})
242+
.withEdgeFunction({
243+
handler: async () => new Response('Edge Function works'),
244+
name: 'edge',
245+
config: {
246+
path: '/*',
247+
},
248+
pathPrefix,
249+
})
250+
251+
await builder.build()
252+
253+
const options = {
254+
cwd: builder.directory,
255+
env: { NETLIFY_SITE_ID: context.siteId },
256+
}
257+
258+
if (shouldRunBuildBeforeDeploy) {
259+
await callCli(['build', '--cwd', pathPrefix], options)
260+
}
261+
const deploy = await callCli(['deploy', '--json', '--no-build', '--cwd', pathPrefix], options).then(
262+
(output: string) => JSON.parse(output),
263+
)
264+
265+
// give edge functions manifest a couple ticks to propagate
266+
await pause(500)
267+
268+
await validateDeploy({
269+
deploy,
270+
siteName: SITE_NAME,
271+
content: 'Edge Function works',
272+
contentMessage: 'Edge function did not execute correctly or was not deployed correctly',
187273
})
274+
})
275+
})
188276

189-
await builder.build()
277+
test(`should deploy integrations Edge Functions when directory exists ${variant}`, async (t) => {
278+
await withSiteBuilder(t, async (builder) => {
279+
const content = 'Edge Function works NOT'
280+
builder
281+
.withContentFile({
282+
path: 'public/index.html',
283+
content,
284+
})
285+
.withNetlifyToml({
286+
config: {
287+
build: { publish: 'public', command: 'echo "no op"' },
288+
},
289+
})
290+
.withEdgeFunction({
291+
handler: async () => new Response('Edge Function works'),
292+
config: {
293+
path: '/*',
294+
},
295+
name: 'edge',
296+
path: '.netlify/edge-functions',
297+
})
190298

191-
const options = {
192-
cwd: builder.directory,
193-
env: { NETLIFY_SITE_ID: context.siteId },
194-
}
299+
await builder.build()
195300

196-
await callCli(['build'], options)
197-
const deploy = await callCli(['deploy', '--json', '--no-build'], options).then((output: string) =>
198-
JSON.parse(output),
199-
)
301+
const options = {
302+
cwd: builder.directory,
303+
env: { NETLIFY_SITE_ID: context.siteId },
304+
}
200305

201-
// give edge functions manifest a couple ticks to propagate
202-
await pause(500)
306+
if (shouldRunBuildBeforeDeploy) {
307+
await callCli(['build'], options)
308+
}
309+
const deploy = await callCli(['deploy', '--json', '--no-build'], options).then((output: string) =>
310+
JSON.parse(output),
311+
)
203312

204-
await validateDeploy({
205-
deploy,
206-
siteName: SITE_NAME,
207-
content: 'Edge Function works',
208-
contentMessage: 'Edge function did not execute correctly or was not deployed correctly',
313+
// give edge functions manifest a couple ticks to propagate
314+
await pause(500)
315+
316+
await validateDeploy({
317+
deploy,
318+
siteName: SITE_NAME,
319+
content: 'Edge Function works',
320+
contentMessage: 'Edge function did not execute correctly or was not deployed correctly',
321+
})
209322
})
210323
})
211-
})
324+
}
212325

213-
test('should deploy Edge Functions with custom cwd when directory exists', async (t) => {
326+
test('should deploy framework Edge Functions when directory exists without running a build', async (t) => {
214327
await withSiteBuilder(t, async (builder) => {
215328
const content = 'Edge Function works NOT'
216-
const pathPrefix = 'app/cool'
217329
builder
218330
.withContentFile({
219-
path: 'app/cool/public/index.html',
331+
path: 'public/index.html',
220332
content,
221333
})
222334
.withNetlifyToml({
223335
config: {
224336
build: { publish: 'public', command: 'echo "no op"' },
225-
edge_functions: [{ function: 'edge', path: '/*' }],
226337
},
227-
pathPrefix,
228338
})
229339
.withEdgeFunction({
230340
handler: async () => new Response('Edge Function works'),
341+
config: {
342+
path: '/*',
343+
},
231344
name: 'edge',
232-
pathPrefix,
345+
path: '.netlify/v1/edge-functions',
233346
})
234347

235348
await builder.build()
@@ -239,9 +352,9 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
239352
env: { NETLIFY_SITE_ID: context.siteId },
240353
}
241354

242-
await callCli(['build', '--cwd', pathPrefix], options)
243-
const deploy = await callCli(['deploy', '--json', '--no-build', '--cwd', pathPrefix], options).then(
244-
(output: string) => JSON.parse(output),
355+
// skipping running build here, because it cleans up frameworks API directories
356+
const deploy = await callCli(['deploy', '--json', '--no-build'], options).then((output: string) =>
357+
JSON.parse(output),
245358
)
246359

247360
// give edge functions manifest a couple ticks to propagate

0 commit comments

Comments
 (0)