mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
0fcc248ac1
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.
19 lines
569 B
JavaScript
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'));
|