我正在尝试为git项目生成覆盖率指标:
以下是样本回购:
https://github.com/imvetri/JS-coverage
my.conf.js
(function() {
function execute(rqst, q, fwk) {
console.log('called api')
var uploadedFile = rqst.files['image'];
console.log(rqst.files['image']);
var newId = fwk.uuid.v4();
console.log('.........', rqst);
if (rqst.body.data) {
var image_type = rqst.body.data;
} else {
var image_type = rqst.body.image_type;
}
console.log('type', image_type, newId);
if (image_type && uploadedFile) {
if (!uploadedFile.extension) {
uploadedFile.extension = "png";
console.log('not ex');
}
var newPath = "images/food-images" + "/" + newId + '.' + uploadedFile.extension;
fwk.getAwsS3Client(function(err, awsS3Client) {
var params = {
localFile: uploadedFile.path,
s3Params: {
Bucket: fwk.config.awsS3.bucketName,
Key: newPath,
},
};
var uploader = awsS3Client.uploadFile(params);
uploader.on('error', function(err) {
console.error('Unable to upload' + image_type + 'photo:' + err.toString());
q.resolve({
status: 200,
data: {
code: 1,
error_message: 'Unable to upload' + image_type + 'photo.'
}
});
});
uploader.on('progress', function() {
console.log(uploader.progressAmount);
});
uploader.on('end', function() {
console.log("upload" + image_type + "photo done.");
fwk.getAwsS3PublicUrl(newPath, function(err, publicUrl) {
if (err) {
console.error('Error getting public url: ' + err.toString());
q.resolve({
status: 200,
data: {
code: 1,
error_message: 'Error getting public url.'
}
});
} else {
// console.log('ho gya upload',newPath,publicUrl)
q.resolve({
status: 200,
data: {
code: 0,
photo_url: newPath,
public_photo_url: publicUrl
}
});
}
})
});
});
} else {
console.error('Error key parameter missing');
q.resolve({
status: 200,
data: {
code: 1,
error_message: 'Error Missing required key in params.'
}
});
}
}
exports.execute = execute;
})();
执行测试:
files: [ 'base/*.js', 'src/*.js', 'test/spec/*.js' ]
如果我将my.conf.js文件更改为
npm test
coverage-jasmine-istanbul-karma@0.0.1 test /Users/valappip/Downloads/coverage-jasmine-istanbul-karma-master
node_modules/.bin/karma start my.conf.js
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket 70e_eJb6AVI-1iy4f_F9
PhantomJS 1.9.8 (Mac OS X) ERROR
ReferenceError: Can't find variable: base
at /Users/valappip/Downloads/coverage-jasmine-istanbul-karma-master/base/base-base.js:6
PhantomJS 1.9.8 (Mac OS X): Executed 0 of 0 ERROR (0.03 secs / 0 secs)
npm ERR! weird error 1
npm ERR! not ok code 0
然后它给出了报告。但在我的实际项目中有很多JS文件,所以我无法逐个添加。有什么方法可以一次包含所有文件吗?或者我可以在测试开始之前加载依赖项吗?
答案 0 :(得分:0)
您可以尝试以下
files: [ 'base/base.js', 'base/*.js', 'src/*.js' 'test/spec/*.js']
另一种选择是查看您的代码并确保您不依赖于这种方式从一个文件到另一个文件。因为这听起来实际问题出现在您的代码中。