forked from phenom/healer-man
111 lines
6.2 KiB
JavaScript
111 lines
6.2 KiB
JavaScript
const { chromium } = require('C:/Users/phenom/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const zlib = require('node:zlib');
|
|
const assert = require('node:assert/strict');
|
|
const directory = path.resolve('playtest-artifacts/dungeon-health-scaling');
|
|
fs.mkdirSync(directory, { recursive: true });
|
|
const catalogSource = fs.readFileSync('src/game/generated/dungeonCampaignCatalog.compressed.ts', 'utf8');
|
|
const catalog = JSON.parse(zlib.gunzipSync(Buffer.from(catalogSource.match(/"([A-Za-z0-9+/=]+)"/)[1], 'base64')));
|
|
const dungeon = catalog.definitions.find((entry) => entry.id === 'stormwind-stockade');
|
|
const boss = dungeon.bosses[0];
|
|
|
|
(async () => {
|
|
const { createGameServer } = await import('../server/server.mjs');
|
|
const runtime = createGameServer({ dataDir: path.join(directory, 'test-database'), enableShelvedModes: false });
|
|
await new Promise((resolve) => runtime.server.listen(4190, '127.0.0.1', resolve));
|
|
const browser = await chromium.launch({ channel: 'msedge', headless: true });
|
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
page.setDefaultTimeout(90000);
|
|
const errors = [];
|
|
page.on('pageerror', (error) => errors.push(error.message));
|
|
const files = fs.readdirSync('dist/assets');
|
|
const mainModule = `/assets/${files.find((file) => /^index-.*\.js$/.test(file))}`;
|
|
const combatModule = `/assets/${files.find((file) => /^combatStore-.*\.js$/.test(file))}`;
|
|
await page.addInitScript(({ mainModule, combatModule }) => {
|
|
window.healthTestStores = async () => {
|
|
const exports = [...Object.values(await import(mainModule)), ...Object.values(await import(combatModule))];
|
|
return {
|
|
game: exports.find((value) => value?.getState && 'bossTest' in value.getState()),
|
|
shell: exports.find((value) => value?.getState && 'characters' in value.getState()),
|
|
combat: exports.find((value) => value?.getState && 'damageMob' in value.getState()),
|
|
party: exports.find((value) => value?.getState && 'categoryId' in value.getState() && 'members' in value.getState()),
|
|
};
|
|
};
|
|
}, { mainModule, combatModule });
|
|
try {
|
|
await page.goto('http://127.0.0.1:4190', { waitUntil: 'domcontentloaded' });
|
|
await page.getByRole('button', { name: /Play offline/ }).click();
|
|
await page.getByRole('button', { name: /Create character/ }).click();
|
|
await page.getByRole('button', { name: /Customize & name/ }).click();
|
|
await page.getByLabel('Character name').fill('Healthtester');
|
|
await page.getByRole('button', { name: /Create character/ }).click();
|
|
await page.getByRole('button', { name: /Continue|Enter world/ }).first().click();
|
|
await page.locator('.main-menu-screen').waitFor();
|
|
// Isolated level-three profile fixture; dungeon entry and registration use the normal UI.
|
|
await page.evaluate(async () => {
|
|
const { shell } = await window.healthTestStores();
|
|
const state = shell.getState();
|
|
const character = state.characters.find((entry) => entry.id === state.selectedCharacterId);
|
|
shell.setState({ activeCharacter: character });
|
|
shell.getState().saveActiveProgression(3, 0, character.talentRanks);
|
|
shell.setState({ activeCharacter: null });
|
|
});
|
|
await page.getByRole('button', { name: /^Dungeons/ }).click();
|
|
await page.locator('.dungeon-select-row').filter({ hasText: /Stockade/i }).click();
|
|
await page.getByRole('button', { name: 'Download and continue', exact: true }).click();
|
|
await page.locator('.dungeon-role-option--healer').click();
|
|
await page.evaluate(async () => {
|
|
const { game } = await window.healthTestStores();
|
|
game.getState().openOverlay('pause');
|
|
});
|
|
await page.waitForFunction(async () => {
|
|
const { game, combat } = await window.healthTestStores();
|
|
return game.getState().assetStatus === 'ready' && combat.getState().level === 3;
|
|
});
|
|
await page.waitForTimeout(10000);
|
|
await page.evaluate(async (boss) => {
|
|
const { game, combat, party } = await window.healthTestStores();
|
|
party?.getState().setCommand('stop');
|
|
game.getState().relocatePlayer({ footPosition: [boss.position[0], boss.position[1], boss.position[2] + 5], yaw: Math.PI });
|
|
combat.getState().setPlayerPosition(game.getState().playerPosition);
|
|
}, boss);
|
|
await page.waitForFunction(async (id) => {
|
|
const { combat } = await window.healthTestStores();
|
|
return combat.getState().level === 3 && combat.getState().mobs[id]?.maxHealth === 1300;
|
|
}, boss.id);
|
|
const result = await page.evaluate(async (id) => {
|
|
const { game, combat } = await window.healthTestStores();
|
|
const state = combat.getState();
|
|
state.selectMob(id);
|
|
game.getState().closeOverlay();
|
|
return { dungeonId: game.getState().activeDungeonId, gameMode: game.getState().gameMode,
|
|
bossTest: game.getState().bossTest, bossDifficulty: game.getState().activeBossDifficulty,
|
|
classId: state.classId, characterLevel: state.level, boss: state.mobs[id].name,
|
|
bossLevel: state.mobs[id].level, bossMaxHealth: state.mobs[id].maxHealth };
|
|
}, boss.id);
|
|
assert.equal(result.dungeonId, 'stormwind-stockade');
|
|
assert.equal(result.gameMode, 'dungeon');
|
|
assert.equal(result.bossTest, null);
|
|
assert.equal(result.bossDifficulty, 1);
|
|
assert.equal(result.classId, 'priest');
|
|
assert.equal(result.characterLevel, 3);
|
|
assert.equal(result.bossLevel, 4);
|
|
assert.equal(result.bossMaxHealth, 1300);
|
|
await page.waitForTimeout(1500);
|
|
await page.screenshot({ path: path.join(directory, 'stockades-level-three.png') });
|
|
assert.deepEqual(errors, []);
|
|
fs.writeFileSync(path.join(directory, 'results.json'), `${JSON.stringify({ passed: true, ...result, errors }, null, 2)}\n`);
|
|
console.log(JSON.stringify(result, null, 2));
|
|
console.log('Regular dungeon health playtest passed');
|
|
} catch (error) {
|
|
await page.screenshot({ path: path.join(directory, 'failure.png') });
|
|
console.log((await page.locator('body').innerText()).slice(-2000));
|
|
console.log('Browser errors:', errors);
|
|
throw error;
|
|
} finally {
|
|
await browser.close();
|
|
await new Promise((resolve) => runtime.server.close(resolve));
|
|
}
|
|
})().catch((error) => { console.error(error); process.exitCode = 1; });
|