Skip to content

Commit

Permalink
refactor: replace got with node-fetch on functions-invoke.test.ts (#6232
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 Dec 13, 2023
1 parent e3f654e commit 8e71e42
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import got from 'got'
import fetch from 'node-fetch'
import { describe, expect, test } from 'vitest'

import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
Expand Down Expand Up @@ -39,26 +39,25 @@ describe('functions:invoke command', () => {
)

test.concurrent<FixtureTestContext>('should serve helpful tips and tricks', async ({ devServer, fixture }) => {
const plainTextResponse = await got(`http://localhost:${devServer.port}/.netlify/functions/scheduled-isc-body`, {
throwHttpErrors: false,
retry: { limit: 0 },
})
const textResponse = await fetch(`http://localhost:${devServer.port}/.netlify/functions/scheduled-isc-body`, {})

const bodyPlainTextResponse = await textResponse.text()

const youReturnedBodyRegex = /.*Your function returned `body`. Is this an accident\?.*/
expect(plainTextResponse.body).toMatch(youReturnedBodyRegex)
expect(plainTextResponse.body).toMatch(/.*You performed an HTTP request.*/)
expect(plainTextResponse.statusCode).toBe(200)
expect(bodyPlainTextResponse).toMatch(youReturnedBodyRegex)
expect(bodyPlainTextResponse).toMatch(/.*You performed an HTTP request.*/)
expect(textResponse.status).toBe(200)

const htmlResponse = await got(`http://localhost:${devServer.port}/.netlify/functions/scheduled-isc-body`, {
throwHttpErrors: false,
retry: { limit: 0 },
const htmlResponse = await fetch(`http://localhost:${devServer.port}/.netlify/functions/scheduled-isc-body`, {
headers: {
accept: 'text/html',
},
})

expect(htmlResponse.body).toMatch(/.*<link.*/)
expect(htmlResponse.statusCode).toBe(200)
const BodyHtmlResponse = await htmlResponse.text()

expect(BodyHtmlResponse).toMatch(/.*<link.*/)
expect(htmlResponse.status).toBe(200)

const stdout = await fixture.callCli([
'functions:invoke',
Expand Down

1 comment on commit 8e71e42

@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,399
  • Package size: 405 MB
  • Number of ts-expect-error directives: 1,292

Please sign in to comment.