Skip to content

Commit

Permalink
Add a quick unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhead committed Sep 12, 2020
1 parent 033fbfd commit 6293609
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Native System V message queues in Node.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jasmine spec/**/*.js",
"install": "node-gyp rebuild"
},
"repository": {
Expand All @@ -30,5 +30,8 @@
"homepage": "https://github.com/jhead/node-svmq#readme",
"dependencies": {
"nan": "^2.2.0"
},
"devDependencies": {
"jasmine": "^3.6.1"
}
}
32 changes: 32 additions & 0 deletions spec/queueSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const MessageQueue = require('../');

const inputs = [
Buffer.alloc(0),
Buffer.from(""),
Buffer.from("test"),
Buffer.from("test 1234 foo bar 567890"),
Buffer.from([1, 2, 3, 4]),
Buffer.from(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])),
Buffer.alloc(1024)
];

describe("MessageQueue", function () {

// Test a batch of diverse inputs that should be supported
inputs.forEach((input, index) =>{
const msgType = index + 1;
const selectedInput = input;

it("push and pop a message: " + selectedInput, function (done) {
const queue = new MessageQueue(31337);

queue.push(selectedInput, { type: msgType })
queue.pop({ type: msgType }, function(err, msg) {
expect(err).toBeNull();
expect(msg).toEqual(selectedInput);
done();
})
});
})

});
11 changes: 11 additions & 0 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}

0 comments on commit 6293609

Please sign in to comment.