From c549cba5162826358415a772942aee781868d062 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Tue, 19 Dec 2023 16:53:58 +0100 Subject: [PATCH] fix: tests --- packages/snippetz/src/snippetz.test.ts | 8 ++++++-- packages/snippetz/src/snippetz.ts | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/snippetz/src/snippetz.test.ts b/packages/snippetz/src/snippetz.test.ts index 231928a..67a63b1 100644 --- a/packages/snippetz/src/snippetz.test.ts +++ b/packages/snippetz/src/snippetz.test.ts @@ -12,12 +12,12 @@ describe('snippetz', async () => { const { statusCode, body } = await request('https://example.com')`) }) - it('loads undici by default', async () => { + it('loads some clients by default', async () => { const targets = snippetz().targets() expect(targets).toStrictEqual(['node']) const clients = snippetz().clients() - expect(clients).toStrictEqual(['undici']) + expect(clients).toStrictEqual(['undici', 'fetch']) }) }) @@ -30,6 +30,10 @@ describe('plugins', async () => { target: 'node', client: 'undici', }, + { + target: 'node', + client: 'fetch', + }, ]) }) }) diff --git a/packages/snippetz/src/snippetz.ts b/packages/snippetz/src/snippetz.ts index 185c644..0c2d446 100644 --- a/packages/snippetz/src/snippetz.ts +++ b/packages/snippetz/src/snippetz.ts @@ -6,18 +6,24 @@ export function snippetz() { const plugins = [undici, fetch] return { - get(target: TargetId, client: ClientId, request: Request) { + get(target: TargetId, client: ClientId, request: Partial) { const plugin = this.findPlugin(target, client) if (plugin) { return plugin(request) } }, - print(target: TargetId, client: ClientId, request: Request) { + print(target: TargetId, client: ClientId, request: Partial) { return this.get(target, client, request)?.code }, targets() { - return plugins.map((plugin) => plugin().target) + return ( + plugins + // all targets + .map((plugin) => plugin().target) + // unique values + .filter((value, index, self) => self.indexOf(value) === index) + ) }, clients() { return plugins.map((plugin) => plugin().client)