Skip to content

Helper functions and environment for unit testing your Screeps code with Jest.

Notifications You must be signed in to change notification settings

eduter/screeps-jest

Repository files navigation

Screeps-Jest

Environment and helper functions for unit testing your Screeps bot with Jest.

Features:

  • All game constants and lodash automatically available in the global scope, when running unit tests
  • Functions for mocking instances of game objects and globals
  • Constructor of RoomPosition already mocked
  • If you're using TypeScript (why wouldn't you?), mocks have fully inferred types and your IDE should autocomplete property names while creating your mocks

How to install it?

yarn add screeps-jest --dev

or

npm install screeps-jest --save-dev

How to set it up?

// jest.config.js
module.exports = {
  // ...
  testEnvironment: "screeps-jest"
  // ...
};

How to use it?

// *.spec.ts
import { mockGlobal, mockInstanceOf, mockStructure } from "screeps-jest";

mockGlobal<Game>('Game', {
  time: 123
});

const creep = mockInstanceOf<Creep>({
  moveTo: () => OK,
  store: {
    getFreeCapacity: () => 0
  },
  transfer: () => ERR_NOT_IN_RANGE
});

const spawn = mockStructure(STRUCTURE_SPAWN, {
  hits: 5000,
  hitsMax: 5000
});

More...

Check screeps-typescript-jest-starter for a more complete example of how to use screeps-jest to unit test a Screeps bot in TypeScript.

If you find a bug or have a feature request, please create an issue. If you have trouble using screeps-jest, ask on #typescript channel on Screeps' Discord server. I hang out there often, and someone else there might be able to help you also.

About

Helper functions and environment for unit testing your Screeps code with Jest.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published