Skip to content

Commit

Permalink
Merge branch 'netlify:main' into refactor/replace-got/edge-functions.…
Browse files Browse the repository at this point in the history
…test.ts
  • Loading branch information
hereje authored Dec 13, 2023
2 parents ccef1ae + ef7e6db commit 67ad53f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 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
6 changes: 4 additions & 2 deletions tests/integration/rules-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 67ad53f

Please sign in to comment.