feat: add support for files and math for messages (#5)
This commit is contained in:
@ -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
|
||||
},
|
||||
|
Reference in New Issue
Block a user