-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathfilesystem.test.ts
49 lines (44 loc) · 1.77 KB
/
filesystem.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
import type { Server } from 'bun';
import { createFileSystem } from './filesystem';
async function serveFixture(fixture: string) {
return new Response(await Bun.file(new URL(`./fixtures/${fixture}`, import.meta.url)).bytes(), {
headers: { 'Content-Type': 'application/yaml' },
});
}
describe('#createFileSystem', () => {
let server: Server;
beforeEach(async () => {
server = Bun.serve({
static: {
'/root/spec.yaml': await serveFixture('/remote-ref/root/spec.yaml'),
'/root/user.yaml': await serveFixture('/remote-ref/root/user.yaml'),
'/root/pet.yaml': await serveFixture('/remote-ref/root/pet.yaml'),
'/root/invalid.yaml': await serveFixture('/remote-ref/root/invalid.txt'),
'/tag.yaml': await serveFixture('/remote-ref/tag.yaml'),
},
fetch() {
return new Response('<404>', {
status: 404,
});
},
port: 3020,
});
});
afterEach(async () => {
await server.stop();
});
it('creates a filesystem by resolving URLs', async () => {
const url = new URL('/root/spec.yaml', server.url).href;
const filesystem = await createFileSystem({
value: url,
rootURL: url,
});
expect(filesystem).toHaveLength(4);
expect(filesystem[0]?.isEntrypoint).toBe(true);
expect(filesystem[1]?.isEntrypoint).toBe(false);
expect(filesystem[1]?.filename).toBe('user.yaml');
expect(filesystem[2]?.filename).toBe('../tag.yaml');
expect(filesystem[3]?.filename).toBe('http://localhost:3020/root/pet.yaml');
});
});