Skip to content

Commit

Permalink
chore: use path without query strings
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed May 12, 2023
1 parent af7ae9e commit af44a8f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
},
"devDependencies": {
"@babel/preset-react": "^7.12.13",
"@fastify/url-data": "^5.3.1",
"@netlify/eslint-config-node": "^7.0.0",
"@netlify/functions": "^1.6.0",
"@types/fs-extra": "^11.0.1",
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/utils/mock-api-vitest.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { isDeepStrictEqual } from 'util'

import fastifyUrlData from '@fastify/url-data'
import fastify from 'fastify'
import { afterAll, beforeAll, beforeEach } from 'vitest'

// Replace mock-api.cjs with this once everything migrated

const addRequest = (requests, request) => {
requests.push({
path: request.url,
path: request.urlData().path,
body: request.body,
method: request.method,
headers: request.headers,
Expand All @@ -22,6 +23,7 @@ const clearRequests = (requests) => {
const startMockApi = async ({ routes, silent }) => {
const requests = []
const app = fastify()
app.register(fastifyUrlData)

routes.forEach(({ method = 'get', path, requestBody, response = {}, status = 200 }) => {
app.route({
Expand Down Expand Up @@ -74,7 +76,7 @@ export const withMockApi = async (routes, factory, silent = false) => {
})

afterAll(() => {
mockApi.close()
if (mockApi) mockApi.close()
})

factory()
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/utils/mock-api.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { isDeepStrictEqual } = require('util')

const fastifyUrlData = require('@fastify/url-data')
const fastify = require('fastify')

/**
Expand All @@ -8,7 +9,7 @@ const fastify = require('fastify')
*/
const addRequest = (requests, request) => {
requests.push({
path: request.url,
path: request.urlData().path,
body: request.body,
method: request.method,
headers: request.headers,
Expand All @@ -23,6 +24,7 @@ const addRequest = (requests, request) => {
const startMockApi = async ({ routes, silent }) => {
const requests = []
const app = fastify()
app.register(fastifyUrlData)

routes.forEach(({ method = 'get', path, requestBody, response = {}, status = 200 }) => {
app.route({
Expand Down Expand Up @@ -68,7 +70,7 @@ const withMockApi = async (routes, testHandler, silent = false) => {
const apiUrl = `http://localhost:${mockApi.server.address().port}/api/v1`
return await testHandler({ apiUrl, requests: mockApi.requests })
} finally {
mockApi.server.close()
if (mockApi) mockApi.close()
}
}

Expand Down

0 comments on commit af44a8f

Please sign in to comment.