@@ -23,7 +23,7 @@ describe("Colors", () => {
23
23
} ;
24
24
25
25
const c1 = Skia . Color ( "cyan" ) ;
26
- const c2 = Skia . Color ( [ 0 , 1 , 1 , 1 ] ) ;
26
+ const c2 = Skia . Color ( [ 0 , 255 , 255 , 255 ] ) ;
27
27
const c3 = Skia . Color ( 0xff00ffff ) ;
28
28
const c4 = Skia . Color ( Float32Array . of ( 0 , 1 , 1 , 1 ) ) ;
29
29
@@ -35,4 +35,37 @@ describe("Colors", () => {
35
35
} ) ;
36
36
expect ( result ) . toBe ( true ) ;
37
37
} ) ;
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
+ } ) ;
38
71
} ) ;
0 commit comments