Skip to content
Snippets Groups Projects
Commit 60d6859a authored by Jason Mulligan's avatar Jason Mulligan
Browse files

Adding a missing worker method (`close()`), adding tests

parent 6eba157e
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,9 @@ module.exports = function (grunt) {
eslint: {
target: ["src/*.js"]
},
nodeunit : {
all : ["test/*_test.js"]
},
watch : {
js : {
files : ["src/*.js"],
......@@ -31,12 +34,13 @@ module.exports = function (grunt) {
});
// tasks
grunt.loadNpmTasks("grunt-contrib-nodeunit");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-babel");
grunt.loadNpmTasks("grunt-eslint");
// aliases
grunt.registerTask("test", ["eslint"]);
grunt.registerTask("test", ["eslint", "nodeunit"]);
grunt.registerTask("build", ["babel"]);
grunt.registerTask("default", ["build", "test"]);
};
......@@ -26,6 +26,9 @@ process.once("message", function (obj) {
sexp = undefined;
global.self = {
close: function close() {
process.exit(0);
},
postMessage: function postMessage(msg) {
process.send(JSON.stringify({ data: msg }));
},
......
{
"name": "tiny-worker",
"version": "1.0.3",
"version": "1.0.4",
"description": "Tiny WebWorker for Server",
"main": "lib/index.js",
"scripts": {
......@@ -27,6 +27,7 @@
"grunt": "^0.4.5",
"grunt-babel": "^5.0.0",
"grunt-cli": "^0.1.13",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-eslint": "^17.1.0"
},
......
......@@ -24,6 +24,9 @@ process.once("message", function (obj) {
sexp;
global.self = {
close: function () {
process.exit(0);
},
postMessage: function (msg) {
process.send(JSON.stringify({data: msg}));
},
......
self.onmessage = function (ev) {
postMessage(ev.data);
};
\ No newline at end of file
var path = require("path"),
Worker = require(path.join("..", "lib", "index.js"));
exports["external script"] = {
setUp: function (done) {
this.worker = new Worker(path.join(__dirname, "worker_repeater.js"));
this.msg = "Hello World!";
this.response = "";
done();
},
test: function (test) {
var self = this;
test.expect(2);
test.notEqual(this.msg, this.response, "Should not match");
this.worker.onmessage = function (ev) {
self.response = ev.data;
self.worker.terminate();
test.equal(self.msg, self.response, "Should be a match");
test.done();
};
this.worker.postMessage(this.msg);
}
};
exports["inline script"] = {
setUp: function (done) {
this.worker = new Worker(function () {
self.onmessage = function (ev) {
postMessage(ev.data);
};
});
this.msg = "Hello World!";
this.response = "";
done();
},
test: function (test) {
var self = this;
test.expect(2);
test.notEqual(this.msg, this.response, "Should not match");
this.worker.onmessage = function (ev) {
self.response = ev.data;
self.worker.terminate();
test.equal(self.msg, self.response, "Should be a match");
test.done();
};
this.worker.postMessage(this.msg);
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment