55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
// About me: Loads the built bundle the way Vortex does - require() with a stubbed
|
|
// `vortex-api` - and drives registerGame/registerInstaller against a fake context.
|
|
// This catches packaging mistakes (bad export shape, missing external) that unit
|
|
// tests on the source cannot see. Run with: node scripts/smoke-load.cjs
|
|
const Module = require('node:module');
|
|
const path = require('node:path');
|
|
|
|
const originalLoad = Module._load;
|
|
Module._load = function patchedLoad(request, parent, isMain) {
|
|
if (request === 'vortex-api') {
|
|
return { log: (level, message) => console.log(` [vortex-api ${level}] ${message}`) };
|
|
}
|
|
return originalLoad.call(this, request, parent, isMain);
|
|
};
|
|
|
|
const extension = require(path.resolve(__dirname, '../dist/index.js'));
|
|
const main = extension.default ?? extension;
|
|
|
|
const registered = { games: [], installers: [] };
|
|
const context = {
|
|
registerGame: (game) => registered.games.push(game),
|
|
registerInstaller: (id, priority, testSupported, install) =>
|
|
registered.installers.push({ id, priority, testSupported, install }),
|
|
once: (cb) => cb(),
|
|
api: {},
|
|
};
|
|
|
|
const result = main(context);
|
|
console.log('main() returned:', result);
|
|
|
|
const game = registered.games[0];
|
|
console.log('game id:', game.id);
|
|
console.log('executable:', game.executable());
|
|
console.log('queryModPath:', JSON.stringify(game.queryModPath('')));
|
|
console.log('queryPath():', game.queryPath());
|
|
|
|
const installer = registered.installers[0];
|
|
installer
|
|
.testSupported(['a.archive'], game.id)
|
|
.then((supported) => {
|
|
console.log('testSupported:', JSON.stringify(supported));
|
|
return installer.install(
|
|
['Cool Mod v1\\archive\\pc\\mod\\cool.archive', 'Cool Mod v1\\readme.txt'],
|
|
'Z:\\staging\\Cool Mod-1234.installing',
|
|
game.id,
|
|
);
|
|
})
|
|
.then((res) => {
|
|
console.log('install instructions:', JSON.stringify(res.instructions, null, 2));
|
|
})
|
|
.catch((err) => {
|
|
console.error('smoke failed:', err);
|
|
process.exitCode = 1;
|
|
});
|