@@ -17,7 +17,7 @@ describe('web worker transfer', () => {
17
17
constructor ( n ) {
18
18
this . n = n ;
19
19
this . buffer = new ArrayBuffer ( 100 ) ;
20
- this . blob = new Blob ( ) ;
20
+ this . blob = new Blob ( [ 'Test' ] , { type : 'application/text' } ) ;
21
21
this . squared ( ) ;
22
22
}
23
23
@@ -34,15 +34,20 @@ describe('web worker transfer', () => {
34
34
35
35
const serializableMock = new SerializableMock ( 10 ) ;
36
36
const transferables = [ ] ;
37
- const deserialized = deserialize ( serialize ( serializableMock , transferables ) ) as SerializableMock ;
38
- expect ( deserialize ( serialize ( serializableMock , transferables ) ) instanceof SerializableMock ) . toBeTruthy ( ) ;
39
-
37
+ const deserialized = mockTransfer ( serializableMock , transferables ) as SerializableMock ;
38
+ expect ( deserialized instanceof SerializableMock ) . toBeTruthy ( ) ;
39
+ expect ( transferables [ 0 ] === serializableMock . buffer ) . toBeTruthy ( ) ;
40
+ expect ( serializableMock . buffer . byteLength ) . toBe ( 0 ) ;
41
+ expect ( deserialized . buffer . byteLength ) . toBe ( 100 ) ;
40
42
expect ( serializableMock !== deserialized ) . toBeTruthy ( ) ;
41
43
expect ( deserialized . constructor === SerializableMock ) . toBeTruthy ( ) ;
42
44
expect ( deserialized . n === 10 ) . toBeTruthy ( ) ;
43
- expect ( deserialized . buffer === serializableMock . buffer ) . toBeTruthy ( ) ;
44
- expect ( deserialized . blob === serializableMock . blob ) . toBeTruthy ( ) ;
45
- expect ( transferables [ 0 ] === serializableMock . buffer ) . toBeTruthy ( ) ;
45
+ expect ( serializableMock . blob . size ) . toBe ( 4 ) ;
46
+ // seems to be a problem with jsdom + node. it works in
47
+ // node and it works in browsers
48
+ // expect(structuredClone(new Blob())).toBeInstanceOf(Blob);
49
+ // expect(deserialized.blob.size).toBe(4);
50
+
46
51
expect ( deserialized . _cached === undefined ) . toBeTruthy ( ) ;
47
52
expect ( deserialized . squared ( ) === 100 ) . toBeTruthy ( ) ;
48
53
} ) ;
@@ -52,7 +57,7 @@ describe('web worker transfer', () => {
52
57
expect ( ! Klass . name ) . toBeTruthy ( ) ;
53
58
register ( 'Anon' , Klass ) ;
54
59
const x = new Klass ( ) ;
55
- const deserialized = deserialize ( serialize ( x ) ) ;
60
+ const deserialized = mockTransfer ( x ) ;
56
61
expect ( deserialized instanceof Klass ) . toBeTruthy ( ) ;
57
62
} ) ;
58
63
@@ -81,8 +86,8 @@ describe('web worker transfer', () => {
81
86
const customSerialization = new CustomSerialization ( 'a' ) ;
82
87
expect ( ! customSerialization . _deserialized ) . toBeTruthy ( ) ;
83
88
84
- const deserialized = deserialize ( serialize ( customSerialization ) ) as CustomSerialization ;
85
- expect ( deserialize ( serialize ( customSerialization ) ) instanceof CustomSerialization ) . toBeTruthy ( ) ;
89
+ const deserialized = mockTransfer ( customSerialization ) as CustomSerialization ;
90
+ expect ( mockTransfer ( customSerialization ) instanceof CustomSerialization ) . toBeTruthy ( ) ;
86
91
expect ( deserialized . id ) . toBe ( customSerialization . id ) ;
87
92
expect ( deserialized . _deserialized ) . toBeTruthy ( ) ;
88
93
} ) ;
0 commit comments