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

Adding `__filename` & `__dirname` variables to worker context, fixes #5

parent 0fef420c
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,8 @@ process.once("message", function (obj) { ...@@ -41,6 +41,8 @@ process.once("message", function (obj) {
} }
}; };
global.__dirname = __dirname;
global.__filename = __filename;
global.require = require; global.require = require;
global.importScripts = function () { global.importScripts = function () {
......
{ {
"name": "tiny-worker", "name": "tiny-worker",
"version": "1.1.5", "version": "1.1.6",
"description": "Tiny WebWorker for Server", "description": "Tiny WebWorker for Server",
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
......
...@@ -39,6 +39,8 @@ process.once("message", obj => { ...@@ -39,6 +39,8 @@ process.once("message", obj => {
} }
}; };
global.__dirname = __dirname;
global.__filename = __filename;
global.require = require; global.require = require;
global.importScripts = (...files) => { global.importScripts = (...files) => {
......
...@@ -56,7 +56,7 @@ exports["inline script"] = { ...@@ -56,7 +56,7 @@ exports["inline script"] = {
exports["inline script - require"] = { exports["inline script - require"] = {
setUp: function (done) { setUp: function (done) {
this.worker = new Worker(function () { this.worker = new Worker(function () {
self.onmessage = function (ev) { self.onmessage = function () {
postMessage(typeof require); postMessage(typeof require);
}; };
}); });
...@@ -80,3 +80,59 @@ exports["inline script - require"] = { ...@@ -80,3 +80,59 @@ exports["inline script - require"] = {
this.worker.postMessage(this.msg); this.worker.postMessage(this.msg);
} }
}; };
exports["inline script - __dirname"] = {
setUp: function (done) {
this.worker = new Worker(function () {
self.onmessage = function () {
postMessage(typeof __dirname);
};
});
this.msg = "What is __dirname?";
this.expected = "string";
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.expected, self.response, "Should be a match");
test.done();
};
this.worker.postMessage(this.msg);
}
};
exports["inline script - __filename"] = {
setUp: function (done) {
this.worker = new Worker(function () {
self.onmessage = function () {
postMessage(typeof __filename);
};
});
this.msg = "What is __filename?";
this.expected = "string";
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.expected, 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