MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/integration/next-image-legacy/base-path/test/static.test.ts:22–101  ·  view source on GitHub ↗
(isDev = false)

Source from the content-addressed store, hash-verified

20const indexPage = new File(join(appDir, 'pages/static-img.js'))
21
22const runTests = (isDev = false) => {
23 it('Should allow an image with a static src to omit height and width', async () => {
24 expect(await browser.elementById('basic-static')).toBeTruthy()
25 expect(await browser.elementById('blur-png')).toBeTruthy()
26 expect(await browser.elementById('blur-webp')).toBeTruthy()
27 expect(await browser.elementById('blur-avif')).toBeTruthy()
28 expect(await browser.elementById('blur-jpg')).toBeTruthy()
29 expect(await browser.elementById('static-svg')).toBeTruthy()
30 expect(await browser.elementById('static-gif')).toBeTruthy()
31 expect(await browser.elementById('static-bmp')).toBeTruthy()
32 expect(await browser.elementById('static-ico')).toBeTruthy()
33 expect(await browser.elementById('static-unoptimized')).toBeTruthy()
34 })
35 it('Should use immutable cache-control header for static import', async () => {
36 await browser.eval(
37 `document.getElementById("basic-static").scrollIntoView()`
38 )
39 await waitFor(1000)
40 const url = await browser.eval(
41 `document.getElementById("basic-static").src`
42 )
43 const res = await fetch(url)
44 expect(res.headers.get('cache-control')).toBe(
45 'public, max-age=315360000, immutable'
46 )
47 })
48
49 if (!isDev) {
50 it('Should use immutable cache-control header even when unoptimized', async () => {
51 await browser.eval(
52 `document.getElementById("static-unoptimized").scrollIntoView()`
53 )
54 await waitFor(1000)
55 const url = await browser.eval(
56 `document.getElementById("static-unoptimized").src`
57 )
58 const res = await fetch(url)
59 expect(res.headers.get('cache-control')).toBe(
60 'public, max-age=31536000, immutable'
61 )
62 })
63 }
64 it('Should automatically provide an image height and width', async () => {
65 expect(html).toContain('width:400px;height:300px')
66 })
67 it('Should allow provided width and height to override intrinsic', async () => {
68 expect(html).toContain('width:200px;height:200px')
69 expect(html).not.toContain('width:400px;height:400px')
70 })
71 it('Should add a blur placeholder to statically imported jpg', async () => {
72 if (process.env.IS_TURBOPACK_TEST) {
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("data:image/jpeg;base64`
75 )
76 } else {
77 expect(html).toContain(
78 `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(${
79 isDev

Callers 1

static.test.tsFile · 0.70

Calls 7

waitForFunction · 0.90
elementByIdMethod · 0.80
evalMethod · 0.80
getMethod · 0.65
itFunction · 0.50
expectFunction · 0.50
fetchFunction · 0.50

Tested by

no test coverage detected