@@ -14,13 +14,38 @@ describe("Brotli-wasm", () => {
14
14
expect ( Buffer . from ( result ) . toString ( 'base64' ) ) . to . equal ( 'Gw4A+KWpyubolCCjVAjmxJ4D' ) ;
15
15
} ) ;
16
16
17
+ it ( "can compress data with a different quality setting" , ( ) => {
18
+ const input = Buffer . from ( "Test input data" ) ;
19
+ const result = brotli . compress ( input , { quality : 1 } ) ;
20
+ expect ( Buffer . from ( result ) . toString ( 'base64' ) ) . to . equal ( 'CweAVGVzdCBpbnB1dCBkYXRhAw==' ) ;
21
+ } ) ;
22
+
17
23
it ( "can decompress data" , ( ) => {
18
24
// Generated with: echo -n '$CONTENT' | brotli --stdout - | base64
19
25
const input = Buffer . from ( 'GxoAABypU587dC0k9ianQOgqjS32iUTcCA==' , 'base64' ) ;
20
26
const result = brotli . decompress ( input ) ;
21
27
expect ( Buffer . from ( result ) . toString ( 'utf8' ) ) . to . equal ( 'Brotli brotli brotli brotli' ) ;
22
28
} ) ;
23
29
30
+ it ( "cleanly fails when options is something other than an object" , ( ) => {
31
+ const input = Buffer . from ( "Test input data" ) ;
32
+ expect ( ( ) =>
33
+ brotli . compress ( input , "this should not be a string" as any )
34
+ ) . to . throw ( 'Options is not an object' ) ;
35
+ } ) ;
36
+
37
+ it ( "does not fail when options contain unknown properties" , ( ) => {
38
+ const input = Buffer . from ( "Test input data" ) ;
39
+ const result = brotli . compress ( input , { someRandomKey : 1 , quality : 5 } as any ) ;
40
+ expect ( Buffer . from ( result ) . toString ( 'base64' ) ) . to . equal ( 'CweAVGVzdCBpbnB1dCBkYXRhAw==' ) ;
41
+ } ) ;
42
+
43
+ it ( "does not fail when compressing with an illegal quality value" , ( ) => {
44
+ const input = Buffer . from ( "Test input data" ) ;
45
+ const result = brotli . compress ( input , { quality : 12 } ) ;
46
+ expect ( Buffer . from ( result ) . toString ( 'base64' ) ) . to . equal ( 'Gw4A+KWpyubolCCjVAjmxJ4D' ) ;
47
+ } ) ;
48
+
24
49
it ( "cleanly fails when decompressing garbage" , ( ) => {
25
50
const input = Buffer . from ( "This is not brotli data, it's just a string" ) ;
26
51
expect ( ( ) =>
@@ -35,4 +60,12 @@ describe("Brotli-wasm", () => {
35
60
) . toString ( 'utf8' ) ;
36
61
expect ( result ) . to . equal ( input ) ;
37
62
} ) ;
38
- } ) ;
63
+
64
+ it ( "can compress & decompress back to the original result with a different quality setting" , ( ) => {
65
+ const input = "Some thrilling text I urgently need to compress" ;
66
+ const result = Buffer . from (
67
+ brotli . decompress ( brotli . compress ( Buffer . from ( input ) , { quality : 3 } ) )
68
+ ) . toString ( 'utf8' ) ;
69
+ expect ( result ) . to . equal ( input ) ;
70
+ } ) ;
71
+ } ) ;
0 commit comments