mtcute/packages/wasm/tests/allocator.test.ts
2023-11-09 00:20:43 +03:00

21 lines
523 B
TypeScript

import { beforeAll, describe, expect, it } from 'vitest'
import { __getWasm, initAsync } from '../src/index.js'
beforeAll(async () => {
await initAsync()
})
describe('allocator', () => {
it('should not leak memory', () => {
const wasm = __getWasm()
const memUsage = wasm.memory.buffer.byteLength
for (let i = 0; i < 1024; i++) {
const ptr = wasm.__malloc(1024)
wasm.__free(ptr)
}
expect(wasm.memory.buffer.byteLength).toEqual(memUsage)
})
})