@@ -23,7 +23,7 @@ describe("Colors", () => {
2323 } ;
2424
2525 const c1 = Skia . Color ( "cyan" ) ;
26- const c2 = Skia . Color ( [ 0 , 1 , 1 , 1 ] ) ;
26+ const c2 = Skia . Color ( [ 0 , 255 , 255 , 255 ] ) ;
2727 const c3 = Skia . Color ( 0xff00ffff ) ;
2828 const c4 = Skia . Color ( Float32Array . of ( 0 , 1 , 1 , 1 ) ) ;
2929
@@ -35,4 +35,37 @@ describe("Colors", () => {
3535 } ) ;
3636 expect ( result ) . toBe ( true ) ;
3737 } ) ;
38+ it ( "should render the same color regardless of constructor input types" , async ( ) => {
39+ // given (different inputs representing the same color
40+ const colors = [
41+ "red" ,
42+ Float32Array . of ( 1 , 0 , 0 , 1 ) ,
43+ 0xff0000ff ,
44+ [ 255 , 0 , 0 , 255 ] ,
45+ ] ;
46+
47+ // when (for each input we draw a colored canvas and encode it to bytes)
48+ const buffers = await Promise . all (
49+ colors . map ( ( color ) =>
50+ surface
51+ . drawOffscreen (
52+ ( Skia , canvas , ctx ) => {
53+ canvas . drawColor ( Skia . Color ( ctx . color ) ) ;
54+ } ,
55+ { color }
56+ )
57+ . then ( ( image ) => image . encodeToBytes ( ) )
58+ )
59+ ) ;
60+
61+ // then (expect the encoded bytes are equal)
62+ for ( let i = 1 ; i < buffers . length ; i ++ ) {
63+ const prev = buffers [ i - 1 ] ;
64+ const curr = buffers [ i ] ;
65+ expect ( prev . length ) . toBe ( curr . length ) ;
66+ for ( let j = 0 ; j < prev . length ; j ++ ) {
67+ expect ( prev [ j ] ) . toBe ( curr [ j ] ) ;
68+ }
69+ }
70+ } ) ;
3871} ) ;
0 commit comments