Open UFOMelkor opened 3 years ago
Yeah, when 0.8 was back in alpha or beta I did a bit of investigation and ran into the same sort of things. I suspect it has to do with how I'm importing mocha and chai, but I didn't get the chance to fully figure out what the issue was or how to fix it. For the moment I can't really dedicate time to investigating it unfortunately, but I'm sure there is some sort of solution that could be reached.
I guess it is about the globalThis
while importing, but still not sure. Will investigate and report :-)
I guess I could enclose the problem.
Hooks do not support async functions. Hence, while quenchInit
is executed, other functions are also executed. They access CONFIG.DatabaseBackend
and some classes like CONFIG.Combatant
. I guess it are the classes whose objects are contained by objects of other classes (like Combatant
is by Combat
).
For me, it works when changing globalThis
as follows. I might be missing some classes because not everything is used in my current world. Perhaps CONFIG: oldGlobal.CONFIG
is a better variant.
I do not know whether this helps, because I don't know what mocha does with the globals.
globalThis = {
Date: oldGlobal.Date,
setTimeout: oldGlobal.setTimeout,
setInterval: oldGlobal.setInterval,
clearTimeout: oldGlobal.clearTimeout,
clearInterval: oldGlobal.clearInterval,
onerror: oldGlobal.onerror,
location: oldGlobal.location,
document: oldGlobal.document,
CONFIG: {
ActiveEffect: oldGlobal.CONFIG.ActiveEffect,
AmbientLight: oldGlobal.CONFIG.AmbientLight,
AmbientSound: oldGlobal.CONFIG.AmbientSound,
Combatant: oldGlobal.CONFIG.Combatant,
DatabaseBackend: oldGlobal.CONFIG.DatabaseBackend,
Drawing: oldGlobal.CONFIG.Drawing,
FogExploration: oldGlobal.CONFIG.FogExploration,
JournalEntry: oldGlobal.CONFIG.JournalEntry,
MeasuredTemplate: oldGlobal.CONFIG.MeasuredTemplate,
Note: oldGlobal.CONFIG.Note,
Playlist: oldGlobal.CONFIG.Playlist,
PlaylistSound: oldGlobal.CONFIG.PlaylistSound,
TableResult: oldGlobal.CONFIG.TableResult,
Tile: oldGlobal.CONFIG.Tile,
Token: oldGlobal.CONFIG.Token,
Wall: oldGlobal.CONFIG.Wall,
},
};
Dancing with the definition of globalThis is a risky business, especially in an async environment.
I tried just loading mocha
and chai
at the top of the module, and the chief issue we encounter is that Foundry is injecting a ui
member into globalThis.mocha
, thereby overwriting mocha's own ui
member. This then causes mocha to fail during startup
when it starts running tests, as it expects ui to be a function it uses for delivering results. If there is some kind of exclude list for Foundry injecting ui into globals, that might let the straightforward approach work.
I've found a way around this issue that doesn't involve messing with globalThis. It does involve bumping mocha to 9.x and applying a three line hack near the end of it:
// Wicked hack for Quench -
// get ui property out of copy of global merged with mocha before merging
// so it doesn't clobber mocha's ui function
var hackedCommonJsGlobal = Object.assign({}, commonjsGlobal);
delete hackedCommonJsGlobal.ui;
var browserEntry = Object.assign(mocha, hackedCommonJsGlobal);
// Original implementation:
//var browserEntry = Object.assign(mocha, commonjsGlobal);
This modified mocha can be used as you'd expect to be able to use it.
Hey,
first, thank you for this module. I run a lot of unit tests, but Quench looks like the missing part to test the things I could not test until now. Currently, my system still uses Foundry VTT 0.7.x, but I'd like to upgrade soon. Writing tests before upgrading is great, but only if the test runner works under the new version too ;-)
I know that the module.json says 0.7.9. I looked through your source code and could not find anything that prevents Quench from running with 0.8.8. Hence, I tried and got some really strange errors (with DnD5e as System and without running any tests). The errors occur even if I do not run the tests on startup or disable the Quench dialog on startup.
Do you have any idea what the origin of this problem might be?