feat: add support for files and math for messages (#5)

This commit is contained in:
Divlo
2022-01-07 21:21:38 +01:00
committed by GitHub
parent fdc2a2d1de
commit 5c03a9b944
57 changed files with 3403 additions and 2992 deletions

View File

@ -1,3 +1,5 @@
import path from 'node:path'
import { getLocal } from 'mockttp'
import { API_DEFAULT_PORT } from '../../tools/api'
@ -7,6 +9,13 @@ import { API_DEFAULT_PORT } from '../../tools/api'
/** @type {import('mockttp').Mockttp | null} */
let server = null
const UPLOADS_FIXTURES_DIRECTORY = path.join(
process.cwd(),
'cypress',
'fixtures',
'uploads'
)
/**
* @type {Cypress.PluginConfig}
*/
@ -21,10 +30,18 @@ module.exports = (on, config) => {
})
await server.start(API_DEFAULT_PORT)
for (const handler of handlers) {
await server[handler.method.toLowerCase()](handler.url).thenJson(
handler.response.statusCode,
handler.response.body
)
const { isFile = false } = handler.response
if (isFile) {
await server[handler.method.toLowerCase()](handler.url).thenFromFile(
handler.response.statusCode,
path.join(UPLOADS_FIXTURES_DIRECTORY, ...handler.response.body)
)
} else {
await server[handler.method.toLowerCase()](handler.url).thenJson(
handler.response.statusCode,
handler.response.body
)
}
}
return null
},