aws-sdk s3上传无法通过摩卡测试进行 [英] aws-sdk s3 upload not working from mocha test
本文介绍了aws-sdk s3上传无法通过摩卡测试进行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试通过Mocha测试运行s3上传:
Trying to run s3 upload from a mocha test:
'use strict';
describe('S3 test', function() {
it.only('S3 test 1', function*() {
var AWS = require('aws-sdk');
//AWS.config.region = 'us-west-2';
var s3 = new AWS.S3({
params: { Bucket: 'test-1-myBucket', Key: 'myKey' }
});
s3.createBucket(function(err) {
if (err) {
console.log("Error:", err);
} else {
s3.upload({
Body: 'Hello!'
}, function() {
console.log("Successfully uploaded data to myBucket/myKey");
});
}
});
});
});
但没有任何反应,它根本没有发送http请求.为什么会这样?
but nothing happens, it is not sending the http request at all. Why is that?
推荐答案
Doh.它是异步的,因此我需要使用完成的回调:
Doh. Its asynchronous so I need to use the done callback:
'use strict';
describe('S3 test', function() {
it.only('S3 test 1', function(done) {
var AWS = require('aws-sdk');
//AWS.config.region = 'us-west-2';
var s3 = new AWS.S3({
params: {
Bucket: 'mkruk-myBucket',
Key: 'myKey'
}
});
s3.createBucket(function(err) {
if (err) {
console.log("Error:", err);
done();
} else {
s3.upload({
Body: 'Hello!'
}, function() {
console.log("Successfully uploaded data to myBucket/myKey");
done();
});
}
});
});
});
这篇关于aws-sdk s3上传无法通过摩卡测试进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文