55 */
66
77import { test , expect } from "@playwright/test" ;
8+ import sharp from "sharp" ;
89
910test . describe ( "playground/cloudflare" , ( ) => {
1011 test ( "NextConfig" , async ( { page } ) => {
@@ -21,36 +22,64 @@ test.describe("playground/cloudflare", () => {
2122
2223 test . describe ( "remotePatterns" , ( ) => {
2324 test ( "fetch an image allowed by remotePatterns" , async ( { page } ) => {
24- const res = await page . request . get ( "/_next/image?url=https://avatars.githubusercontent.com/u/248818" ) ;
25+ const res = await page . request . get (
26+ "/_next/image?url=https://avatars.githubusercontent.com/u/248818&w=256&q=75"
27+ ) ;
2528 expect ( res . status ( ) ) . toBe ( 200 ) ;
2629 expect ( res . headers ( ) ) . toMatchObject ( { "content-type" : "image/jpeg" } ) ;
2730 } ) ;
2831
2932 test ( "400 when fetching an image disallowed by remotePatterns" , async ( { page } ) => {
30- const res = await page . request . get ( "/_next/image?url=https://avatars.githubusercontent.com/u/248817" ) ;
33+ const res = await page . request . get (
34+ "/_next/image?url=https://avatars.githubusercontent.com/u/248817&w=256&q=75"
35+ ) ;
3136 expect ( res . status ( ) ) . toBe ( 400 ) ;
3237 } ) ;
3338 } ) ;
3439
3540 test . describe ( "localPatterns" , ( ) => {
3641 test ( "fetch an image allowed by localPatterns" , async ( { page } ) => {
37- const res = await page . request . get ( "/_next/image?url=/snipp/snipp.webp?iscute=yes" ) ;
42+ const res = await page . request . get ( "/_next/image?url=/snipp/snipp.webp?iscute=yes&w=256&q=75 " ) ;
3843 expect ( res . status ( ) ) . toBe ( 200 ) ;
3944 expect ( res . headers ( ) ) . toMatchObject ( { "content-type" : "image/webp" } ) ;
4045 } ) ;
4146
4247 test ( "400 when fetching an image disallowed by localPatterns with wrong query parameter" , async ( {
4348 page,
4449 } ) => {
45- const res = await page . request . get ( "/_next/image?url=/snipp/snipp?iscute=no" ) ;
50+ const res = await page . request . get ( "/_next/image?url=/snipp/snipp?iscute=no&w=256&q=75 " ) ;
4651 expect ( res . status ( ) ) . toBe ( 400 ) ;
4752 } ) ;
4853
4954 test ( "400 when fetching an image disallowed by localPatterns without query parameter" , async ( {
5055 page,
5156 } ) => {
52- const res = await page . request . get ( "/_next/image?url=/snipp/snipp" ) ;
57+ const res = await page . request . get ( "/_next/image?url=/snipp/snipp&w=256&q=75 " ) ;
5358 expect ( res . status ( ) ) . toBe ( 400 ) ;
5459 } ) ;
5560 } ) ;
61+
62+ test . describe ( "imageSizes" , ( ) => {
63+ test ( "400 when fetching an image with unsupported width value" , async ( { page } ) => {
64+ const res = await page . request . get ( "/_next/image?url=/snipp/snipp.webp?iscute=yes&w=100&q=75" ) ;
65+ expect ( res . status ( ) ) . toBe ( 400 ) ;
66+ } ) ;
67+ } ) ;
68+
69+ test . describe ( "qualities" , ( ) => {
70+ test ( "400 when fetching an image with unsupported quality value" , async ( { page } ) => {
71+ const res = await page . request . get ( "/_next/image?url=/snipp/snipp.webp?iscute=yes&w=256&q=100" ) ;
72+ expect ( res . status ( ) ) . toBe ( 400 ) ;
73+ } ) ;
74+ } ) ;
75+
76+ test . describe ( '"w" parameter' , ( ) => {
77+ test ( "Image is shrunk to target width" , async ( { page } ) => {
78+ const res = await page . request . get ( "/_next/image?url=/snipp/snipp.webp?iscute=yes&w=256&q=75" ) ;
79+ expect ( res . status ( ) ) . toBe ( 200 ) ;
80+ const buffer = await res . body ( ) ;
81+ const metadata = await sharp ( buffer ) . metadata ( ) ;
82+ expect ( metadata . width ) . toBe ( 256 ) ;
83+ } ) ;
84+ } ) ;
5685} ) ;
0 commit comments