Skip to content

Commit

Permalink
refactor: replace got with node-fetch on server.test.js (#6231)
Browse files Browse the repository at this point in the history
replace got with node-fetch

related to #5695

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
hereje and kodiakhq[bot] authored Jan 11, 2024
1 parent 134f4ca commit 7ac6ae8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tests/unit/lib/functions/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tmpdir } from 'os'
import { join } from 'path'

import express from 'express'
import got from 'got'
import fetch from 'node-fetch'
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'

import { FunctionsRegistry } from '../../../../src/lib/functions/registry.js'
Expand Down Expand Up @@ -52,27 +52,27 @@ describe('createHandler', () => {
)

test('should get the url as the `rawUrl` inside the function', async () => {
const response = await got.get(new URL('/hello', serverAddress))
const response = await fetch(new URL('/hello', serverAddress))

expect(response.statusCode).toBe(200)
expect(response.body).toMatch(/^http:\/\/localhost:\d+?\/hello$/)
expect(response.status).toBe(200)
expect(await response.text()).toMatch(/^http:\/\/localhost:\d+?\/hello$/)
})

test('should get the original url as the `rawUrl` when the header was provided by the proxy', async () => {
const response = await got.get(new URL('/hello', serverAddress), {
const response = await fetch(new URL('/hello', serverAddress), {
headers: { 'x-netlify-original-pathname': '/orig' },
})

expect(response.statusCode).toBe(200)
expect(response.body).toMatch(/^http:\/\/localhost:\d+?\/orig$/)
expect(response.status).toBe(200)
expect(await response.text()).toMatch(/^http:\/\/localhost:\d+?\/orig$/)
})

test('should check if query params are passed to the `rawUrl` when redirected', async () => {
const response = await got.get(new URL('/hello?jam=stack', serverAddress), {
const response = await fetch(new URL('/hello?jam=stack', serverAddress), {
headers: { 'x-netlify-original-pathname': '/orig' },
})

expect(response.statusCode).toBe(200)
expect(response.body).toMatch(/^http:\/\/localhost:\d+?\/orig\?jam=stack$/)
expect(response.status).toBe(200)
expect(await response.text()).toMatch(/^http:\/\/localhost:\d+?\/orig\?jam=stack$/)
})
})

1 comment on commit 7ac6ae8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,295
  • Package size: 309 MB
  • Number of ts-expect-error directives: 1,182

Please sign in to comment.