Skip to content

Commit

Permalink
add test for resolveRemoteMount
Browse files Browse the repository at this point in the history
  • Loading branch information
UnCor3 committed Jul 28, 2024
1 parent 49c5b3f commit 46bc36d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/port/remote.browser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Worker } from 'node:worker_threads';
import { Port } from '../../src/backends/port/fs.js';
import { configureSingle, fs } from '../../src/index.js';

const dir = dirname(fileURLToPath(import.meta.url));

let port: Worker;

try {
port = new Worker(dir + '/worker.browser.js');
} catch (e) {
/* nothing */
}

describe('Remote FS with resolveRemoteMount', () => {
const content = 'FS is in a port';

test('Build exists for worker', () => {
expect(port).toBeDefined();
});

(port ? test : test.skip)('Configuration', async () => {
await configureSingle({ backend: Port, port, timeout: 300 });
});

(port ? test : test.skip)('Write', async () => {
await fs.promises.writeFile('/test', content);
});

(port ? test : test.skip)('Read', async () => {
expect(await fs.promises.readFile('/test', 'utf8')).toBe(content);
});

(port ? test : test.skip)('Cleanup', async () => {
await port.terminate();
port.unref();
});
});
5 changes: 5 additions & 0 deletions tests/port/worker.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { parentPort } from 'node:worker_threads';
import { resolveRemoteMount } from '../../dist/backends/port/fs.js';
import { InMemory } from '../../dist/backends/memory.js';

await resolveRemoteMount(parentPort, { backend: InMemory });

0 comments on commit 46bc36d

Please sign in to comment.