aorecomp

Anarchy Online classic in the browser

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


tests/e2e/options.test.mjs (2027B)


      1 import assert from 'node:assert/strict';
      2 import {before, test} from 'node:test';
      3 import {buildServer, withFixture} from './fixture.mjs';
      4 
      5 before(buildServer);
      6 
      7 test('Options opens without waiting for account information or fetching it again',
      8 {timeout: 240_000}, async () => withFixture('options', async fixture => {
      9   const context = await fixture.visitor();
     10   let release, requests = 0;
     11   const held = new Promise(resolve => { release = resolve; });
     12   await context.route('**/browser-account', async route => {
     13     ++requests;
     14     await held;
     15     await route.continue();
     16   });
     17   try {
     18     const game = await fixture.game(context);
     19     const page = game.page;
     20 
     21     // Keep the lookup pending while real browser input opens and uses Options.
     22     await page.keyboard.press('Control+Alt+M');
     23     assert.equal(await page.locator('#create-button').isEnabled(), true);
     24     assert.equal(await page.locator('#login-button').isEnabled(), true);
     25     await page.locator('#login-button').click();
     26     assert.equal(await page.locator('#account-form').isVisible(), true);
     27     await page.locator('#account-back').click();
     28     release();
     29     await page.locator('#claim-button').waitFor({state: 'visible'});
     30     await page.keyboard.press('Control+Alt+M');
     31     await page.keyboard.press('Control+Alt+M');
     32     assert.equal(await page.locator('#claim-button').isEnabled(), true);
     33     assert.equal(requests, 1);
     34     await game.save(fixture.output + '/instant-options');
     35 
     36     // Measure the authenticated endpoint with the full native client running.
     37     const milliseconds = [];
     38     for (let index = 0; index < 10; ++index) {
     39       const start = performance.now();
     40       const response = await context.request.get(fixture.url + '/browser-account');
     41       assert.equal(response.status(), 200);
     42       milliseconds.push(performance.now() - start);
     43     }
     44     console.log('Authenticated account HTTP timings (ms): ' + milliseconds.map(value => value.toFixed(1)).join(', '));
     45     assert.deepEqual(game.errors, []);
     46   } finally {
     47     release();
     48   }
     49 }));