istanbul-client
v0.2.1
Published
## Project build ``` npm run build ``` ## Express use demo ```js const { v4: uuidv4 } = require('uuid'); const { dynamicUtilJS, SSEConnections } = require('istanbul-client'); const sse = new SSEConnections();
Downloads
16
Readme
istanbul-client
Project build
npm run build
Express use demo
const { v4: uuidv4 } = require('uuid');
const { dynamicUtilJS, SSEConnections } = require('istanbul-client');
const sse = new SSEConnections();
//创建长链接来发送收集事件
router.get('/', (req, res) => {
sse.addConnection(req, res)
});
//接收从客户端发送的覆盖率数据
router.post('/', (req, res, next) => {
const body = req.body;
//保存覆盖率数据
......
res.send("ok")
});
//输出动态的客户端js代码
router.get('/util.js', (req, res) => {
res.set('Content-Type', 'application/javascript');
let esUrl = "http://127.0.0.1:3000/";
let versionName = req.query.versionName;
res.send(dynamicUtilJS(esUrl, versionName))
});
//查看所有的已有连接
router.get('/connections', (req, res) => {
res.success(sse.getConnections())
});
//收集覆盖率
router.post('/collect', (req, res) => {
const uuid = uuidv4();
//对所有链接发送收集事件
sse.sendCollectToConnections({}, uuid)
res.success({ tag: uuid })
});