karma.conf.base.js
function (req, res, next) {
    if (req.url.indexOf('/api/mock') === -1) {
        return next();
    }

    var data = url.parse(req.url, true).query;

    setTimeout(function () {
        res.statusCode = data.statusCode || 200;
        res.setHeader('content-type', data.contentType || 'json');
        res.end(data.response || '{}');
    }, data.timeout || 0);
}
function (req, res, next) {
    if (req.url.indexOf('/api/mock') === -1) {
        return next();
    }

    var data = url.parse(req.url, true).query;

    setTimeout(function () {
        res.statusCode = data.statusCode || 200;
        res.setHeader('content-type', data.contentType || 'json');
        res.end(data.response || '{}');
    }, data.timeout || 0);
}
mock一个server供测试使用

@param  {Object}   req  request
@param  {Object}   res  response
@param  {Function} next 下一路由

@example
请求 /api/mock 参数如:
timeout - 超时时间, 默认 0
statusCode - 状态码, 默认 200
response - 响应内容, 默认 {}
dataType - 响应格式, 默认 json