Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace got with node-fetch on server.test.js #6231

Merged
merged 16 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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$/)
})
})
Loading