Skip to content

Commit 0483bb2

Browse files
committed
chore: add tests for image ef
1 parent ad51812 commit 0483bb2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/runtime/src/helpers/edge.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ export const writeEdgeFunctions = async (netlifyConfig: NetlifyConfig) => {
206206
await copy(getEdgeTemplatePath('../edge-shared'), join(edgeFunctionRoot, 'edge-shared'))
207207
await writeJSON(join(edgeFunctionRoot, 'edge-shared', 'nextConfig.json'), nextConfig)
208208

209-
if (!process.env.NEXT_DISABLE_EDGE_IMAGES) {
209+
if (
210+
process.env.NEXT_DISABLE_EDGE_IMAGES !== '1' &&
211+
process.env.NEXT_DISABLE_EDGE_IMAGES !== 'true' &&
212+
process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' &&
213+
process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1'
214+
) {
210215
console.log(
211216
'Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.',
212217
)

test/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,29 @@ describe('onBuild()', () => {
571571
'X-Foo': mockHeaderValue,
572572
})
573573
})
574+
575+
test('generates an ipx edge function by default', async () => {
576+
await moveNextDist()
577+
await nextRuntime.onBuild(defaultArgs)
578+
expect(existsSync(path.join('.netlify', 'edge-functions', 'ipx', 'index.ts'))).toBeTruthy()
579+
})
580+
581+
test('does not generate an ipx edge function if the feature is disabled', async () => {
582+
process.env.NEXT_DISABLE_EDGE_IMAGES = '1'
583+
await moveNextDist()
584+
await nextRuntime.onBuild(defaultArgs)
585+
expect(existsSync(path.join('.netlify', 'edge-functions', 'ipx', 'index.ts'))).toBeFalsy()
586+
delete process.env.NEXT_DISABLE_EDGE_IMAGES
587+
})
588+
589+
test('does not generate an ipx edge function if Netlify Edge is disabled', async () => {
590+
process.env.NEXT_DISABLE_NETLIFY_EDGE = '1'
591+
await moveNextDist()
592+
await nextRuntime.onBuild(defaultArgs)
593+
594+
expect(existsSync(path.join('.netlify', 'edge-functions', 'ipx', 'index.ts'))).toBeFalsy()
595+
delete process.env.NEXT_DISABLE_NETLIFY_EDGE
596+
})
574597
})
575598

576599
describe('onPostBuild', () => {

0 commit comments

Comments
 (0)