Commit Graph

55 Commits

Author SHA1 Message Date
Mia
7811795344
Handle new TypeScript version (#8449)
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2021-08-30 20:11:44 -07:00
Annika
c134195915
Use ts-node instead of Sucrase (#8369) 2021-07-09 19:59:22 -07:00
Annika
a80ce32b1f Punishments: Add broader, more integrated tests 2021-06-29 17:55:45 -07:00
Annika
a1b085f033
Chat monitor: Support unit tests (#7710) 2020-11-26 01:33:09 -08:00
Annika
577b858994
Tests: Allow requiring Config at the top level (#7109)
This solves issues like https://github.com/smogon/pokemon-showdown/pull/7100#discussion_r463922425 and makes it easier to test chat plugins.
2020-08-02 22:10:22 -07:00
Peach
7761c69763
Ignore existing chatrooms in tests (#6446) 2020-03-11 10:46:45 -07:00
Guangcong Luo
125fe31d06 Improve eslintrc
Fixed some more code style, allowing these rules to be enabled:

- `comma-dangle`
- `function-paren-newline`
- `member-delimiter-style`
- `no-eval`
- `no-fallthrough`
- `no-misused-promises`
- `no-unused-vars`
- `operator-linebreak`
2020-03-06 22:35:55 -08:00
not_a_seagull
ae28a960be Convert index.js and team-validator-async.js to typescript (#5987) 2020-01-04 07:11:54 -05:00
Slayer95
c18f244071
Test: Prevent before hook from timing out
It times out often in certain environments.
2019-03-28 00:06:45 -05:00
Kirk Scheibelhut
6e122d5d74 Refactor lib/ to be native Typescript (#5217) 2019-03-02 11:12:24 -06:00
Guangcong Luo
f3e45fbb72 Move server code to server/
Also move mods/ to data/mods/

This makes PS more monorepo-like. The intent is to further separate
the sim and the server code, but without fully committing to splitting
the repository itself.

We now support `./pokemon-showdown start` in addition to
`./pokemon-showdown`. I'm not clear which I want to be the default
yet.
2019-02-03 16:07:06 -06:00
Guangcong Luo
74dfd71355 Support Config.fakeladder
Useful for local testing, ignores matchmaking conditions like "can't
match same player twice in a row" and "can't match same IP", to make
it easier to test ladder stuff.
2019-01-26 00:40:00 -06:00
whales
c85d931fdf Use default config for tests (#4959) 2018-11-08 10:13:32 -06:00
asgdf
b205140de0 Tests: Prevent expired battle warning message (#4505) 2018-03-20 10:54:11 +09:00
Guangcong Luo
1b8d7775d9 Tests: Improve error message for Promise rejections 2018-01-31 21:53:10 -06:00
Guangcong Luo
43103f98ae Disable ProcessManager in tests 2018-01-18 04:10:19 -06:00
Guangcong Luo
ab1f995daa Rewrite Process Manager
Process Manager is now lib/process-manager.js

It's been entirely rewritten to reflect what I think a process manager
API should look like.

In particular, there are now two Process Managers, QueryProcessManager
and StreamProcessManager.

Pass QueryProcessManager a pure-ish query function (sync or async) that
takes a JSON value and returns a JSON value, and PM.query() will
execute that function in a subprocess, and return a Promise for its
return value.

StreamProcessManager is the same idea: Pass it a function to create an
ObjectReadWriteStream, and PM.createStream() will create a stream in a
subprocess and return a stream connected to it.
2018-01-18 03:34:16 -06:00
Guangcong Luo
738c60ed8b Move repl.js -> lib/repl.js 2017-12-16 15:40:45 -06:00
Ben Davies
1efe9525f0 Check for ENOENT error codes where MODULE_NOT_FOUND is checked 2017-11-17 13:19:18 +00:00
Guangcong Luo
0143ae28dd Replace fs module (#3686)
The new FS module is an abstraction layer over the built-in fs module.

The main reason it exists is because I need an abstraction layer I can
disable writing from. But that'll be in another commit.

Currently, mine is better because:
 - paths are always relative to PS's base directory
 - Promises (seriously wtf Node Core what are you thinking)
 - PS-style API: FS("foo.txt").write("bar") for easier argument order
 - mkdirp

This also increases the minimum supported Node version from v6.0 to
v7.7, because we now use async/await. Sorry for the inconvenience!

This also drops the mock-fs-require-fix dependency

mock-fs-require-fix was always kind of a huge hack. It's no longer
necessary, with an FS API that does everything it used to.

This removes a lot of other hacks from test/main.js, which is nice.
2017-06-24 13:42:54 -07:00
Ben Davies
0e736074a9 Tests: refactor test/main.js, remove test/simulator/index.js (#3565)
- The before hook in test/main.js has no reason to be handled
asynchronously when nothing it handles is async
- test/simulator/index.js has no reason to exist when mocha.opts
already handles finding files to test
2017-06-02 01:21:47 -05:00
Guangcong Luo
9e180e4fc1 Remove MockBattle
No MockBattle feature needs to be kept out of sim/...
2017-05-05 16:57:18 -05:00
Dan Pantry
9c65c5b84a add mock for battle tests that can reset the RNG
This enables battles in tests to reset their RNG to what it originally
was when they were created. A number of tests do this already by
breaking encapsulating and modifying the prng variable directly. This
should fix that.

We also remove createBattleWithPRNG and min/maxSeed properties.

Firstly, the tests that were still using the maxSeed property were
setting it to Battle.seed which has no effect since the PRNG class does
not look at this property any more - so these were no-ops.

After removing this property from tests, maxRollSeed was never used, so
I removed it and renamed minRollSeed to DEFAULT_ROLL_SEED (since it's
constant).

The places that were still using minRollSeed also were no-ops or were
using createBattleWithPRNG. Since every single instance was actually
just using the same code, I removed createBattleWithPRNG and made
createBattle default to giving you a seed with DEFAULT_ROLL_SEED and
removed the minRollSeed property too.

This makes tests much simpler and reduces the usage surface of
TestTools; now, you must define your *own* seed if you're making a PRNG
for a test, or you use one that TestTools gives you; you may not use a
public property that TestTools gives you.

We also remove the code that removes a listener in the Battle Engine.
This was rendered obsolete by f6a7c4b (see more info [in the discussion
on github][disc]

[disc]:
https://github.com/Zarel/Pokemon-Showdown/pull/3272#discussion_r102414795
2017-02-22 20:44:20 -05:00
Dan Pantry
89d4265be8 don't rely on global BattleEngine in tests
This is necessary for us to introduce a mock object.
2017-02-22 20:44:20 -05:00
Dan Pantry
56ba782966 refactor PRNG to its own class
This removes the 'deterministic test' tools by preventing action at a
distance (namely, preventing the modification of the `init` method in
`Battle` during tests). This action at a distance is incredibly
confusing.

All this action at a distance did was discard any parameters that were
passed to `Battle` that weren't the first three (which was probably a
mistake by the original author) and also hard code `this.seed` and
`this.startingSeed` in `Battle`.

This functionality has now been moved to the `PRNG` class, so instead
users should pass a `PRNG` to `Battle` as the 5th constructor argument.
Users can also pass one as the third argument to `common.createBattle`
or use `common.createBattleWithPRNG` with the PRNG as the first
argument.

The PRNG is just an encapsulation of the pseudo-random algorithm in a
class. It is stateful, so make sure to take a `clone()` of the PRNG if
you want to re-use it.
2017-02-22 20:44:20 -05:00
Ivo Julca
e741700553 Test: Update the PRNG seed to make confusion self-hits more consistent 2016-11-17 23:09:04 -05:00
Ivo Julca
ddfe02efe3 Build: Fix Node v7 support 2016-11-17 14:20:33 -05:00
Guangcong Luo
87c41eb67c Rename simulator.js to room-battle.js
simulator.js doesn't actually contain the simulator, but is really just
an implementation of battles in the RoomGame interface.

Renames:
`Simulator.Battle` -> `Rooms.RoomBattle`
`Simulator.BattlePlayer` -> `Rooms.RoomBattlePlayer`
`Simulator.SimulatorManager` -> `Rooms.SimulatorManager`
`Simulator.SimulatorProcess` -> `Rooms.SimulatorProcess`
`Simulator.create` -> no longer exists, use `new Rooms.RoomBattle(...)`
2016-10-21 13:21:12 -05:00
Taylor Everding
1a1f64fe95 Remove .js extension from requires (#2725) 2016-08-30 00:04:40 -05:00
Bär Halberkamp
55429ed884 Move modlog writing to Room.prototype (#2700)
* Move modlog-related functions to Room.prototype, instead of CommandParser

* Wifi: modnote the winner of a giveaway
2016-08-18 16:45:53 -05:00
Taylor Everding
f6a7c4bd30 Move IPC from battle-engine.js to simulator.js (#2666) 2016-08-04 00:35:59 -05:00
Konrad Borowski
bb3acda351 Copy auth from tournament room to tournament battle (#2608)
This allows room staff to perform moderation in tournament battles.
2016-07-06 07:28:47 -05:00
kotarou3
952cefbad4 Minor crash guard changes (#2470)
- Remove unused crash guard comment
- Update Config.crashguard comment a bit
- Use Config.crashguard to disable it in tests
2016-04-17 02:15:17 -07:00
Guangcong Luo
b665660608 Refactor for more ES6 features
Now that nodejs/node#3072 is mostly fixed, we can finally start using
Node 4+ features.

This refactor:

- uses arrow functions where appropriate

  Note that arrow functions still aren't used in Mocha, where `this`
  is sometimes meaningful.

  This also removes the need for .bind() nearly everywhere, as well
  as the `self = this` trick.

- refactors Validator and Connection into ES6 classes

- no longer uses Array#forEach for iterating arrays

  We strongly prefer for (let i = 0; i < arr.length; i++) because of
  performance reasons. Most forEaches have been replaced with for..of,
  though, which is 5x slower than the long-form loop but 2x faster
  than forEach, which is good enough outside of most inner loops.

  The only exception is tournaments, which is due for a more invasive
  refactor soon anyway.
2016-02-10 17:40:21 -06:00
小太
edb9d27262 Don't enable repl while testing 2016-01-12 20:44:27 +11:00
Guangcong Luo
573922f145 Give more control over when servers are spawned
Previously, include('./sockets.js') and include('./app.js') would
automatically spawn listener processes.

Now, you have to actually use .listen() to spawn listener processes.

This makes the testing framework simpler, since it no longer needs an
ugly hack to suppress spawning socket processes, and also makes it
easier for the ./pokemon-showdown "binary" to pass a port to app.js.

./pokemon-showdown will now also install dependencies if necessary.
2016-01-07 00:20:49 -06:00
Konrad Borowski
81f602b8d8 Always use trailing comma for multiline objects 2016-01-01 00:20:07 +01:00
Ivo Julca
f5b3a3b875 Test: use mock-fs to sandbox the file system 2015-12-20 03:22:02 -05:00
Ivo Julca
9116fea506 Fix config crashes possibly resulting in config reset 2015-12-04 01:01:50 -05:00
Juanma Serrano
c4ac8d6e2f Use strict mode and let and const instead of var
This commit also fixes some duplicated variable declarations.
2015-11-06 21:56:52 -05:00
Ivo Julca
e2709e6213 Fix Travis CI build 2015-09-11 00:54:37 -05:00
Ivo Julca
3ae84997c9 Test: don't load chatroom data 2015-09-11 00:41:15 -05:00
Ivo Julca
234e87319b Test: don't write to file system 2015-09-11 00:40:22 -05:00
Ivo Julca
85379ff12e Test: don't listen for connections 2015-09-11 00:38:49 -05:00
Ivo Julca
0a1cf02b9d Prevent login server requests in tests 2015-07-30 09:20:47 -05:00
Ivo Julca
2670d4d2ce Fix stray spacing style issues
These were not caught by the CI until the cache was deleted.
2015-07-29 15:34:42 -05:00
Ivo Julca
43e20ebf24 Add regression test for issue described in b3b435c 2015-07-07 03:11:49 -05:00
Ivo Julca
fc89d5f372 Test suite is now deterministic 2015-06-26 21:55:43 -05:00
Ivo Julca
4222ffb5df Dependant support: make sure that relative paths are resolved properly 2015-05-11 15:38:18 -05:00
Ivo Julca
fe4eb481fa Simplify b6aea81 2015-03-24 14:37:23 -05:00