mapbox / mock-aws-sdk-js Goto Github PK
View Code? Open in Web Editor NEWCreate stubbed aws-sdk-js clients for testing purposes
License: ISC License
Create stubbed aws-sdk-js clients for testing purposes
License: ISC License
looking at #4 shows that upgrading to sinon 2.x will give the AWS stubs a few more methods useful for testing. This hopefully isn't a huge lift, and should result in mostly updating the stub
call to use the callsFake
method.
We should be able to specify the response payload in some way that is agnostic to the method our applications use to make the request. Specifying the payload should allow a callback, promise, or event-based application to receive the stubbed payload.
Sinon is up in the v4.x territory now. Upgrading would make it easier to read sinon docs to understand how to use the stubs that this library creates.
Since this library returns sinon stubs and since that lib has gone through major version upgrades, making this change should increment the major version here as well.
First of all thanks for this, it's been really handy.
I expect my tests to be independent from each other, and also to not need to cleanup after themselves. Given this, I'd like to call a single AWS.restore()
(or similar) after each test runs.
Would you be interested in a PR with such a function?
Any suggestions on how you'd like to see it work? I was thinking a list of services could be maintained when stubbing, then it'd be easy enough to iterate through these calling .restore()
, but I'm happy to defer to your judgment.
Is there a way to run the same stub twice, but with different specifications? (ie There are two calls to two different SQS queues with different responses for each queue.)
Example code:
var q = d3.queue(5);
q.defer(getInfo, QueueUrl);
q.defer(getInfo, QueueUrl);
q.await(function(err, main, dl) {
if (err) return callback(err);
console.log(dl.Attributes.ApproximateNumberOfMessages)
if (+dl.Attributes.ApproximateNumberOfMessages === 0) return callback(null);
var message = 'Queue stats:\n';
message += '```\n';
message += 'Main queue: ' + main.Attributes.ApproximateNumberOfMessages
message += 'Other queue: ' + dl.Attributes.ApproximateNumberOfMessages
message += '```';
if (err) return callback(err);
return callback(null, message);
});
}
function getInfo(url, callback) {
var sqs = new AWS.SQS(); // retrieving queue information
var params = {
AttributeNames: ['All'],
QueueUrl: url
};
sqs.getQueueAttributes(params, function(err, data) {
if (err) return callback(err);
return callback(null, data);
});
}
Here is the test:
test('Check main + dl queue returns total message(s) in queue(s)', function(assert) {
AWS.stub('SQS', 'getQueueAttributes', function(params, callback) {
var response = {'Attributes':{'ApproximateNumberOfMessages':5, 'ApproximateNumberOfMessagesNotVisible':3}}
callback(null, response);
});
debugger;
index.retrieveQueueLengths(function(err, result) {
assert.equal(err, null);
assert.equal(result.length, 97);
assert.equal(result[29], '5');
AWS.SQS.restore()
assert.end();
})
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.