feat: better code formatting

This commit is contained in:
2026-04-23 23:03:00 -03:00
parent a3841bd173
commit e18980938e
37 changed files with 1691 additions and 7930 deletions

View File

@@ -9,51 +9,57 @@ const DIST_MAIN_JS = 'dist/main.js';
* manipulating the terrain and game state.
*/
class IntegrationTestHelper {
private _server: any;
private _player: any;
private _server: any;
private _player: any;
get server() {
return this._server;
}
get server() {
return this._server;
}
get player() {
return this._player;
}
get player() {
return this._player;
}
async beforeEach() {
this._server = new ScreepsServer();
async beforeEach() {
this._server = new ScreepsServer();
// reset world but add invaders and source keepers bots
await this._server.world.reset();
// reset world but add invaders and source keepers bots
await this._server.world.reset();
// create a stub world composed of 9 rooms with sources and controller
await this._server.world.stubWorld();
// create a stub world composed of 9 rooms with sources and controller
await this._server.world.stubWorld();
// add a player with the built dist/main.js file
const modules = {
main: readFileSync(DIST_MAIN_JS).toString(),
};
this._player = await this._server.world.addBot({ username: 'player', room: 'W0N1', x: 15, y: 15, modules });
// add a player with the built dist/main.js file
const modules = {
main: readFileSync(DIST_MAIN_JS).toString(),
};
this._player = await this._server.world.addBot({
username: 'player',
room: 'W0N1',
x: 15,
y: 15,
modules,
});
// Start server
await this._server.start();
}
// Start server
await this._server.start();
}
async afterEach() {
await this._server.stop();
}
async afterEach() {
await this._server.stop();
}
}
beforeEach(async () => {
await helper.beforeEach();
await helper.beforeEach();
});
afterEach(async () => {
await helper.afterEach();
await helper.afterEach();
});
before(() => {
stdHooks.hookWrite();
stdHooks.hookWrite();
});
export const helper = new IntegrationTestHelper();

View File

@@ -1,18 +1,18 @@
import {assert} from "chai";
import {helper} from "./helper";
import { helper } from './helper';
import { assert } from 'chai';
describe("main", () => {
it("runs a server and matches the game tick", async function () {
for (let i = 1; i < 10; i += 1) {
assert.equal(await helper.server.world.gameTime, i);
await helper.server.tick();
}
});
describe('main', () => {
it('runs a server and matches the game tick', async function () {
for (let i = 1; i < 10; i += 1) {
assert.equal(await helper.server.world.gameTime, i);
await helper.server.tick();
}
});
it("writes and reads to memory", async function () {
await helper.player.console(`Memory.foo = 'bar'`);
await helper.server.tick();
const memory = JSON.parse(await helper.player.memory);
assert.equal(memory.foo, 'bar');
});
it('writes and reads to memory', async function () {
await helper.player.console(`Memory.foo = 'bar'`);
await helper.server.tick();
const memory = JSON.parse(await helper.player.memory);
assert.equal(memory.foo, 'bar');
});
});

View File

@@ -6,4 +6,4 @@ global.sinon = require('sinon');
global.chai.use(require('sinon-chai'));
// Override ts-node compiler options
process.env.TS_NODE_PROJECT = 'tsconfig.test.json'
process.env.TS_NODE_PROJECT = 'tsconfig.test.json';

View File

@@ -1,37 +1,37 @@
import {assert} from "chai";
import {loop} from "../../src/main";
import {Game, Memory} from "./mock"
import { loop } from '../../src/main';
import { Game, Memory } from './mock';
import { assert } from 'chai';
describe("main", () => {
before(() => {
// runs before all test in this block
});
describe('main', () => {
before(() => {
// runs before all test in this block
});
beforeEach(() => {
// runs before each test in this block
// @ts-ignore : allow adding Game to global
global.Game = _.clone(Game);
// @ts-ignore : allow adding Memory to global
global.Memory = _.clone(Memory);
});
beforeEach(() => {
// runs before each test in this block
// @ts-ignore : allow adding Game to global
global.Game = _.clone(Game);
// @ts-ignore : allow adding Memory to global
global.Memory = _.clone(Memory);
});
it("should export a loop function", () => {
assert.isTrue(typeof loop === "function");
});
it('should export a loop function', () => {
assert.isTrue(typeof loop === 'function');
});
it("should return void when called with no context", () => {
assert.isUndefined(loop());
});
it('should return void when called with no context', () => {
assert.isUndefined(loop());
});
it("Automatically delete memory of missing creeps", () => {
Memory.creeps.persistValue = "any value";
Memory.creeps.notPersistValue = "any value";
it('Automatically delete memory of missing creeps', () => {
Memory.creeps.persistValue = 'any value';
Memory.creeps.notPersistValue = 'any value';
Game.creeps.persistValue = "any value";
Game.creeps.persistValue = 'any value';
loop();
loop();
assert.isDefined(Memory.creeps.persistValue);
assert.isUndefined(Memory.creeps.notPersistValue);
});
assert.isDefined(Memory.creeps.persistValue);
assert.isUndefined(Memory.creeps.notPersistValue);
});
});

View File

@@ -1,17 +1,17 @@
export const Game: {
creeps: { [name: string]: any };
rooms: any;
spawns: any;
time: any;
creeps: { [name: string]: any };
rooms: any;
spawns: any;
time: any;
} = {
creeps: {},
rooms: [],
spawns: {},
time: 12345
creeps: {},
rooms: [],
spawns: {},
time: 12345,
};
export const Memory: {
creeps: { [name: string]: any };
creeps: { [name: string]: any };
} = {
creeps: {}
creeps: {},
};