Skip to content

Commit

Permalink
fixup! review suggestion testTransfer
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 13, 2025
1 parent 16fbf27 commit 05e35aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
20 changes: 8 additions & 12 deletions packages/immutable-arraybuffer/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,7 @@ test('TypedArray on Immutable ArrayBuffer ponyfill limitations', t => {
t.is(ta3.byteLength, 0);
});

test('Standard buf.transfer(newLength) behavior baseline', t => {
if (!('transfer' in ArrayBuffer.prototype)) {
// Will happen on Node <= 20
const msg =
'skip when platform does not yet implement ArrayBuffer.prototype.transfer';
t.pass(msg);
t.log(msg);
return;
}
// Will happen on Node >= 22
t.log('ArrayBuffer.prototype.transfer exists');
const testTransfer = t => {
const ta12 = new Uint8Array([3, 4, 5]);
const ab12 = ta12.buffer;
t.is(ab12.byteLength, 3);
Expand All @@ -158,7 +148,13 @@ test('Standard buf.transfer(newLength) behavior baseline', t => {
t.is(ab13.byteLength, 0);
const ta3 = new Uint8Array(ab3);
t.deepEqual([...ta3], [3, 4]);
});
};

{
// `transfer` is absent in Node <= 20. Present in Node >= 22
const maybeTest = 'transfer' in ArrayBuffer.prototype ? test : test.skip;
maybeTest('Standard buf.transfer(newLength) behavior baseline', testTransfer);
}

test('Analogous transferBufferToImmutable(buf, newLength) ponyfill', t => {
const ta12 = new Uint8Array([3, 4, 5]);
Expand Down
20 changes: 8 additions & 12 deletions packages/immutable-arraybuffer/test/shim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,7 @@ test('TypedArray on Immutable ArrayBuffer shim limitations', t => {
t.is(ta3.byteLength, 0);
});

test('Standard buf.transfer(newLength) behavior baseline', t => {
if (!('transfer' in ArrayBuffer.prototype)) {
// Will happen on Node <= 20
const msg =
'skip when platform does not yet implement ArrayBuffer.prototype.transfer';
t.pass(msg);
t.log(msg);
return;
}
// Will happen on Node >= 22
t.log('ArrayBuffer.prototype.transfer exists');
const testTransfer = t => {
const ta12 = new Uint8Array([3, 4, 5]);
const ab12 = ta12.buffer;
t.is(ab12.byteLength, 3);
Expand All @@ -154,7 +144,13 @@ test('Standard buf.transfer(newLength) behavior baseline', t => {
t.is(ab13.byteLength, 0);
const ta3 = new Uint8Array(ab3);
t.deepEqual([...ta3], [3, 4]);
});
};

{
// `transfer` is absent in Node <= 20. Present in Node >= 22
const maybeTest = 'transfer' in ArrayBuffer.prototype ? test : test.skip;
maybeTest('Standard buf.transfer(newLength) behavior baseline', testTransfer);
}

test('Analogous buf.transferToImmutable(newLength) shim', t => {
const ta12 = new Uint8Array([3, 4, 5]);
Expand Down

0 comments on commit 05e35aa

Please sign in to comment.