Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/core/src/utils/__fixtures__/dummy.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a wasm fixture.
19 changes: 19 additions & 0 deletions packages/core/src/utils/fileUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import fs from 'node:fs';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
import os from 'node:os';
import { fileURLToPath } from 'node:url';
// eslint-disable-next-line import/no-internal-modules
import mime from 'mime/lite';

Expand All @@ -30,6 +31,7 @@ import {
detectBOM,
readFileWithEncoding,
fileExists,
readWasmBinaryFromDisk,
} from './fileUtils.js';
import { StandardFileSystemService } from '../services/fileSystemService.js';

Expand Down Expand Up @@ -77,6 +79,23 @@ describe('fileUtils', () => {
vi.restoreAllMocks(); // Restore any spies
});

describe('readWasmBinaryFromDisk', () => {
it('loads a WASM binary from disk as a Uint8Array', async () => {
const wasmFixtureUrl = new URL(
'./__fixtures__/dummy.wasm',
import.meta.url,
);
const wasmFixturePath = fileURLToPath(wasmFixtureUrl);
const result = await readWasmBinaryFromDisk(wasmFixturePath);
const expectedBytes = new Uint8Array(
await fsPromises.readFile(wasmFixturePath),
);

expect(result).toBeInstanceOf(Uint8Array);
expect(result).toStrictEqual(expectedBytes);
});
});

describe('isWithinRoot', () => {
const root = path.resolve('/project/root');

Expand Down