mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-04-04 08:05:35 -05:00
It turns out that when I switched us from `assert` to `assert.strict`,
I didn't actually update any existing tests or tell anyone:
0df0d234f2
So apparently everyone else just kept on using `strictEqual`.
This will be a PR and also throw an error if people continue trying to
use it, which should make it much clearer what PS policy is on this.
A lot of the problem may be that TypeScript marks assert.strict.equal
as deprecated when it's not. This was fixed 4 days ago:
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/48452
But this probably hasn't made it to a thing yet. Until then, you'll
have to deal with TS marking your tests as deprecated, but it shouldn't
be too long.
Accidentally using `assert` instead of `assert.strict` should now show
an error. This protects against the probably much worse mistake of
accidentally using `assert.equal` rather than `assert.strict.equal`.
`assert.ok` is also deprecated now.
145 lines
4.1 KiB
JavaScript
145 lines
4.1 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert').strict;
|
|
|
|
global.Ladders = require('../../.server-dist/ladders').Ladders;
|
|
const {Connection, User} = require('../users-utils');
|
|
|
|
describe('Matchmaker', function () {
|
|
const FORMATID = 'gen7ou';
|
|
const addSearch = (player, rating = 1000, formatid = FORMATID) => {
|
|
const search = new Ladders.BattleReady(player.id, formatid, player.battleSettings, rating);
|
|
Ladders(formatid).addSearch(search, player);
|
|
return search;
|
|
};
|
|
const destroyPlayer = player => {
|
|
player.resetName();
|
|
player.disconnectAll();
|
|
player.destroy();
|
|
return null;
|
|
};
|
|
|
|
before(function () {
|
|
clearInterval(Ladders.periodicMatchInterval);
|
|
Ladders.periodicMatchInterval = null;
|
|
});
|
|
|
|
beforeEach(function () {
|
|
this.p1 = new User(new Connection('127.0.0.1'));
|
|
this.p1.forceRename('Morfent', true);
|
|
this.p1.connected = true;
|
|
this.p1.battleSettings.team = 'Gengar||||lick||252,252,4,,,|||||';
|
|
Users.users.set(this.p1.id, this.p1);
|
|
|
|
this.p2 = new User(new Connection('0.0.0.0'));
|
|
this.p2.forceRename('Mrofnet', true);
|
|
this.p2.connected = true;
|
|
this.p2.battleSettings.team = 'Gengar||||lick||252,252,4,,,|||||';
|
|
Users.users.set(this.p2.id, this.p2);
|
|
});
|
|
|
|
afterEach(function () {
|
|
this.p1 = destroyPlayer(this.p1);
|
|
this.p2 = destroyPlayer(this.p2);
|
|
});
|
|
|
|
it('should add a search', function () {
|
|
const s1 = addSearch(this.p1);
|
|
assert(Ladders.searches.has(FORMATID));
|
|
|
|
const formatSearches = Ladders.searches.get(FORMATID);
|
|
assert(formatSearches instanceof Map);
|
|
assert.equal(formatSearches.size, 1);
|
|
assert.equal(s1.userid, this.p1.id);
|
|
assert.equal(s1.team, this.p1.battleSettings.team);
|
|
assert.equal(s1.rating, 1000);
|
|
});
|
|
|
|
it('should matchmake users when appropriate', function () {
|
|
addSearch(this.p1);
|
|
addSearch(this.p2);
|
|
assert.equal(Ladders.searches.get(FORMATID).size, 0);
|
|
});
|
|
|
|
it('should matchmake users within a reasonable rating range', function () {
|
|
addSearch(this.p1);
|
|
addSearch(this.p2, 2000);
|
|
assert.equal(Ladders.searches.get(FORMATID).size, 2);
|
|
});
|
|
|
|
it('should cancel searches', function () {
|
|
addSearch(this.p1);
|
|
Ladders(FORMATID).cancelSearch(this.p1);
|
|
Ladders.cancelSearches(this.p2);
|
|
assert.equal(Ladders.searches.get(FORMATID).size, 0);
|
|
});
|
|
|
|
it('should periodically matchmake users when appropriate', function () {
|
|
addSearch(this.p1);
|
|
const s2 = addSearch(this.p2, 2000);
|
|
assert.equal(Ladders.searches.get(FORMATID).size, 2);
|
|
|
|
s2.rating = 1000;
|
|
Ladders.Ladder.periodicMatch();
|
|
assert.equal(Ladders.searches.get(FORMATID).size, 0);
|
|
});
|
|
|
|
it('should create a new battle room after matchmaking', function () {
|
|
assert.equal(this.p1.games.size, 0);
|
|
addSearch(this.p1);
|
|
addSearch(this.p2);
|
|
assert.equal(this.p1.games.size, 1);
|
|
for (const roomid of this.p1.games) {
|
|
assert(Rooms.get(roomid).battle);
|
|
}
|
|
});
|
|
|
|
it('should cancel search on disconnect', function () {
|
|
addSearch(this.p1);
|
|
this.p1.onDisconnect(this.p1.connections[0]);
|
|
assert.equal(Ladders.searches.get(FORMATID).size, 0);
|
|
});
|
|
|
|
it('should cancel search on merge', function () {
|
|
addSearch(this.p1);
|
|
this.p2.merge(this.p1);
|
|
assert.equal(Ladders.searches.get(FORMATID).size, 0);
|
|
});
|
|
|
|
describe('#startBattle', function () {
|
|
beforeEach(function () {
|
|
this.s1 = addSearch(this.p1);
|
|
this.s2 = addSearch(this.p2);
|
|
});
|
|
|
|
afterEach(function () {
|
|
this.s1 = null;
|
|
this.s2 = null;
|
|
});
|
|
|
|
it('should prevent battles from starting if both players are identical', function () {
|
|
Object.assign(this.s2, this.s1);
|
|
let room;
|
|
try {
|
|
room = Rooms.createBattle(FORMATID, {p1: this.p1, p2: this.p1, p1team: this.s1.team, p2team: this.s2.team, rated: 1000});
|
|
} catch (e) {}
|
|
assert.equal(room, undefined);
|
|
});
|
|
|
|
before(function () {
|
|
this.lockdown = Rooms.global.lockdown;
|
|
Rooms.global.lockdown = true;
|
|
});
|
|
|
|
after(function () {
|
|
Rooms.global.lockdown = this.lockdown;
|
|
this.lockdown = null;
|
|
});
|
|
|
|
it('should prevent battles from starting if the server is in lockdown', function () {
|
|
const room = Rooms.createBattle(FORMATID, {p1: this.p1, p2: this.p2, p1team: this.s1.team, p2team: this.s2.team, rated: 1000});
|
|
assert.equal(room, undefined);
|
|
});
|
|
});
|
|
});
|