scratch-vm/test/fixtures/dispatch-test-worker-shim.js
Christopher Willis-Ford 0fcc248ac1 Add tests for message dispatch system; fix bugs
The tests run using TinyWorker, which emulates web workers on Node.
There are quite a few quirks in that situation due to the differences
between Node and Webpack as well as the differences between TinyWorker
and real Web Workers.

The tests also exposed a few bugs in the dispatch system, which have now
been fixed. Most notably, if a method called through the dispatch system
throws an exception that exception will now be passed back to the
caller. Previously the exception would escape the dispatch system and
the caller would never hear any response at all.
2017-07-21 13:23:52 -07:00

19 lines
569 B
JavaScript

const Module = require('module');
const callsite = require('callsite');
const path = require('path');
const oldRequire = Module.prototype.require;
Module.prototype.require = function (target) {
if (target.indexOf('/') === -1) {
return oldRequire.apply(this, arguments);
}
const stack = callsite();
const callerFile = stack[2].getFileName();
const callerDir = path.dirname(callerFile);
target = path.resolve(callerDir, target);
return oldRequire.call(this, target);
};
oldRequire(path.resolve(__dirname, 'dispatch-test-worker'));