【发布时间】:2020-02-24 03:13:24
【问题描述】:
我用 Jest 设置了一堆测试,在同一个 repo 中测试 Express 服务器端点。为了完成这个测试,我让 Jest 在 beforeAll() 方法中启动了一个 Express 服务器。当我使用--coverage 标志运行 Jest 时,我只获得了为启动 Jest 而运行的脚本的覆盖率信息,而没有报告通过命中端点触发的脚本。这是有道理的,但有没有办法获取端点代码的覆盖率信息?
测试代码片段:
const rp = require('request-promise')
describe('testFunctions', () => {
beforeAll(done => {
app.listen(config.PORT, async () => {
done()
})
})
it('hit endpoint', async () => {
const response = await rp({ uri: '/testFunctions', method: 'POST' })
expect(response).toEqual('response)
})
})
我正在尝试获取使用/testFunctions 请求命中的所有服务器代码的覆盖率报告。
【问题讨论】:
标签: express jestjs integration-testing