Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hanspagel committed Dec 19, 2023
1 parent fbf21d2 commit c549cba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions packages/snippetz/src/snippetz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
})
})

Expand All @@ -30,6 +30,10 @@ describe('plugins', async () => {
target: 'node',
client: 'undici',
},
{
target: 'node',
client: 'fetch',
},
])
})
})
Expand Down
12 changes: 9 additions & 3 deletions packages/snippetz/src/snippetz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Request>) {
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<Request>) {
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)
Expand Down

0 comments on commit c549cba

Please sign in to comment.