mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-06 13:47:24 -05:00
89 lines
2.3 KiB
JavaScript
89 lines
2.3 KiB
JavaScript
var assert = require('assert');
|
|
var path = require('path');
|
|
var net = require('net');
|
|
var fs = require('fs');
|
|
|
|
var testPort;
|
|
function getPort (callback) {
|
|
var port = testPort;
|
|
var server = net.createServer();
|
|
|
|
server.listen(port, function (err) {
|
|
server.once('close', function onclose () {
|
|
callback(port);
|
|
});
|
|
server.close();
|
|
});
|
|
server.on('error', function (err) {
|
|
testPort++;
|
|
getPort(callback);
|
|
});
|
|
}
|
|
|
|
function init (callback) {
|
|
require('./../app.js');
|
|
process.listeners('uncaughtException').forEach(function (listener) {
|
|
process.removeListener('uncaughtException', listener);
|
|
});
|
|
|
|
// Run the battle engine in the main process to keep our sanity
|
|
var BattleEngine = global.BattleEngine = require('./../battle-engine.js');
|
|
process.listeners('message').forEach(function (listener) {
|
|
process.removeListener('message', listener);
|
|
});
|
|
|
|
// Turn IPC methods into no-op
|
|
BattleEngine.Battle.prototype.send = function () {};
|
|
BattleEngine.Battle.prototype.receive = function () {};
|
|
|
|
callback();
|
|
}
|
|
|
|
before('initialization', function (done) {
|
|
this.timeout(0); // Remove timeout limitation
|
|
|
|
// Load and override configuration before starting the server
|
|
var config;
|
|
try {
|
|
config = require('./../config/config.js');
|
|
} catch (err) {
|
|
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
|
|
console.log("config.js doesn't exist - creating one with default settings...");
|
|
fs.writeFileSync(path.resolve(__dirname, '../config/config.js'),
|
|
fs.readFileSync(path.resolve(__dirname, '../config/config-example.js'))
|
|
);
|
|
config = require('./../config/config.js');
|
|
}
|
|
|
|
// Don't listen at SSL port
|
|
config.ssl = null;
|
|
|
|
// Make sure that there are no net conflicts with an active server
|
|
if (typeof config.testport !== 'undefined') {
|
|
config.port = config.testport;
|
|
init(done);
|
|
} else {
|
|
testPort = config.port;
|
|
getPort(function (port) {
|
|
config.port = port;
|
|
init(done);
|
|
});
|
|
}
|
|
});
|
|
|
|
describe('Native timer/event loop globals', function () {
|
|
var globalList = ['setTimeout', 'clearTimeout', 'setImmediate', 'clearImmediate'];
|
|
globalList.forEach(function (elem) {
|
|
describe('`' + elem + '`', function () {
|
|
it('should be a global function', function () {
|
|
assert.strictEqual(typeof global[elem], 'function');
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Battle simulation', function () {
|
|
require('./simulator');
|
|
});
|