Runs a fake SQS server on a HTTP port.
const assert = require('assert')
const SQSServer = require('fake-sqs')
const AWS = require('aws-sdk')
async function test() {
const myServer = new SQSServer({
port: 0
})
await myServer.bootstrap()
const sqs = new AWS.SQS({
region: 'us-east-1',
sslEnabled: false,
accessKeyId: '123',
secretAccessKey: 'abc',
apiVersion: '2012-11-05'
})
const queueUrl = `http://` + myServer.hostPort
await sqs.sendMessage({
QueueURL: queueUrl,
MessageBody: 'my message'
}).promise()
await myServer.waitForMessages(1)
var queue = myServer.getQueue()
assert.equal(queue[0].MessageBody, 'my message')
assert.equal(queue.length, 1)
await myServer.close()
}
process.on('unhandledReject', (err) => { throw err })
test()
Create a fake SQS server
opts.port
; defaults to 0
Starts the server.
After bootstrap returns you can read server.hostPort
to get
the actual listening port of the server.
Returns the current array of items queued in SQS. These are shaped like aws SQS objects.
Get notified once N messages have in total been sent to this fake SQS.
Get notified once N messages have in total been deleted from this fake SQS.
Get notified when the number of pending messages in the SQS queue is zero.
This can be used with waitForMessages()
to first wait for N
messages to be send and then wait for them to have been received
and deleted from the queue.
Closes the underlying http server.
% npm install fake-sqs