44// Tests for ImageDecoder configuration options per W3C spec.
55
66import * as assert from 'node:assert/strict' ;
7- import { describe , it } from 'node:test' ;
7+ import { before , describe , it } from 'node:test' ;
88import { ImageDecoder } from '../../lib' ;
99
10+ // Check if PNG decoder is available (may be missing in LGPL FFmpeg builds)
11+ let pngSupported = false ;
12+ before ( async ( ) => {
13+ pngSupported = await ImageDecoder . isTypeSupported ( 'image/png' ) ;
14+ if ( ! pngSupported ) {
15+ console . log ( 'Note: PNG decoder not available, skipping PNG-specific tests' ) ;
16+ }
17+ } ) ;
18+
1019describe ( 'ImageDecoder Configuration Options' , ( ) => {
1120 // Helper to create minimal valid PNG
1221 function createMinimalPNG ( ) : Buffer {
@@ -21,6 +30,8 @@ describe('ImageDecoder Configuration Options', () => {
2130
2231 describe ( 'colorSpaceConversion' , ( ) => {
2332 it ( 'accepts "default" value' , ( ) => {
33+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
34+
2435 const data = createMinimalPNG ( ) ;
2536 const decoder = new ImageDecoder ( {
2637 type : 'image/png' ,
@@ -32,6 +43,8 @@ describe('ImageDecoder Configuration Options', () => {
3243 } ) ;
3344
3445 it ( 'accepts "none" value' , ( ) => {
46+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
47+
3548 const data = createMinimalPNG ( ) ;
3649 const decoder = new ImageDecoder ( {
3750 type : 'image/png' ,
@@ -50,6 +63,8 @@ describe('ImageDecoder Configuration Options', () => {
5063 // Both must be present together or neither should be present.
5164
5265 it ( 'accepts desiredWidth/desiredHeight options together' , async ( ) => {
66+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
67+
5368 const data = createMinimalPNG ( ) ;
5469 const decoder = new ImageDecoder ( {
5570 type : 'image/png' ,
@@ -63,6 +78,8 @@ describe('ImageDecoder Configuration Options', () => {
6378 } ) ;
6479
6580 it ( 'accepts neither desiredWidth nor desiredHeight' , async ( ) => {
81+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
82+
6683 const data = createMinimalPNG ( ) ;
6784 const decoder = new ImageDecoder ( {
6885 type : 'image/png' ,
@@ -76,6 +93,8 @@ describe('ImageDecoder Configuration Options', () => {
7693
7794 // W3C Spec 10.3 step 4: desiredWidth without desiredHeight is INVALID
7895 it ( 'throws TypeError for desiredWidth without desiredHeight (spec 10.3 step 4)' , ( ) => {
96+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
97+
7998 const data = createMinimalPNG ( ) ;
8099 assert . throws (
81100 ( ) =>
@@ -91,6 +110,8 @@ describe('ImageDecoder Configuration Options', () => {
91110
92111 // W3C Spec 10.3 step 5: desiredHeight without desiredWidth is INVALID
93112 it ( 'throws TypeError for desiredHeight without desiredWidth (spec 10.3 step 5)' , ( ) => {
113+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
114+
94115 const data = createMinimalPNG ( ) ;
95116 assert . throws (
96117 ( ) =>
@@ -107,6 +128,8 @@ describe('ImageDecoder Configuration Options', () => {
107128
108129 describe ( 'preferAnimation' , ( ) => {
109130 it ( 'accepts preferAnimation option' , ( ) => {
131+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
132+
110133 const data = createMinimalPNG ( ) ;
111134 const decoder = new ImageDecoder ( {
112135 type : 'image/png' ,
@@ -118,6 +141,8 @@ describe('ImageDecoder Configuration Options', () => {
118141 } ) ;
119142
120143 it ( 'accepts preferAnimation: false' , ( ) => {
144+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
145+
121146 const data = createMinimalPNG ( ) ;
122147 const decoder = new ImageDecoder ( {
123148 type : 'image/png' ,
@@ -131,6 +156,8 @@ describe('ImageDecoder Configuration Options', () => {
131156
132157 describe ( 'transfer' , ( ) => {
133158 it ( 'accepts transfer option with empty array' , ( ) => {
159+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
160+
134161 const data = createMinimalPNG ( ) ;
135162 const decoder = new ImageDecoder ( {
136163 type : 'image/png' ,
@@ -142,12 +169,14 @@ describe('ImageDecoder Configuration Options', () => {
142169 } ) ;
143170
144171 it ( 'detaches ArrayBuffers specified in transfer' , ( ) => {
172+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
173+
145174 // Create a copy of the data in an ArrayBuffer
146175 const pngData = createMinimalPNG ( ) ;
147176 const arrayBuffer = pngData . buffer . slice (
148177 pngData . byteOffset ,
149178 pngData . byteOffset + pngData . byteLength ,
150- ) ;
179+ ) as ArrayBuffer ;
151180
152181 const decoder = new ImageDecoder ( {
153182 type : 'image/png' ,
@@ -164,6 +193,8 @@ describe('ImageDecoder Configuration Options', () => {
164193
165194 describe ( 'combined options' , ( ) => {
166195 it ( 'accepts all options together' , ( ) => {
196+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
197+
167198 const data = createMinimalPNG ( ) ;
168199 const decoder = new ImageDecoder ( {
169200 type : 'image/png' ,
@@ -183,6 +214,8 @@ describe('ImageDecoder Configuration Options', () => {
183214
184215 describe ( 'premultiplyAlpha option' , ( ) => {
185216 it ( 'accepts premultiplyAlpha: premultiply' , ( ) => {
217+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
218+
186219 const data = createMinimalPNG ( ) ;
187220
188221 const decoder = new ImageDecoder ( {
@@ -198,6 +231,8 @@ describe('ImageDecoder Configuration Options', () => {
198231 } ) ;
199232
200233 it ( 'accepts premultiplyAlpha: none' , ( ) => {
234+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
235+
201236 const data = createMinimalPNG ( ) ;
202237
203238 const decoder = new ImageDecoder ( {
@@ -211,6 +246,8 @@ describe('ImageDecoder Configuration Options', () => {
211246 } ) ;
212247
213248 it ( 'accepts premultiplyAlpha: default' , ( ) => {
249+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
250+
214251 const data = createMinimalPNG ( ) ;
215252
216253 const decoder = new ImageDecoder ( {
@@ -224,6 +261,8 @@ describe('ImageDecoder Configuration Options', () => {
224261 } ) ;
225262
226263 it ( 'throws TypeError for invalid value' , ( ) => {
264+ if ( ! pngSupported ) return ; // Skip if PNG decoder not available
265+
227266 const data = createMinimalPNG ( ) ;
228267
229268 assert . throws (
0 commit comments