tools/client/test_resource_pickup_cold.mjs (2120B)
1 import assert from 'node:assert/strict'; 2 import fs from 'node:fs/promises'; 3 import {createRequire} from 'node:module'; 4 import {GameTest} from './game_test.mjs'; 5 6 const {chromium} = createRequire(import.meta.url)('playwright'); 7 const [url, output] = process.argv.slice(2); 8 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [ 9 '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', 10 '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); 11 const games = []; 12 try { 13 for (const index of [0, 1]) { 14 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 15 await context.addCookies([{name: 'ao_client', value: 'resource-pickup-' + index, url}]); 16 const page = await context.newPage(), game = await GameTest.attach(page); 17 games.push(game); 18 await page.goto(url); 19 await game.ready(); 20 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 21 await game.snapshot(); 22 } 23 const [owner, observer] = games; 24 const state = await (await owner.page.request.get(url + '/test-state')).json(); 25 assert.deepEqual(owner.local().inventory, [{slot: 48, type: 51005, id: state.item, quality: 1, 26 templates: [150274, 150274], count: 1}]); 27 assert.deepEqual(observer.local().inventory, []); 28 assert.equal(state.onGround, false); 29 assert.equal(state.depleted, true); 30 assert.equal(state.inventory.Credits, 0); 31 assert.equal(state.inventory.Items[0].ID, state.item); 32 for (const game of games) assert(!game.state.actors.some(actor => actor.type === 51005 && actor.id === state.item)); 33 await owner.key('KeyI'); 34 assert(games.every(game => game.errors.length === 0)); 35 await fs.mkdir(output, {recursive: true}); 36 await fs.writeFile(output + '/verification.json', JSON.stringify(state, null, 2) + '\n'); 37 console.log('PASS: cold resource identity, selected quality, inventory and independent depletion remain exact'); 38 } finally { 39 try { await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); } 40 finally { await browser.close(); } 41 }