pokemon-showdown/test/sim/misc/state.js
Guangcong Luo 78439b4a02
Update to ESLint 9 (#10926)
ESLint has a whole new config format, so I figure it's a good time to
make the config system saner.

- First, we no longer have separate eslint-no-types configs. Lint
  performance shouldn't be enough of a problem to justify the
  relevant maintenance complexity.

- Second, our base config should work out-of-the-box now. `npx eslint`
  will work as expected, without any CLI flags. You should still use
  `npm run lint` which adds the `--cached` flag for performance.

- Third, whatever updates I did fixed style linting, which apparently
  has been bugged for quite some time, considering all the obvious
  mixed-tabs-and-spaces issues I found in the upgrade.

Also here are some changes to our style rules. In particular:

- Curly brackets (for objects etc) now have spaces inside them. Sorry
  for the huge change. ESLint doesn't support our old style, and most
  projects use Prettier style, so we might as well match them in this way.
  See https://github.com/eslint-stylistic/eslint-stylistic/issues/415

- String + number concatenation is no longer allowed. We now
  consistently use template strings for this.
2025-02-25 20:03:46 -08:00

53 lines
2.3 KiB
JavaScript

'use strict';
const assert = require('./../../assert');
const common = require('./../../common');
const Battle = require('./../../../dist/sim/battle').Battle;
const State = require('./../../../dist/sim/state').State;
const TEAMS = [[
{ species: 'Mew', ability: 'synchronize', item: 'assaultvest', moves: ['psychic'] },
{ species: 'Ditto', ability: 'imposter', item: 'choicescarf', moves: ['transform'] },
{ species: 'Amoonguss', ability: 'effectspore', item: 'blacksludge', moves: ['toxic'] },
{ species: 'Gliscor', ability: 'poisonheal', item: 'toxicorb', moves: ['curse'] },
{ species: 'Zoroark', ability: 'illusion', item: 'leftovers', moves: ['knockoff'] },
{ species: 'Gengar', ability: 'cursedbody', item: 'brightpowder', moves: ['disable'] },
], [
{ species: 'Ninjask', ability: 'speedboost', item: 'rockyhelmet', moves: ['batonpass'] },
{ species: 'Hippowdon', ability: 'sandstream', item: 'choiceband', moves: ['earthquake'] },
{ species: 'Jirachi', ability: 'serenegrace', item: 'choicescarf', moves: ['ironhead'] },
{ species: 'Chansey', ability: 'naturalcure', item: 'eviolite', moves: ['seismictoss'] },
{ species: 'Vaporeon', ability: 'waterabsorb', item: 'wacanberry', moves: ['surf'] },
{ species: 'Snorlax', ability: 'thickfat', item: 'leftovers', moves: ['rest'] },
]];
describe('State', () => {
describe('Battles', () => {
it('should be able to be serialized and deserialized without affecting functionality (slow)', function () {
this.timeout(5000);
const control = common.createBattle({ seed: 'sodium,00000001000000020000000300000004' }, TEAMS);
let test = common.createBattle({ seed: 'sodium,00000001000000020000000300000004' }, TEAMS);
while (!(control.ended || test.ended)) {
control.makeChoices();
test.makeChoices();
assert.deepEqual(State.normalize(test.toJSON()), State.normalize(control.toJSON()));
// Roundtrip the test battle to confirm it still works.
const send = test.send;
test = Battle.fromJSON(JSON.stringify(test));
test.restart(send);
}
control.destroy();
test.destroy();
});
it('should require special treatment for complex objects', () => {
const battle = common.createBattle(TEAMS);
battle.foo = new Map();
assert.throws(() => battle.toJSON(), /Unsupported type Map/);
});
});
});