Skip to content

Commit

Permalink
refactor: replace some deprecated signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Jan 8, 2024
1 parent 323bab9 commit 2e5556b
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions tests/integration/commands/dev/dev.config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
import { version } from 'process'

import FormData from 'form-data'
import getPort from 'get-port'
import fetch from 'node-fetch'
import { gte } from 'semver'
import { describe, test } from 'vitest'
import getPort from 'get-port'

import { withDevServer } from '../../utils/dev-server.ts'
import { withSiteBuilder } from '../../utils/site-builder.ts'

describe.concurrent('commands/dev/config', () => {
test('should use [build.environment] and not [context.production.environment]', async (t) => {
await withSiteBuilder('site-with-build-environment', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: {
Expand All @@ -30,7 +30,7 @@ describe.concurrent('commands/dev/config', () => {
}),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await fetch(`${server.url}/.netlify/functions/env`).then((res) => res.text())
Expand All @@ -40,7 +40,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should use [context.production.environment] when --context=production', async (t) => {
await withSiteBuilder('site-with-build-environment', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: {
Expand All @@ -55,7 +55,7 @@ describe.concurrent('commands/dev/config', () => {
handler: async () => ({ statusCode: 200, body: `${process.env.TEST_PRODUCTION_ENVIRONMENT}` }),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory, context: 'production' }, async (server) => {
const response = await fetch(`${server.url}/.netlify/functions/env`).then((res) => res.text())
Expand All @@ -65,7 +65,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should override .env.development with process env', async (t) => {
await withSiteBuilder('site-with-override', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({ config: { functions: { directory: 'functions' } } })
.withEnvFile({ path: '.env.development', env: { TEST: 'FROM_DEV_FILE' } })
Expand All @@ -75,7 +75,7 @@ describe.concurrent('commands/dev/config', () => {
handler: async () => ({ statusCode: 200, body: `${process.env.TEST}` }),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory, env: { TEST: 'FROM_PROCESS_ENV' } }, async (server) => {
const response = await fetch(`${server.url}/.netlify/functions/env`).then((res) => res.text())
Expand All @@ -85,7 +85,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should override [build.environment] with process env', async (t) => {
await withSiteBuilder('site-with-build-environment-override', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: { build: { environment: { TEST: 'FROM_CONFIG_FILE' } }, functions: { directory: 'functions' } },
Expand All @@ -96,7 +96,7 @@ describe.concurrent('commands/dev/config', () => {
handler: async () => ({ statusCode: 200, body: `${process.env.TEST}` }),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory, env: { TEST: 'FROM_PROCESS_ENV' } }, async (server) => {
const response = await fetch(`${server.url}/.netlify/functions/env`).then((res) => res.text())
Expand All @@ -106,15 +106,15 @@ describe.concurrent('commands/dev/config', () => {
})

test('should replicate Lambda behaviour for synchronous return values', async (t) => {
await withSiteBuilder('site-replicate-aws-sync-behaviour', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({
path: 'env.js',
handler: () => ({
statusCode: 200,
}),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await fetch(`${server.url}/.netlify/functions/env`)
Expand All @@ -127,14 +127,14 @@ describe.concurrent('commands/dev/config', () => {
})

test('should override value of the NETLIFY_DEV env variable', async (t) => {
await withSiteBuilder('site-with-netlify-dev-override', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({
path: 'env.js',
// eslint-disable-next-line n/prefer-global/process
handler: async () => ({ statusCode: 200, body: `${process.env.NETLIFY_DEV}` }),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory, env: { NETLIFY_DEV: 'FROM_PROCESS_ENV' } }, async (server) => {
const response = await fetch(`${server.url}/.netlify/functions/env`).then((res) => res.text())
Expand All @@ -144,7 +144,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should provide CLI version in env var', async (t) => {
await withSiteBuilder('site-with-netlify-version-env-var', async (builder) => {
await withSiteBuilder(t, async (builder) => {
const port = await getPort()

await builder
Expand Down Expand Up @@ -181,14 +181,14 @@ describe.concurrent('commands/dev/config', () => {
})

test('should set value of the CONTEXT env variable', async (t) => {
await withSiteBuilder('site-with-context-override', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({
path: 'env.js',
// eslint-disable-next-line n/prefer-global/process
handler: async () => ({ statusCode: 200, body: `${process.env.CONTEXT}` }),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await fetch(`${server.url}/.netlify/functions/env`).then((res) => res.text())
Expand All @@ -198,14 +198,14 @@ describe.concurrent('commands/dev/config', () => {
})

test('should set value of the CONTEXT env variable to the --context flag', async (t) => {
await withSiteBuilder('site-with-context-override', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({
path: 'env.js',
// eslint-disable-next-line n/prefer-global/process
handler: async () => ({ statusCode: 200, body: `${process.env.CONTEXT}` }),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory, context: 'deploy-preview' }, async (server) => {
const response = await fetch(`${server.url}/.netlify/functions/env`).then((res) => res.text())
Expand All @@ -215,7 +215,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should redirect using a wildcard when set in netlify.toml', async (t) => {
await withSiteBuilder('site-with-redirect-function', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: {
Expand All @@ -231,7 +231,7 @@ describe.concurrent('commands/dev/config', () => {
}),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await fetch(`${server.url}/api/ping`).then((res) => res.text())
Expand All @@ -241,7 +241,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should pass undefined body to functions event for GET requests when redirecting', async (t) => {
await withSiteBuilder('site-with-get-echo-function', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: {
Expand All @@ -257,7 +257,7 @@ describe.concurrent('commands/dev/config', () => {
}),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await fetch(`${server.url}/api/echo?ding=dong`).then((res) => res.json())
Expand All @@ -272,7 +272,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should pass body to functions event for POST requests when redirecting', async (t) => {
await withSiteBuilder('site-with-post-echo-function', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: {
Expand All @@ -288,7 +288,7 @@ describe.concurrent('commands/dev/config', () => {
}),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await fetch(`${server.url}/api/echo?ding=dong`, {
Expand All @@ -312,7 +312,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should pass body to functions event for POST requests with passthrough edge function', async (t) => {
await withSiteBuilder('site-with-post-echo-function', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: {
Expand All @@ -338,7 +338,7 @@ describe.concurrent('commands/dev/config', () => {
}),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await fetch(`${server.url}/api/echo?ding=dong`, {
Expand All @@ -362,7 +362,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should return an empty body for a function with no body when redirecting', async (t) => {
await withSiteBuilder('site-with-no-body-function', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: {
Expand All @@ -377,7 +377,7 @@ describe.concurrent('commands/dev/config', () => {
}),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await fetch(`${server.url}/api/echo?ding=dong`, {
Expand All @@ -395,7 +395,7 @@ describe.concurrent('commands/dev/config', () => {
})

test('should handle multipart form data when redirecting', async (t) => {
await withSiteBuilder('site-with-multi-part-function', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withNetlifyToml({
config: {
Expand All @@ -411,7 +411,7 @@ describe.concurrent('commands/dev/config', () => {
}),
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const form = new FormData()
Expand All @@ -438,7 +438,7 @@ describe.concurrent('commands/dev/config', () => {
})

test.runIf(gte(version, '18.14.0'))('should support functions with streaming responses', async (t) => {
await withSiteBuilder('site-with-streaming-function', async (builder) => {
await withSiteBuilder(t, async (builder) => {
builder
.withPackageJson({ packageJson: { dependencies: { '@netlify/functions': 'latest' } } })
.withCommand({ command: ['npm', 'install'] })
Expand Down Expand Up @@ -486,7 +486,7 @@ describe.concurrent('commands/dev/config', () => {
path: 'netlify/functions/streamer.js',
})

await builder.buildAsync()
await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
const chunks = []
Expand Down

0 comments on commit 2e5556b

Please sign in to comment.