Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ describe('Index Module', () => {
expect(typeof globalThis.WebAssembly?.instantiateStreaming).toBe(
'function'
);

// Call the polyfilled function and ensure it delegates to WebAssembly.instantiate
const arrayBufferMock = vi.fn().mockResolvedValue(new ArrayBuffer(8));
const response = Promise.resolve({
arrayBuffer: arrayBufferMock
} as unknown as Response);

const instantiateSpy = vi
.spyOn(globalThis.WebAssembly, 'instantiate')
.mockResolvedValue({
exports: {}
});

await globalThis.WebAssembly.instantiateStreaming?.(
response as any,
{ imports: true } as any
);

expect(arrayBufferMock).toHaveBeenCalledTimes(1);
expect(instantiateSpy).toHaveBeenCalledTimes(1);
});

it('should use existing WebAssembly.instantiateStreaming when available', async () => {
Expand Down
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require('./wasm_exec');

import LNC from './lnc';
import { WasmManager } from './wasmManager';

// polyfill
if (!WebAssembly.instantiateStreaming) {
Expand All @@ -14,3 +15,4 @@ if (!WebAssembly.instantiateStreaming) {
export type { LncConfig, CredentialStore } from './types/lnc';
export * from '@lightninglabs/lnc-core';
export default LNC;
export { WasmManager };
Loading