【发布时间】:2020-05-05 08:33:43
【问题描述】:
我正在尝试通过代码启动和停止无服务器应用程序。一旦所有测试通过,我就可以启动和停止它。但是,当测试失败时 globalTeardown 不要运行。您可以在此处查看示例项目:https://github.com/bilalsha/sls-test-jest/tree/fail_test
teardown.js
module.exports = async function() {
let slsOfflineProcess = global.__SERVERD__;
slsOfflineProcess.stdin.write('q\n');
slsOfflineProcess.stdin.pause();
await slsOfflineProcess.kill('SIGINT');
console.log('Serverless Offline stopped');
};
output
7 | expect(res.statusCode).toEqual(200);
> 8 | expect(res.body).toEqual('Go Serverless v1.0! Your function executed successfully!');
| ^
9 | });
10 | });
11 |
at Object.<anonymous> (handler.test.js:8:20)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 1.972s, estimated 2s
Ran all test suites.
npm ERR! Test failed. See above for more details.
【问题讨论】: