aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tests/e2e/starter-cold.mjs (2487B)


      1 import assert from 'node:assert/strict';
      2 import fs from 'node:fs/promises';
      3 import {GameTest} from '../../tools/client/game_test.mjs';
      4 
      5 export async function checkStarterCold(browser, url, output, readState) {
      6   const games = [];
      7   const evidence = {};
      8   try {
      9     for (const name of ['Starterowner', 'Starterwatch']) {
     10       const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     11       const page = await context.newPage();
     12       const game = await GameTest.attach(page);
     13       games.push(game);
     14       await page.goto(url);
     15       await game.ready();
     16       await page.keyboard.press('Control+Alt+M');
     17       await page.locator('#login-button').click();
     18       await page.locator('#account-name').fill(name);
     19       await page.locator('#account-password').fill('starter regression password');
     20       await Promise.all([page.waitForEvent('load'), page.locator('#account-submit').click()]);
     21       await game.ready();
     22       const state = await readState(page);
     23       assert.equal(state.name, name);
     24       assert.equal(game.local().playfield, state.playfield);
     25       assert.equal(game.local().stats[54], state.level);
     26       assert.equal(game.local().stats[52], state.experience);
     27       assert.equal(game.local().stats[53], state.ip);
     28       assert.equal(game.local().stats[61], state.credits);
     29       assert.equal(game.local().stats[27], state.health);
     30       assert.equal(game.local().stats[1], state.maximumHealth);
     31       const expected = state.items.map(([id, type, slot, quality, count, low, high]) =>
     32         [id, type, slot >= 64 ? slot - 16 : slot, quality, count, low, high]).sort((a, b) => a[0] - b[0]);
     33       const actual = game.local().inventory.map(item =>
     34         [item.id, item.type, item.slot, item.quality, item.count, ...item.templates]).sort((a, b) => a[0] - b[0]);
     35       assert.deepEqual(actual, expected);
     36       assert.deepEqual(game.errors, []);
     37       evidence[name] = state;
     38       await game.key('KeyI');
     39       await game.save(output + '/' + name);
     40     }
     41     assert.equal(evidence.Starterowner.level, 2);
     42     assert.equal(evidence.Starterwatch.level, 1);
     43     assert.equal(evidence.Starterwatch.credits, 0);
     44     assert.equal(evidence.Starterwatch.ip, 1500);
     45     return evidence;
     46   } finally {
     47     await fs.mkdir(output, {recursive: true});
     48     await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
     49     for (let index = 0; index < games.length; ++index) await games[index].save(output + '/final-' + index);
     50   }
     51 }