mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-27 07:40:48 +00:00
0d30a5528e
tests/parser/parserTests.js. * Removed var from es in es.js to allow node.js to access it as global. Only alternative solution appears to be a node-specific 'exports' construct: http://nodejs.org/docs/v0.3.1/api/modules.html * Added es.Document.js and es.Document.Serializer.js in es/bases. Not sure if this is the desired location. * Changed es.extend to es.extendClass in the serializers * Modified the first parser test to include the WikiDom modules and call the new HTML serializer
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
var path = require('path');
|
|
|
|
// Fake a worker-like interface so we can test it in-process
|
|
// workers in node's webworker module don't seem to report errors very well.
|
|
if (typeof module == "object") {
|
|
module.exports = {
|
|
postMessage: function(data) {
|
|
var msg = {data: JSON.parse(JSON.stringify(data))};
|
|
setTimeout(function() {
|
|
onmessage(msg);
|
|
}, 0);
|
|
},
|
|
onmessage: function(msg) {}
|
|
};
|
|
|
|
if (typeof postMessage === 'undefined') {
|
|
postMessage = function(data) {
|
|
var msg = {data: JSON.parse(JSON.stringify(data))};
|
|
setTimeout(function() {
|
|
module.exports.onmessage(msg)
|
|
}, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
// The worker context for some reason doesn't let us adjust globals,
|
|
// so farming the good stuff out to a module which can.
|
|
var didInit = false;
|
|
var myWorker = {
|
|
postMessage: postMessage,
|
|
onmessage: function(msg) {
|
|
var data = msg.data;
|
|
if (data.action == 'init') {
|
|
if (didInit) {
|
|
throw new Error('second init request');
|
|
}
|
|
// Running as a worker in node.js we have to set the working directory
|
|
// or we won't be able to find our local files.
|
|
//
|
|
// It's a bit annoying. ;)
|
|
process.chdir(data.dir);
|
|
require(path.join(data.dir, 'roundtrip-test.js')).init(myWorker);
|
|
didInit = true;
|
|
} else {
|
|
throw new Error('Must init first!');
|
|
}
|
|
}
|
|
};
|
|
|
|
onmessage = function(msg) {
|
|
return myWorker.onmessage(msg);
|
|
}
|
|
|