Skip to content

Commit c1fbdc1

Browse files
committed
test: fix use of expect in concurrent tests
1 parent 11d96d6 commit c1fbdc1

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

tests/integration/commands/dev/edge-functions.test.ts

+30-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { join } from 'path'
44

55
import execa from 'execa'
66
import fetch from 'node-fetch'
7-
import { describe, expect, expectTypeOf, test } from 'vitest'
7+
import { describe, expectTypeOf, test } from 'vitest'
88

99
import { withDevServer } from '../../utils/dev-server.js'
1010
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
@@ -51,7 +51,7 @@ describe.skipIf(isWindows)('edge functions', () => {
5151
'dev-server-with-edge-functions',
5252
{ devServer: true, mockApi: { routes }, setupAfterDev: recreateEdgeFunctions },
5353
() => {
54-
test<FixtureTestContext>('should run edge functions in correct order', async ({ devServer }) => {
54+
test<FixtureTestContext>('should run edge functions in correct order', async ({ devServer, expect }) => {
5555
const response = await fetch(`http://localhost:${devServer.port}/ordertest`)
5656
const body = await response.text()
5757

@@ -71,7 +71,7 @@ describe.skipIf(isWindows)('edge functions', () => {
7171
])
7272
})
7373

74-
test<FixtureTestContext>('should provide context properties', async ({ devServer }) => {
74+
test<FixtureTestContext>('should provide context properties', async ({ devServer, expect }) => {
7575
const response = await fetch(`http://localhost:${devServer.port}/context`)
7676

7777
const { deploy, geo, ip, params, requestId, server, site } = await response.json()
@@ -85,7 +85,7 @@ describe.skipIf(isWindows)('edge functions', () => {
8585
expect(site).toEqual({ id: 'foo', name: 'site-name', url: `http://localhost:${devServer.port}` })
8686
})
8787

88-
test<FixtureTestContext>('should expose URL parameters', async ({ devServer }) => {
88+
test<FixtureTestContext>('should expose URL parameters', async ({ devServer, expect }) => {
8989
const response = await fetch(`http://localhost:${devServer.port}/categories/foo/products/bar`)
9090

9191
const { params } = await response.json()
@@ -97,6 +97,7 @@ describe.skipIf(isWindows)('edge functions', () => {
9797

9898
test<FixtureTestContext>('should expose URL parameters to edge functions with `cache: "manual"`', async ({
9999
devServer,
100+
expect,
100101
}) => {
101102
const response = await fetch(`http://localhost:${devServer.port}/categories-after-cache/foo/products/bar`)
102103

@@ -107,7 +108,7 @@ describe.skipIf(isWindows)('edge functions', () => {
107108
})
108109
})
109110

110-
test<FixtureTestContext>('should respect config.methods field', async ({ devServer }) => {
111+
test<FixtureTestContext>('should respect config.methods field', async ({ devServer, expect }) => {
111112
const responseGet = await fetch(`http://localhost:${devServer.port}/products/really-bad-product`, {
112113
method: 'GET',
113114
})
@@ -123,6 +124,7 @@ describe.skipIf(isWindows)('edge functions', () => {
123124

124125
test<FixtureTestContext>('should show an error page when an edge function has an uncaught exception', async ({
125126
devServer,
127+
expect,
126128
}) => {
127129
const [plainTextResponse, htmlResponse] = await Promise.all([
128130
fetch(`http://localhost:${devServer.port}/uncaught-exception`, {
@@ -146,6 +148,7 @@ describe.skipIf(isWindows)('edge functions', () => {
146148

147149
test<FixtureTestContext>('should set the `URL`, `SITE_ID`, and `SITE_NAME` environment variables', async ({
148150
devServer,
151+
expect,
149152
}) => {
150153
const body = (await fetch(`http://localhost:${devServer.port}/echo-env`).then((res) => res.json())) as Record<
151154
string,
@@ -169,6 +172,7 @@ describe.skipIf(isWindows)('edge functions', () => {
169172
() => {
170173
test<FixtureTestContext>('skips edge functions when --internal-disable-edge-functions is passed', async ({
171174
devServer,
175+
expect,
172176
}) => {
173177
const response = await fetch(`http://localhost:${devServer.port}/ordertest`)
174178
const body = await response.text()
@@ -181,7 +185,11 @@ describe.skipIf(isWindows)('edge functions', () => {
181185
)
182186

183187
setupFixtureTests('dev-server-with-edge-functions', { devServer: true, mockApi: { routes } }, () => {
184-
test<FixtureTestContext>('should not remove other edge functions on change', async ({ devServer, fixture }) => {
188+
test<FixtureTestContext>('should not remove other edge functions on change', async ({
189+
devServer,
190+
expect,
191+
fixture,
192+
}) => {
185193
// we need to wait till file watchers are loaded
186194
await pause(500)
187195

@@ -200,6 +208,8 @@ describe.skipIf(isWindows)('edge functions', () => {
200208
})
201209

202210
test('should reload on change to transitive dependency', async (t) => {
211+
const { expect } = t
212+
203213
await withSiteBuilder(t, async (builder) => {
204214
await builder
205215
.withContentFile({
@@ -221,8 +231,9 @@ describe.skipIf(isWindows)('edge functions', () => {
221231
.build()
222232

223233
await withDevServer({ cwd: builder.directory }, async (server) => {
224-
const response = await fetch(server.url, {}).then((res) => res.text())
225-
t.expect(response).toEqual('foo')
234+
const response = await fetch(server.url, {})
235+
const text = await response.text()
236+
expect(text).toEqual('foo')
226237

227238
// update file
228239
await builder
@@ -234,13 +245,16 @@ describe.skipIf(isWindows)('edge functions', () => {
234245

235246
await pause(500)
236247

237-
const response2 = await fetch(server.url, {}).then((res) => res.text())
238-
t.expect(response2).toEqual('bar')
248+
const response2 = await fetch(server.url, {})
249+
const text2 = await response2.text()
250+
expect(text2).toEqual('bar')
239251
})
240252
})
241253
})
242254

243255
test('functions and edge functions should receive url-encoded search params in the same way', async (t) => {
256+
const { expect } = t
257+
244258
await withSiteBuilder(t, async (builder) => {
245259
await builder
246260
.withContentFile({
@@ -262,8 +276,8 @@ describe.skipIf(isWindows)('edge functions', () => {
262276
await withDevServer({ cwd: builder.directory }, async (server) => {
263277
const funcResponse = await fetch(new URL('/func?1,2,3', server.url), {})
264278
const efResponse = await fetch(new URL('/ef?1,2,3', server.url), {})
265-
t.expect(await funcResponse.text()).toEqual('?1,2,3')
266-
t.expect(await efResponse.text()).toEqual('?1,2,3')
279+
expect(await funcResponse.text()).toEqual('?1,2,3')
280+
expect(await efResponse.text()).toEqual('?1,2,3')
267281
})
268282
})
269283
})
@@ -272,7 +286,10 @@ describe.skipIf(isWindows)('edge functions', () => {
272286
'dev-server-with-edge-functions-and-npm-modules',
273287
{ devServer: true, mockApi: { routes }, setup },
274288
() => {
275-
test<FixtureTestContext>('should run an edge function that uses the Blobs npm module', async ({ devServer }) => {
289+
test<FixtureTestContext>('should run an edge function that uses the Blobs npm module', async ({
290+
devServer,
291+
expect,
292+
}) => {
276293
const res = await fetch(`http://localhost:${devServer.port}/blobs`, {
277294
method: 'GET',
278295
})

tests/integration/commands/functions-create/functions-create.test.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { readFile } from 'fs/promises'
33
import { join } from 'path'
44

55
import execa from 'execa'
6-
import { describe, expect, test } from 'vitest'
6+
import { describe, test } from 'vitest'
77

88
import { fileExistsAsync } from '../../../../src/lib/fs.js'
99
import { cliPath } from '../../utils/cli-path.js'
@@ -36,6 +36,8 @@ describe.concurrent('functions:create command', () => {
3636
]
3737

3838
test('should create a new function directory when none is found', async (t) => {
39+
const { expect } = t
40+
3941
await withSiteBuilder(t, async (builder) => {
4042
await builder.build()
4143
await withMockApi(routes, async ({ apiUrl }) => {
@@ -72,6 +74,8 @@ describe.concurrent('functions:create command', () => {
7274
})
7375

7476
test('should create a new edge function directory when none is found', async (t) => {
77+
const { expect } = t
78+
7579
await withSiteBuilder(t, async (builder) => {
7680
await builder.build()
7781
await withMockApi(routes, async ({ apiUrl }) => {
@@ -108,6 +112,8 @@ describe.concurrent('functions:create command', () => {
108112
})
109113

110114
test('should use specified edge function directory when found', async (t) => {
115+
const { expect } = t
116+
111117
await withSiteBuilder(t, async (builder) => {
112118
builder.withNetlifyToml({ config: { build: { edge_functions: 'somethingEdgy' } } })
113119
await builder.build()
@@ -144,6 +150,8 @@ describe.concurrent('functions:create command', () => {
144150
})
145151

146152
test('should not create a new function directory when one is found', async (t) => {
153+
const { expect } = t
154+
147155
await withSiteBuilder(t, async (builder) => {
148156
builder.withNetlifyToml({ config: { build: { functions: 'functions' } } })
149157

@@ -181,6 +189,8 @@ describe.concurrent('functions:create command', () => {
181189
})
182190

183191
test('should only show function templates for the language specified via the --language flag, if one is present', async (t) => {
192+
const { expect } = t
193+
184194
const createWithLanguageTemplate = async (language, outputPath) =>
185195
await withSiteBuilder(t, async (builder) => {
186196
await builder.build()
@@ -224,6 +234,8 @@ describe.concurrent('functions:create command', () => {
224234
})
225235

226236
test('throws an error when the --language flag contains an unsupported value', async (t) => {
237+
const { expect } = t
238+
227239
await withSiteBuilder(t, async (builder) => {
228240
await builder.build()
229241

@@ -263,7 +275,7 @@ describe.concurrent('functions:create command', () => {
263275
})
264276

265277
setupFixtureTests('nx-integrated-monorepo', () => {
266-
test<FixtureTestContext>('should create a new edge function', async ({ fixture }) => {
278+
test<FixtureTestContext>('should create a new edge function', async ({ expect, fixture }) => {
267279
await withMockApi(routes, async ({ apiUrl }) => {
268280
const childProcess = execa(
269281
cliPath,
@@ -322,7 +334,7 @@ describe.concurrent('functions:create command', () => {
322334
// await devServer.waitForLogMatching('Loaded edge function new')
323335
// expect(devServer.output).not.toContain('Removed edge function')
324336
})
325-
test<FixtureTestContext>('should create a new serverless function', async ({ fixture }) => {
337+
test<FixtureTestContext>('should create a new serverless function', async ({ expect, fixture }) => {
326338
await withMockApi(routes, async ({ apiUrl }) => {
327339
const childProcess = execa(
328340
cliPath,

0 commit comments

Comments
 (0)