Skip to content

Commit 7777402

Browse files
committed
Turn off SharedArrayBuffer-based tests when SharedArrayBuffer is not available
1 parent fce1640 commit 7777402

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

packages/encoding/src/uint8array.spec.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { fixUint8Array } from "./uint8array";
22

3+
// Turned off in Chrome without secure context
4+
const hasSharedArrayBuffer = typeof SharedArrayBuffer !== "undefined";
5+
36
describe("fixUint8Array", () => {
47
it("works for Uint8Array<ArrayBuffer>", () => {
58
const input: Uint8Array<ArrayBuffer> = Uint8Array.of(1, 2, 255);
@@ -20,23 +23,26 @@ describe("fixUint8Array", () => {
2023
expect(fixed.buffer).toBe(buffer); // no copy must be performed in this case
2124
});
2225

23-
it("works for Uint8Array<SharedArrayBuffer>", () => {
26+
(hasSharedArrayBuffer ? it : xit)("works for Uint8Array<SharedArrayBuffer>", () => {
2427
const sharedBuffer = new SharedArrayBuffer(8);
2528
const input: Uint8Array<SharedArrayBuffer> = new Uint8Array(sharedBuffer);
2629
const fixed = fixUint8Array(input);
2730
expect(fixed).toEqual(input);
2831
expect(fixed.buffer).toBeInstanceOf(ArrayBuffer);
2932
});
3033

31-
it("works for Uint8Array<SharedArrayBuffer> where data is not using all of the buffer", () => {
32-
const sharedBuffer = new SharedArrayBuffer(8);
33-
const input: Uint8Array<SharedArrayBuffer> = new Uint8Array(sharedBuffer, 0, 3);
34-
input[0] = 0xaa;
35-
input[1] = 0xbb;
36-
input[2] = 0xcc;
37-
const fixed = fixUint8Array(input);
38-
expect(fixed.buffer).toBeInstanceOf(ArrayBuffer);
39-
expect(fixed.length).toEqual(3);
40-
expect(fixed).toEqual(new Uint8Array([0xaa, 0xbb, 0xcc]));
41-
});
34+
(hasSharedArrayBuffer ? it : xit)(
35+
"works for Uint8Array<SharedArrayBuffer> where data is not using all of the buffer",
36+
() => {
37+
const sharedBuffer = new SharedArrayBuffer(8);
38+
const input: Uint8Array<SharedArrayBuffer> = new Uint8Array(sharedBuffer, 0, 3);
39+
input[0] = 0xaa;
40+
input[1] = 0xbb;
41+
input[2] = 0xcc;
42+
const fixed = fixUint8Array(input);
43+
expect(fixed.buffer).toBeInstanceOf(ArrayBuffer);
44+
expect(fixed.length).toEqual(3);
45+
expect(fixed).toEqual(new Uint8Array([0xaa, 0xbb, 0xcc]));
46+
},
47+
);
4248
});

0 commit comments

Comments
 (0)