Skip to content

Commit ab17bfa

Browse files
committed
test: add tests
also do general cleanup
1 parent 276b948 commit ab17bfa

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

demos/default/netlify.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[build]
22
command = "next build"
33
publish = ".next"
4+
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"
45

56
[build.environment]
67
# cache Cypress binary in local "node_modules" folder

packages/runtime/src/helpers/functions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ export const setupImageFunction = async ({
7272
responseHeaders?: Record<string, string>
7373
}): Promise<void> => {
7474
const imagePath = imageconfig.path || '/_next/image'
75-
console.log('DISABLE?', process.env.DISABLE_IPX)
76-
75+
7776
if (isEnvSet('DISABLE_IPX')) {
7877
// If no image loader is specified, need to redirect to a 404 page since there's no
7978
// backing loader to serve local site images once deployed to Netlify

test/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,34 @@ describe('onBuild()', () => {
571571
'X-Foo': mockHeaderValue,
572572
})
573573
})
574+
575+
test('generates an ipx function by default', async () => {
576+
await moveNextDist()
577+
await nextRuntime.onBuild(defaultArgs)
578+
expect(existsSync(path.join('.netlify', 'functions-internal', '_ipx', '_ipx.js'))).toBeTruthy()
579+
})
580+
581+
test('does not generate an ipx function when DISABLE_IPX is set', async () => {
582+
process.env.DISABLE_IPX = '1'
583+
await moveNextDist()
584+
await nextRuntime.onBuild(defaultArgs)
585+
expect(existsSync(path.join('.netlify', 'functions-internal', '_ipx', '_ipx.js'))).toBeFalsy()
586+
delete process.env.DISABLE_IPX
587+
})
588+
589+
test('creates 404 redirect when DISABLE_IPX is set', async () => {
590+
process.env.DISABLE_IPX = '1'
591+
await moveNextDist()
592+
await nextRuntime.onBuild(defaultArgs)
593+
const nextImageRedirect = netlifyConfig.redirects.find(redirect => redirect.from.includes('/_next/image'))
594+
595+
expect(nextImageRedirect).toBeDefined()
596+
expect(nextImageRedirect.to).toEqual("/404.html")
597+
expect(nextImageRedirect.status).toEqual(404)
598+
expect(nextImageRedirect.force).toEqual(true)
599+
600+
delete process.env.DISABLE_IPX
601+
})
574602
})
575603

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

0 commit comments

Comments
 (0)