1
1
const { expect } = require ( 'chai' ) ;
2
2
const { getResponsiveImageAttributes } = require ( '../src/getResponsiveImageAttributes' ) ;
3
3
4
- describe . only ( 'getResponsiveImageAttributes – smoke run‑through ' , ( ) => {
4
+ describe . only ( 'getResponsiveImageAttributes' , ( ) => {
5
5
it ( 'bare minimum input' , ( ) => {
6
6
const out = getResponsiveImageAttributes ( {
7
7
src : 'sample.jpg' ,
8
8
urlEndpoint : 'https://ik.imagekit.io/demo' ,
9
9
} ) ;
10
- // Expected object based on default deviceSizes and imageSizes :
10
+ // Expected object based on default deviceBreakpoints and imageBreakpoints :
11
11
expect ( out ) . to . deep . equal ( {
12
12
src : "https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max" ,
13
13
srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-640,c-at_max 640w, https://ik.imagekit.io/demo/sample.jpg?tr=w-750,c-at_max 750w, https://ik.imagekit.io/demo/sample.jpg?tr=w-828,c-at_max 828w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1080,c-at_max 1080w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1200,c-at_max 1200w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1920,c-at_max 1920w, https://ik.imagekit.io/demo/sample.jpg?tr=w-2048,c-at_max 2048w, https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max 3840w" ,
14
- sizes : "100vw" ,
15
- width : undefined
14
+ sizes : "100vw"
16
15
} ) ;
17
16
} ) ;
18
17
@@ -26,8 +25,7 @@ describe.only('getResponsiveImageAttributes – smoke run‑through', () => {
26
25
expect ( out ) . to . deep . equal ( {
27
26
src : "https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max" ,
28
27
srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-640,c-at_max 640w, https://ik.imagekit.io/demo/sample.jpg?tr=w-750,c-at_max 750w, https://ik.imagekit.io/demo/sample.jpg?tr=w-828,c-at_max 828w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1080,c-at_max 1080w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1200,c-at_max 1200w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1920,c-at_max 1920w, https://ik.imagekit.io/demo/sample.jpg?tr=w-2048,c-at_max 2048w, https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max 3840w" ,
29
- sizes : "100vw" ,
30
- width : undefined
28
+ sizes : "100vw"
31
29
} ) ;
32
30
} ) ;
33
31
@@ -39,9 +37,8 @@ describe.only('getResponsiveImageAttributes – smoke run‑through', () => {
39
37
} ) ;
40
38
// When width is provided without sizes attribute, the DPR strategy should be used.
41
39
expect ( out ) . to . deep . equal ( {
42
- src : "https://ik.imagekit.io/demo/sample.jpg?tr=w-750,c-at_max" ,
43
- srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-640,c-at_max 1x, https://ik.imagekit.io/demo/sample.jpg?tr=w-750,c-at_max 2x" ,
44
- sizes : undefined ,
40
+ src : "https://ik.imagekit.io/demo/sample.jpg?tr=w-828,c-at_max" ,
41
+ srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-640,c-at_max 1x, https://ik.imagekit.io/demo/sample.jpg?tr=w-828,c-at_max 2x" ,
45
42
width : 400
46
43
} ) ;
47
44
} ) ;
@@ -50,15 +47,14 @@ describe.only('getResponsiveImageAttributes – smoke run‑through', () => {
50
47
const out = getResponsiveImageAttributes ( {
51
48
src : 'sample.jpg' ,
52
49
urlEndpoint : 'https://ik.imagekit.io/demo' ,
53
- deviceSizes : [ 200 , 400 , 800 ] ,
54
- imageSizes : [ 100 ] ,
50
+ deviceBreakpoints : [ 200 , 400 , 800 ] ,
51
+ imageBreakpoints : [ 100 ] ,
55
52
} ) ;
56
53
// For custom breakpoints, the breakpoints will be derived from the provided arrays.
57
54
expect ( out ) . to . deep . equal ( {
58
55
src : "https://ik.imagekit.io/demo/sample.jpg?tr=w-800,c-at_max" ,
59
56
srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-200,c-at_max 200w, https://ik.imagekit.io/demo/sample.jpg?tr=w-400,c-at_max 400w, https://ik.imagekit.io/demo/sample.jpg?tr=w-800,c-at_max 800w" ,
60
- sizes : "100vw" ,
61
- width : undefined
57
+ sizes : "100vw"
62
58
} ) ;
63
59
} ) ;
64
60
@@ -71,9 +67,8 @@ describe.only('getResponsiveImageAttributes – smoke run‑through', () => {
71
67
} ) ;
72
68
// The provided transformation should be preserved in the output.
73
69
expect ( out ) . to . deep . equal ( {
74
- src : "https://ik.imagekit.io/demo/sample.jpg?tr=height-300,w-1200,c-at_max" ,
75
- srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=height-300,w-640,c-at_max 1x, https://ik.imagekit.io/demo/sample.jpg?tr=height-300,w-1200,c-at_max 2x" ,
76
- sizes : undefined ,
70
+ src : "https://ik.imagekit.io/demo/sample.jpg?tr=h-300:w-1080,c-at_max" ,
71
+ srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=h-300:w-640,c-at_max 1x, https://ik.imagekit.io/demo/sample.jpg?tr=h-300:w-1080,c-at_max 2x" ,
77
72
width : 500
78
73
} ) ;
79
74
} ) ;
@@ -87,8 +82,8 @@ describe.only('getResponsiveImageAttributes – smoke run‑through', () => {
87
82
} ) ;
88
83
// Both sizes and width are provided, so the function should apply the sizes attribute while using width for DPR strategy.
89
84
expect ( out ) . to . deep . equal ( {
90
- src : "https://ik.imagekit.io/demo/sample.jpg?tr=w-1200 ,c-at_max" ,
91
- srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-640,c-at_max 640w, https://ik.imagekit.io/demo/sample.jpg?tr=w-750,c-at_max 750w, https://ik.imagekit.io/demo/sample.jpg?tr=w-828,c-at_max 828w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1080,c-at_max 1080w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1200,c-at_max 1200w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1920,c-at_max 1920w, https://ik.imagekit.io/demo/sample.jpg?tr=w-2048,c-at_max 2048w, https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max 3840w" ,
85
+ src : "https://ik.imagekit.io/demo/sample.jpg?tr=w-3840 ,c-at_max" ,
86
+ srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-384,c-at_max 384w, https://ik.imagekit.io/demo/sample.jpg?tr=w- 640,c-at_max 640w, https://ik.imagekit.io/demo/sample.jpg?tr=w-750,c-at_max 750w, https://ik.imagekit.io/demo/sample.jpg?tr=w-828,c-at_max 828w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1080,c-at_max 1080w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1200,c-at_max 1200w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1920,c-at_max 1920w, https://ik.imagekit.io/demo/sample.jpg?tr=w-2048,c-at_max 2048w, https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max 3840w" ,
92
87
sizes : "50vw" ,
93
88
width : 600
94
89
} ) ;
@@ -106,9 +101,8 @@ describe.only('getResponsiveImageAttributes – smoke run‑through', () => {
106
101
} ) ;
107
102
// Multiple caller transformations should be combined appropriately.
108
103
expect ( out ) . to . deep . equal ( {
109
- src : "https://ik.imagekit.io/demo/sample.jpg?tr=height-300,aiRemoveBackground-true,w-828,c-at_max" ,
110
- srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=height-300,aiRemoveBackground-true,w-640,c-at_max 1x, https://ik.imagekit.io/demo/sample.jpg?tr=height-300,aiRemoveBackground-true,w-828,c-at_max 2x" ,
111
- sizes : undefined ,
104
+ src : "https://ik.imagekit.io/demo/sample.jpg?tr=h-300:e-bgremove:w-1080,c-at_max" ,
105
+ srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=h-300:e-bgremove:w-640,c-at_max 1x, https://ik.imagekit.io/demo/sample.jpg?tr=h-300:e-bgremove:w-1080,c-at_max 2x" ,
112
106
width : 450
113
107
} ) ;
114
108
} ) ;
@@ -122,9 +116,8 @@ describe.only('getResponsiveImageAttributes – smoke run‑through', () => {
122
116
// When specified with a sizes attribute that prunes breakpoints, the output should reflect the pruned values.
123
117
expect ( out ) . to . deep . equal ( {
124
118
src : "https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max" ,
125
- srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-640,c-at_max 640w, https://ik.imagekit.io/demo/sample.jpg?tr=w-750,c-at_max 750w, https://ik.imagekit.io/demo/sample.jpg?tr=w-828,c-at_max 828w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1080,c-at_max 1080w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1200,c-at_max 1200w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1920,c-at_max 1920w, https://ik.imagekit.io/demo/sample.jpg?tr=w-2048,c-at_max 2048w, https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max 3840w" ,
126
- sizes : "(min-width: 800px) 33vw, 100vw" ,
127
- width : undefined
119
+ srcSet : "https://ik.imagekit.io/demo/sample.jpg?tr=w-256,c-at_max 256w, https://ik.imagekit.io/demo/sample.jpg?tr=w-384,c-at_max 384w, https://ik.imagekit.io/demo/sample.jpg?tr=w-640,c-at_max 640w, https://ik.imagekit.io/demo/sample.jpg?tr=w-750,c-at_max 750w, https://ik.imagekit.io/demo/sample.jpg?tr=w-828,c-at_max 828w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1080,c-at_max 1080w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1200,c-at_max 1200w, https://ik.imagekit.io/demo/sample.jpg?tr=w-1920,c-at_max 1920w, https://ik.imagekit.io/demo/sample.jpg?tr=w-2048,c-at_max 2048w, https://ik.imagekit.io/demo/sample.jpg?tr=w-3840,c-at_max 3840w" ,
120
+ sizes : "(min-width: 800px) 33vw, 100vw"
128
121
} ) ;
129
122
} ) ;
130
123
} ) ;
0 commit comments