hapi 使用 lab 和 code 进行测试

版权声明:转载请评论留言 https://blog.csdn.net/solocao/article/details/85842507

测试库有很多,我选了lab
1、安装labcode

yarn add lab code

2、创建test文件夹
test文件夹里面的js文件会被跑测试。比如创建index.js

const { expect } = require('code');
const Lab = require('lab');
const lab = exports.lab = Lab.script();

lab.test('returns true when 1 + 1 equals 2', () => {
  expect(1 + 1).to.equal(2);
});

3、在package.json新增运行脚本

"scripts": {
  "test": "lab -t 75",
  "test-cov-html": "lab -r html -o coverage.html"
}

猜你喜欢

转载自blog.csdn.net/solocao/article/details/85842507