Commit Graph

36 Commits

Author SHA1 Message Date
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
Ivo Julca
317389e2d2 Test: make sure that test server uses a clean port 2015-03-24 14:37:06 -05:00
Ivo Julca
03a8b03692 Test: remove unneeded tests for custom globals 2015-03-24 14:06:47 -05:00
Guangcong Luo
8f81cfa4de Run tests on port 18003
Port 18003 was chosen at random, but the point is not to use the same
port as PS itself is running on.

This might not be the best approach, but it probably at least beats
running it on the port in config.js and conflicting with an active
PS process.
2015-03-03 01:52:50 -05:00
Ivo Julca
68aaa48974 Gulpfile: no files are exempt from style checks
- Streams are merged to make sure that all errors and warnings are reported.
- Adds dev dependencies: `merge-stream` and `lazypipe`.
- Tracks a fork of `gulp-jshint` to fix https://github.com/spalger/gulp-jshint/issues/88
2015-02-18 19:51:15 -05:00
Ivo Julca
88c74abe76 Implement Mocha-based test suite 2015-02-15 13:27:36 -05:00