From e3f654eb140ebf27ee019939da8e8188cd8dac70 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Tue, 12 Dec 2023 19:40:23 -0600 Subject: [PATCH 1/3] refactor: replace got with node-fetch on scheduled-functions.test.ts (#6233) replace got with node-fetch related to #5695 Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../commands/dev/scheduled-functions.test.ts | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tests/integration/commands/dev/scheduled-functions.test.ts b/tests/integration/commands/dev/scheduled-functions.test.ts index 7475332d072..27f62494e0e 100644 --- a/tests/integration/commands/dev/scheduled-functions.test.ts +++ b/tests/integration/commands/dev/scheduled-functions.test.ts @@ -1,27 +1,23 @@ import { describe, expect, test } from 'vitest' import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js' -import got from '../../utils/got.js' +import fetch from 'node-fetch' import { pause } from '../../utils/pause.js' describe('scheduled functions', () => { setupFixtureTests('dev-server-with-functions', { devServer: true }, () => { test('should emulate next_run for scheduled functions', async ({ devServer }) => { - const response = await got(`http://localhost:${devServer.port}/.netlify/functions/scheduled-isc`, { - throwHttpErrors: false, - retry: { limit: 0 }, - }) + const response = await fetch(`http://localhost:${devServer.port}/.netlify/functions/scheduled-isc`, {}) - expect(response.statusCode).toBe(200) + expect(response.status).toBe(200) }) }) setupFixtureTests('dev-server-with-functions', { devServer: true }, () => { test('should detect file changes to scheduled function', async ({ devServer, fixture }) => { - const { body } = await got(`http://localhost:${devServer.port}/.netlify/functions/ping`, { - throwHttpErrors: false, - retry: { limit: 0 }, - }) + const body = await fetch(`http://localhost:${devServer.port}/.netlify/functions/ping`, {}).then((res) => + res.text(), + ) expect(body).toBe('ping') @@ -43,10 +39,9 @@ describe('scheduled functions', () => { const DETECT_FILE_CHANGE_DELAY = 500 await pause(DETECT_FILE_CHANGE_DELAY) - const { body: warning } = await got(`http://localhost:${devServer.port}/.netlify/functions/ping`, { - throwHttpErrors: false, - retry: { limit: 0 }, - }) + const warning = await fetch(`http://localhost:${devServer.port}/.netlify/functions/ping`, {}).then((res) => + res.text(), + ) expect(warning).toContain('Your function returned `body`') }) From 8e71e4298c4bfcdf167026018887999568c8405c Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Wed, 13 Dec 2023 08:20:38 -0600 Subject: [PATCH 2/3] refactor: replace got with node-fetch on functions-invoke.test.ts (#6232) replace got with node-fetch related to #5695 Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../functions-invoke/functions-invoke.test.ts | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/integration/commands/functions-invoke/functions-invoke.test.ts b/tests/integration/commands/functions-invoke/functions-invoke.test.ts index cc30f216a82..fa63e84d25c 100644 --- a/tests/integration/commands/functions-invoke/functions-invoke.test.ts +++ b/tests/integration/commands/functions-invoke/functions-invoke.test.ts @@ -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' @@ -39,26 +39,25 @@ describe('functions:invoke command', () => { ) test.concurrent('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(/.* Date: Wed, 13 Dec 2023 08:31:31 -0600 Subject: [PATCH 3/3] refactor: replace got with node-fetch on rules-proxy.test.ts (#6236) replace got with node-fetch related to #5695 Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- tests/integration/rules-proxy.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/integration/rules-proxy.test.ts b/tests/integration/rules-proxy.test.ts index ac76a9f8ee7..7db083951c7 100644 --- a/tests/integration/rules-proxy.test.ts +++ b/tests/integration/rules-proxy.test.ts @@ -6,7 +6,7 @@ import { afterAll, beforeAll, describe, expect, test } from 'vitest' import { createRewriter, getWatchers } from '../../src/utils/rules-proxy.js' -import got from './utils/got.js' +import fetch from 'node-fetch' import { createSiteBuilder, SiteBuilder } from './utils/site-builder.ts' describe('rules-proxy', () => { @@ -48,7 +48,9 @@ describe('rules-proxy', () => { }) test('should apply re-write rule based on _redirects file', async () => { - const response = await got(`http://localhost:${(server?.address() as net.AddressInfo).port}/something`).json() + const response = await fetch(`http://localhost:${(server?.address() as net.AddressInfo).port}/something`).then( + (res) => res.json(), + ) expect(response.from).toBe('/something') expect(response.to).toBe('/ping')