Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 8 additions & 15 deletions tests/integration/commands/dev/dev-miscellaneous.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { cliPath } from '../../utils/cli-path.js'
import { getExecaOptions, withDevServer } from '../../utils/dev-server.js'
import { withMockApi } from '../../utils/mock-api.js'
import { pause } from '../../utils/pause.js'
import { withSiteBuilder, type SiteBuilder } from '../../utils/site-builder.js'
import { normalize } from '../../utils/snapshots.js'

Expand Down Expand Up @@ -848,7 +847,7 @@

await builder.build()

await withDevServer({ cwd: builder.directory }, async ({ port }) => {
await withDevServer({ cwd: builder.directory }, async ({ port, waitForLogMatching }) => {
const helloWorldMessage = await fetch(`http://localhost:${port}/hello`).then((res) => res.text())

await builder
Expand All @@ -858,8 +857,7 @@
})
.build()

const DETECT_FILE_CHANGE_DELAY = 500
await pause(DETECT_FILE_CHANGE_DELAY)
await waitForLogMatching('Reloaded edge function', { timeout: 500 })

const helloBuilderMessage = await fetch(`http://localhost:${port}/hello`, {}).then((res) => res.text())

Expand Down Expand Up @@ -894,7 +892,7 @@

await builder.build()

await withDevServer({ cwd: builder.directory }, async ({ port }) => {
await withDevServer({ cwd: builder.directory }, async ({ port, waitForLogMatching }) => {
const authResponseMessage = await fetch(`http://localhost:${port}/auth`).then((response) => response.text())

await builder
Expand All @@ -903,8 +901,7 @@
})
.build()

const DETECT_FILE_CHANGE_DELAY = 500
await pause(DETECT_FILE_CHANGE_DELAY)
await waitForLogMatching('Removed edge function', { timeout: 500 })

const authNotFoundMessage = await fetch(`http://localhost:${port}/auth`).then((response) => response.text())

Expand Down Expand Up @@ -940,9 +937,7 @@
t.expect(res1.status).toBe(200)
t.expect(await res1.text()).toEqual('Hello world')

// wait for file watcher to be up and running, which might take a little
// if we do not wait, the next file change will not be picked up
await pause(500)
await waitForLogMatching('Loaded edge function', { timeout: 500 })

await builder
.withEdgeFunction({
Expand All @@ -952,7 +947,7 @@
})
.build()

await waitForLogMatching('Reloaded edge function')
await waitForLogMatching('Reloaded edge function', { timeout: 500 })

const [res2, res3, res4] = await Promise.all([
fetch(`http://localhost:${port}/hello-1`),
Expand Down Expand Up @@ -1072,12 +1067,10 @@

const res1 = await fetch(`http://localhost:${port}/internal-1`)

t.expect(res1.status).toBe(200)

Check failure on line 1070 in tests/integration/commands/dev/dev-miscellaneous.test.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-2025, 20.12.2, 4/4)

tests/integration/commands/dev/dev-miscellaneous.test.ts > commands/dev-miscellaneous > should respect in-source configuration from internal edge functions

AssertionError: expected 404 to be 200 // Object.is equality - Expected + Received - 200 + 404 ❯ tests/integration/commands/dev/dev-miscellaneous.test.ts:1070:31 ❯ withDevServer tests/integration/utils/dev-server.ts:222:12 ❯ tests/integration/commands/dev/dev-miscellaneous.test.ts:1056:7 ❯ withSiteBuilder tests/integration/utils/site-builder.ts:342:12 ❯ tests/integration/commands/dev/dev-miscellaneous.test.ts:1044:5

Check failure on line 1070 in tests/integration/commands/dev/dev-miscellaneous.test.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-2025, 20.12.2, 4/4)

tests/integration/commands/dev/dev-miscellaneous.test.ts > commands/dev-miscellaneous > should respect in-source configuration from internal edge functions

AssertionError: expected 404 to be 200 // Object.is equality - Expected + Received - 200 + 404 ❯ tests/integration/commands/dev/dev-miscellaneous.test.ts:1070:31 ❯ withDevServer tests/integration/utils/dev-server.ts:222:12 ❯ tests/integration/commands/dev/dev-miscellaneous.test.ts:1056:7 ❯ withSiteBuilder tests/integration/utils/site-builder.ts:342:12 ❯ tests/integration/commands/dev/dev-miscellaneous.test.ts:1044:5
t.expect(await res1.text()).toEqual('Hello from an internal function')

// wait for file watcher to be up and running, which might take a little
// if we do not wait, the next file change will not be picked up
await pause(500)
await waitForLogMatching('Loaded edge function', { timeout: 500 })

await builder
.withEdgeFunction({
Expand All @@ -1088,7 +1081,7 @@
})
.build()

await waitForLogMatching('Reloaded edge function')
await waitForLogMatching('Reloaded edge function', { timeout: 500 })

const [res2, res3] = await Promise.all([
fetch(`http://localhost:${port}/internal-1`),
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/commands/dev/edge-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { describe, expect, test } from 'vitest'

import { withDevServer } from '../../utils/dev-server.js'
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
import { pause } from '../../utils/pause.js'
import { withSiteBuilder } from '../../utils/site-builder.js'

// Skipping tests on Windows because of an issue with the Deno CLI throwing IO
Expand Down Expand Up @@ -184,8 +183,7 @@ describe.skipIf(isWindows)('edge functions', async () => {

await setupFixtureTests('dev-server-with-edge-functions', { devServer: true, mockApi: { routes } }, () => {
test<FixtureTestContext>('should not remove other edge functions on change', async ({ devServer, fixture }) => {
// we need to wait till file watchers are loaded
await pause(500)
await devServer!.waitForLogMatching('Loaded edge function', { timeout: 500 })

await fixture.builder
.withEdgeFunction({
Expand Down Expand Up @@ -234,7 +232,7 @@ describe.skipIf(isWindows)('edge functions', async () => {
})
.build()

await pause(500)
await server.waitForLogMatching('Reloaded edge function', { timeout: 500 })

const response2 = await fetch(server.url, {}).then((res) => res.text())
t.expect(response2).toEqual('bar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe, expect, test } from 'vitest'

import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
import fetch from 'node-fetch'
import { pause } from '../../utils/pause.js'

describe('scheduled functions', async () => {
await setupFixtureTests('dev-server-with-functions', { devServer: true }, () => {
Expand Down Expand Up @@ -36,8 +35,7 @@ describe('scheduled functions', async () => {
})
.build()

const DETECT_FILE_CHANGE_DELAY = 500
await pause(DETECT_FILE_CHANGE_DELAY)
await devServer!.waitForLogMatching('Reloaded function ping', { timeout: 500 })

const warning = await fetch(`http://localhost:${devServer!.port}/.netlify/functions/ping`, {}).then((res) =>
res.text(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
const testMatrix = [{ args: [] }, { args: ['esbuild'] }]

const WAIT_WRITE = 3000
const DEBOUNCE_WAIT = 150

describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args }) => {
test('Updates a JavaScript function when its main file is modified', async (t) => {
Expand Down Expand Up @@ -48,7 +49,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
).toEqual('Hello')
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

await builder
.withFunction({
Expand All @@ -61,7 +62,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

await waitForLogMatching('Reloaded function hello')
await waitForLogMatching('Reloaded function hello', { timeout: WAIT_WRITE })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/hello`)

Expand Down Expand Up @@ -115,7 +116,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
).toEqual('Modern Web Development on the JAMStack')
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

await builder
.withContentFile({
Expand Down Expand Up @@ -143,7 +144,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

await waitForLogMatching('Reloaded function hello')
await waitForLogMatching('Reloaded function hello', { timeout: WAIT_WRITE })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/hello`)

Expand Down Expand Up @@ -180,16 +181,16 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
).toEqual('WOOF!')
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

await builder
.withContentFile({ path: 'functions/lib/util.js', content: js`exports.bark = () => 'WOOF WOOF!'` })
.build()

if (args.includes('esbuild')) {
await waitForLogMatching('Reloaded function hello')
await waitForLogMatching('Reloaded function hello', { timeout: WAIT_WRITE })
} else {
// no message printed when using not esbuild
// no message printed when not using esbuild
await pause(WAIT_WRITE)
}

Expand Down Expand Up @@ -258,7 +259,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
).toEqual('Modern Web Development on the JAMStack')
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

await builder
.withContentFile({
Expand All @@ -271,7 +272,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

await waitForLogMatching('Reloaded function hello')
await waitForLogMatching('Reloaded function hello', { timeout: WAIT_WRITE })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/hello`).then((res) =>
res.text(),
Expand Down Expand Up @@ -317,7 +318,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

await waitForLogMatching('Loaded function hello')
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/hello`).then((res) =>
res.text(),
Expand Down Expand Up @@ -359,7 +360,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
t.expect(unauthenticatedResponse.status).toBe(404)
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function help', { timeout: WAIT_WRITE })

await builder
.withContentFile({
Expand Down Expand Up @@ -387,7 +388,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

await waitForLogMatching('Loaded function hello')
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/hello`).then((res) =>
res.text(),
Expand Down Expand Up @@ -428,15 +429,15 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
).toEqual('Hello')
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

await builder
.withoutFile({
path: 'functions/hello.js',
})
.build()

await waitForLogMatching('Removed function hello')
await waitForLogMatching('Removed function hello', { timeout: WAIT_WRITE })

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

Expand Down Expand Up @@ -491,7 +492,6 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

const DEBOUNCE_WAIT = 150
await pause(DEBOUNCE_WAIT)

const resp2 = await fetch(`${server.url}/.netlify/functions/hello`)
Expand Down Expand Up @@ -528,16 +528,14 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

await tryAndLogOutput(async () => {
t.expect(
await fetch(`http://localhost:${port.toString()}/.netlify/functions/hello`).then((res) => res.text()),
).toEqual('Internal')
}, outputBuffer)

await pause(WAIT_WRITE)

await builder
.withFunction({
path: 'hello.js',
Expand All @@ -550,7 +548,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

await waitForLogMatching('Reloaded function hello')
await waitForLogMatching('Reloaded function hello', { timeout: WAIT_WRITE })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/hello`).then((res) =>
res.text(),
Expand Down Expand Up @@ -603,7 +601,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
).toEqual('User')
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function hello', { timeout: WAIT_WRITE })

await builder
.withFunction({
Expand All @@ -625,7 +623,7 @@ describe.concurrent.each(testMatrix)('withSiteBuilder with args: $args', ({ args
})
.build()

await waitForLogMatching('Reloaded function hello')
await waitForLogMatching('Reloaded function hello', { timeout: WAIT_WRITE })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/hello`).then((res) =>
res.text(),
Expand Down Expand Up @@ -979,7 +977,8 @@ describe.concurrent('serving functions', () => {
})
.build()

await withDevServer({ cwd: builder.directory }, async ({ outputBuffer, port }) => {
// eslint-disable-next-line @typescript-eslint/unbound-method
await withDevServer({ cwd: builder.directory }, async ({ outputBuffer, port, waitForLogMatching }) => {
await tryAndLogOutput(async () => {
const [responseHelloNameOne, responseHelloNameTwo] = await Promise.all([
fetch(`http://localhost:${port.toString()}/.netlify/functions/hello?name=one`).then((res) => res.text()),
Expand All @@ -1002,9 +1001,7 @@ describe.concurrent('serving functions', () => {
])
.build()

// wait for the watcher to rebuild the function
const delay = 1000
await pause(delay)
await waitForLogMatching('Reloaded function hello', { timeout: 1000 })

t.expect(outputBuffer.some((buffer) => /.*Reloaded function hello.*/.test(buffer.toString()))).toBe(true)
await tryAndLogOutput(async () => {
Expand Down
7 changes: 2 additions & 5 deletions tests/integration/serve/functions-go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { describe, test } from 'vitest'

import { tryAndLogOutput, withDevServer } from '../utils/dev-server.js'
import { createMock as createExecaMock } from '../utils/mock-execa.js'
import { pause } from '../utils/pause.js'
import { withSiteBuilder } from '../utils/site-builder.js'

const WAIT_WRITE = 1000

describe.concurrent('serve/functions-go', () => {
test('Updates a Go function when a file is modified', async (t) => {
const originalBody = 'Hello, world!'
Expand Down Expand Up @@ -89,13 +86,13 @@ describe.concurrent('serve/functions-go', () => {
t.expect(response).toEqual(originalBody)
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function go-func', { timeout: 1000 })

await builder
.withContentFile({ path: 'functions/go-func/main.go', content: `<updated mock main.go>` })
.build()

await waitForLogMatching('Reloaded function go-func')
await waitForLogMatching('Reloaded function go-func', { timeout: 1000 })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/go-func`).then((res) =>
res.text(),
Expand Down
7 changes: 2 additions & 5 deletions tests/integration/serve/functions-rust.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { test } from 'vitest'

import { tryAndLogOutput, withDevServer } from '../utils/dev-server.js'
import { createMock as createExecaMock } from '../utils/mock-execa.js'
import { pause } from '../utils/pause.js'
import { withSiteBuilder } from '../utils/site-builder.js'

const WAIT_WRITE = 1000

test('Updates a Rust function when a file is modified', async (t) => {
await withSiteBuilder(t, async (builder) => {
const originalBody = 'Netlify likes Rust'
Expand Down Expand Up @@ -83,13 +80,13 @@ test('Updates a Rust function when a file is modified', async (t) => {
t.expect(response).toEqual(originalBody)
}, outputBuffer)

await pause(WAIT_WRITE)
await waitForLogMatching('Loaded function rust-func', { timeout: 1000 })

await builder
.withContentFile({ path: 'functions/rust-func/src/main.rs', content: `<updated mock main.rs>` })
.build()

await waitForLogMatching('Reloaded function rust-func')
await waitForLogMatching('Reloaded function rust-func', { timeout: 1000 })

const response = await fetch(`http://localhost:${port.toString()}/.netlify/functions/rust-func`).then((res) =>
res.text(),
Expand Down
Loading
Loading