Skip to content

Commit

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

* refactor: replace got with node-fetch on functions-with-args.test.js (#6245)

related to #5695

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* chore: empty commit to rerun actions

---------

Co-authored-by: Angel Mendez <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Sarah Etter <[email protected]>
  • Loading branch information
4 people authored Dec 18, 2023
1 parent a5740db commit 1d43172
Showing 1 changed file with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fetch from 'node-fetch'
import { describe, test } from 'vitest'

import { tryAndLogOutput, withDevServer } from '../../utils/dev-server.ts'
import got from '../../utils/got.js'
import { pause } from '../../utils/pause.js'
import { withSiteBuilder } from '../../utils/site-builder.ts'

Expand All @@ -15,18 +14,6 @@ const testMatrix = [{ args: [] }, { args: ['esbuild'] }]

const WAIT_WRITE = 3000

// TODO: Remove function and got
const gotCatch404 = async (url, options) => {
try {
return await got(url, options)
} catch (error) {
if (error.response && error.response.statusCode === 404) {
return error.response
}
throw error
}
}

describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args }) => {
test('Updates a JavaScript function when its main file is modified', async (t) => {
await withSiteBuilder('js-function-update-main-file', async (builder) => {
Expand Down Expand Up @@ -303,9 +290,9 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args

await withDevServer({ cwd: builder.directory, args }, async ({ outputBuffer, port, waitForLogMatching }) => {
await tryAndLogOutput(async () => {
const unauthenticatedResponse = await gotCatch404(`http://localhost:${port}/.netlify/functions/hello`)
const unauthenticatedResponse = await fetch(`http://localhost:${port}/.netlify/functions/hello`)

t.expect(unauthenticatedResponse.statusCode).toBe(404)
t.expect(unauthenticatedResponse.status).toBe(404)
}, outputBuffer)

await pause(WAIT_WRITE)
Expand All @@ -322,7 +309,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args

await waitForLogMatching('Loaded function hello')

const response = await got(`http://localhost:${port}/.netlify/functions/hello`).text()
const response = await fetch(`http://localhost:${port}/.netlify/functions/hello`).then((res) => res.text())

t.expect(response).toEqual('Hello')
})
Expand Down Expand Up @@ -353,9 +340,9 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args

await withDevServer({ cwd: builder.directory, args }, async ({ outputBuffer, port, waitForLogMatching }) => {
await tryAndLogOutput(async () => {
const unauthenticatedResponse = await gotCatch404(`http://localhost:${port}/.netlify/functions/hello`)
const unauthenticatedResponse = await fetch(`http://localhost:${port}/.netlify/functions/hello`)

t.expect(unauthenticatedResponse.statusCode).toBe(404)
t.expect(unauthenticatedResponse.status).toBe(404)
}, outputBuffer)

await pause(WAIT_WRITE)
Expand Down Expand Up @@ -388,7 +375,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args

await waitForLogMatching('Loaded function hello')

const response = await got(`http://localhost:${port}/.netlify/functions/hello`).text()
const response = await fetch(`http://localhost:${port}/.netlify/functions/hello`).then((res) => res.text())

t.expect(response).toEqual('Modern Web Development on the Jamstack')
})
Expand Down Expand Up @@ -433,9 +420,9 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args

await waitForLogMatching('Removed function hello')

const { statusCode } = await gotCatch404(`http://localhost:${port}/.netlify/functions/hello`)
const { status } = await fetch(`http://localhost:${port}/.netlify/functions/hello`)

t.expect(statusCode).toBe(404)
t.expect(status).toBe(404)
})
})
})
Expand Down

1 comment on commit 1d43172

@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.