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

Function runTests

test/integration/next-image-legacy/default/test/static.test.ts:22–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20const indexPage = new File(join(appDir, 'pages/static-img.js'))
21
22const runTests = () => {
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 it('Should use immutable cache-control header even when unoptimized', async () => {
49 await browser.eval(
50 `document.getElementById("static-unoptimized").scrollIntoView()`
51 )
52 await waitFor(1000)
53 const url = await browser.eval(
54 `document.getElementById("static-unoptimized").src`
55 )
56 const res = await fetch(url)
57 expect(res.headers.get('cache-control')).toBe(
58 'public, max-age=31536000, immutable'
59 )
60 })
61 it('Should automatically provide an image height and width', async () => {
62 expect(html).toContain('width:400px;height:300px')
63 })
64 it('Should allow provided width and height to override intrinsic', async () => {
65 expect(html).toContain('width:200px;height:200px')
66 expect(html).not.toContain('width:400px;height:400px')
67 })
68 it('Should add a blur placeholder to statically imported jpg', async () => {
69 const $ = cheerio.load(html)
70 // The base64 snapshot is not necessarily stable across OSs and Architectures
71 if (process.env.IS_TURBOPACK_TEST) {
72 expect(
73 replaceDataUrl($('#basic-static').attr('style'))
74 ).toMatchInlineSnapshot(
75 `"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:<REPLACED>")"`
76 )
77 } else {
78 expect(
79 replaceDataUrl($('#basic-static').attr('style'))

Callers 1

static.test.tsFile · 0.70

Calls 11

waitForFunction · 0.90
replaceDataUrlFunction · 0.85
elementByIdMethod · 0.80
evalMethod · 0.80
getAttributeMethod · 0.80
getMethod · 0.65
loadMethod · 0.65
itFunction · 0.50
expectFunction · 0.50
fetchFunction · 0.50
$Function · 0.50

Tested by

no test coverage detected