Skip to content

Commit e66185d

Browse files
authored
Turbopack build: Fix next/image tests (vercel#68449)
## What? These tests were checking specific values that are slightly different with Turbopack but still correct. Updated the tests. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
1 parent 939251b commit e66185d

4 files changed

Lines changed: 40 additions & 18 deletions

File tree

test/integration/next-image-legacy/default/test/static.test.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
File,
88
waitFor,
99
} from 'next-test-utils'
10+
import cheerio from 'cheerio'
1011
import webdriver from 'next-webdriver'
1112
import { join } from 'path'
1213

@@ -65,14 +66,28 @@ const runTests = () => {
6566
expect(html).not.toContain('width:400px;height:400px')
6667
})
6768
it('Should add a blur placeholder to statically imported jpg', async () => {
68-
expect(html).toContain(
69-
`style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url(&quot;data:image/jpeg;base64,/9j/2wBDAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/v/2wBDAQoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/v/wgARCAAGAAgDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAACVA//EABwQAAICAgMAAAAAAAAAAAAAABITERQAAwUVIv/aAAgBAQABPwB3H9YmrsuvN5+VxADn/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwB//9k=&quot;)"`
70-
)
69+
const $ = cheerio.load(html)
70+
if (process.env.TURBOPACK) {
71+
expect($('#basic-static').attr('style')).toMatchInlineSnapshot(
72+
`"position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/wAARCAAGAAgDAREAAhEBAxEB/9sAQwAKBwcIBwYKCAgICwoKCw4YEA4NDQ4dFRYRGCMfJSQiHyIhJis3LyYpNCkhIjBBMTQ5Oz4+PiUuRElDPEg3PT47/9sAQwEKCwsODQ4cEBAcOygiKDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDyj7Rp39h/Zvscn9oefv8AtPmfLsxjZtx+Oc0Af//Z")"`
73+
)
74+
} else {
75+
expect($('#basic-static').attr('style')).toMatchInlineSnapshot(
76+
`"position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url("data:image/jpeg;base64,/9j/2wBDAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/v/2wBDAQoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/v/wgARCAAGAAgDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAACVA//EABwQAAICAgMAAAAAAAAAAAAAABITERQAAwUVIv/aAAgBAQABPwB3H9YmrsuvN5+VxADn/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwB//9k=")"`
77+
)
78+
}
7179
})
7280
it('Should add a blur placeholder to statically imported png', async () => {
73-
expect(html).toContain(
74-
`style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAICAMAAAALMbVOAAAAFVBMVEUBAQEtLS1CQkIHBwf9/f21tbWurq5/IXexAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAHElEQVR4nGNggAJmJmYGJhYmBlYWNgZGRkaYMAACTwAjtdG5RQAAAABJRU5ErkJggg==&quot;)`
75-
)
81+
const $ = cheerio.load(html)
82+
if (process.env.TURBOPACK) {
83+
expect($('#basic-static')[2].attribs.style).toMatchInlineSnapshot(
84+
`"position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAICAYAAAA870V8AAAARUlEQVR42l3MoQ0AQQhE0XG7xWwIJSBIKBRJOZRBEXOWnPjimQ8AXC3ce+nuPOcQEcHuppkRVcWZYWYSIkJV5XvvN9j4AFZHJTnjDHb/AAAAAElFTkSuQmCC")"`
85+
)
86+
} else {
87+
expect($('#basic-static')[2].attribs.style).toMatchInlineSnapshot(
88+
`"position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAICAMAAAALMbVOAAAAFVBMVEUBAQEtLS1CQkIHBwf9/f21tbWurq5/IXexAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAHElEQVR4nGNggAJmJmYGJhYmBlYWNgZGRkaYMAACTwAjtdG5RQAAAABJRU5ErkJggg==")"`
89+
)
90+
}
7691
})
7792

7893
it('should load direct imported image', async () => {
@@ -115,7 +130,12 @@ describe('Build Error Tests', () => {
115130
"Module not found: Can't resolve '../public/foo/test-rect-broken.jpg"
116131
)
117132
// should contain the importing module
118-
expect(stderr).toContain('./pages/static-img.js')
133+
if (process.env.TURBOPACK) {
134+
// For this test with Turbopack the root of the project is the root of the Next.js repository because it's not isolated.
135+
expect(stderr).toContain('pages/static-img.js')
136+
} else {
137+
expect(stderr).toContain('./pages/static-img.js')
138+
}
119139
// should contain a import trace
120140
expect(stderr).not.toContain('Import trace for requested module')
121141
})

test/integration/next-image-new/app-dir/test/static.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ describe('Build Error Tests', () => {
238238
"Module not found: Can't resolve '../../public/foo/test-rect-broken.jpg"
239239
)
240240
// should contain the importing module
241-
expect(stderr).toContain('./app/static-img/page.js')
241+
if (process.env.TURBOPACK) {
242+
// For this test with Turbopack the root of the project is the root of the Next.js repository because it's not isolated.
243+
expect(stderr).toContain('app/static-img/page.js')
244+
} else {
245+
expect(stderr).toContain('./app/static-img/page.js')
246+
}
242247
// should contain a import trace
243248
expect(stderr).not.toContain('Import trace for requested module')
244249
})

test/integration/next-image-new/default/test/static.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe('Build Error Tests', () => {
250250
"Module not found: Can't resolve '../public/foo/test-rect-broken.jpg"
251251
)
252252
// should contain the importing module
253-
expect(stderr).toContain('./pages/static-img.js')
253+
expect(stderr).toContain('pages/static-img.js')
254254
// should contain a import trace
255255
expect(stderr).not.toContain('Import trace for requested module')
256256
})

test/turbopack-build-tests-manifest.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13040,13 +13040,12 @@
1304013040
"Static Image Component Tests production mode Should use immutable cache-control header even when unoptimized",
1304113041
"Static Image Component Tests production mode Should use immutable cache-control header for static import",
1304213042
"Static Image Component Tests production mode should load direct imported image",
13043-
"Static Image Component Tests production mode should load staticprops imported image"
13044-
],
13045-
"failed": [
13043+
"Static Image Component Tests production mode should load staticprops imported image",
1304613044
"Build Error Tests production mode should throw build error when import statement is used with missing file",
1304713045
"Static Image Component Tests production mode Should add a blur placeholder to statically imported jpg",
1304813046
"Static Image Component Tests production mode Should add a blur placeholder to statically imported png"
1304913047
],
13048+
"failed": [],
1305013049
"pending": [],
1305113050
"flakey": [],
1305213051
"runtimeError": false
@@ -13289,11 +13288,10 @@
1328913288
"Static Image Component Tests production mode should load direct imported image",
1329013289
"Static Image Component Tests production mode should use height prop to adjust both width and height",
1329113290
"Static Image Component Tests production mode should use width and height prop to override import",
13292-
"Static Image Component Tests production mode should use width prop to adjust both width and height"
13293-
],
13294-
"failed": [
13291+
"Static Image Component Tests production mode should use width prop to adjust both width and height",
1329513292
"Build Error Tests production mode should throw build error when import statement is used with missing file"
1329613293
],
13294+
"failed": [],
1329713295
"pending": [
1329813296
"Static Image Component Tests development mode Should allow an image with a static src to omit height and width",
1329913297
"Static Image Component Tests development mode Should automatically provide an image height and width",
@@ -13512,11 +13510,10 @@
1351213510
"Static Image Component Tests production mode should load staticprops imported image",
1351313511
"Static Image Component Tests production mode should use height prop to adjust both width and height",
1351413512
"Static Image Component Tests production mode should use width and height prop to override import",
13515-
"Static Image Component Tests production mode should use width prop to adjust both width and height"
13516-
],
13517-
"failed": [
13513+
"Static Image Component Tests production mode should use width prop to adjust both width and height",
1351813514
"Build Error Tests production mode should throw build error when import statement is used with missing file"
1351913515
],
13516+
"failed": [],
1352013517
"pending": [
1352113518
"Static Image Component Tests development mode Should allow an image with a static src to omit height and width",
1352213519
"Static Image Component Tests development mode Should automatically provide an image height and width",

0 commit comments

Comments
 (0)