LongYinan 583a2ba5c8
chore(triples): update target list (#2879)
* chore(triples): update target list

* convert compat tests to esm

* Fix node 20 test
2025-08-15 18:31:56 +08:00

33 lines
927 B
TypeScript

import ava from 'ava'
import { napiVersion } from '../napi-version'
// @ts-expect-error
import bindings from '../../index.node'
const test = napiVersion >= 7 ? ava : ava.skip
test('should be able to detach ArrayBuffer', (t) => {
const buf = Buffer.from('hello world')
const ab = buf.buffer.slice(0, buf.length)
try {
bindings.testDetachArrayBuffer(ab)
t.is(ab.byteLength, 0)
} catch (e) {
t.is((e as any).code, 'DetachableArraybufferExpected')
}
})
test('is detached arraybuffer should work fine', (t) => {
const buf = Buffer.from('hello world')
const ab = buf.buffer.slice(0, buf.length)
try {
bindings.testDetachArrayBuffer(ab)
const nonDetachedArrayBuffer = new ArrayBuffer(10)
t.true(bindings.testIsDetachedArrayBuffer(ab))
t.false(bindings.testIsDetachedArrayBuffer(nonDetachedArrayBuffer))
} catch (e) {
t.is((e as any).code, 'DetachableArraybufferExpected')
}
})