Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

screeps-test-helper

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

screeps-test-helper

Helper functions and environment for unit testing your Screeps code.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Screeps Test Helper

Fork of https://github.com/eduter/screeps-jest that has been updated to be test framework agnostic. All credit should go to Eduter.

Helper functions for unit testing your Screeps AI.

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?

npm install screeps-test-helper --save-dev

Before any of your tests run you will need to call the setup(global) function.

Jest

There is a Jest Environment provided.

Mocha

Mocha will require creating a file that calls the setup function that is loading using --require when using the CLI or referenced in the .mocharc.* file.

Example ./src/test_globals.ts for Mocha:

import {setup} from 'screeps-test-helper';
setup(global);

The file can be referenced by the .mocharc.json file like so:

{
  "extension": [
    "ts"
  ],
  "spec": "./src/**/*.test.ts",
  "require": [
    "ts-node/register",
    "./src/test_globals.ts"
  ]
}

How to use it?

import { mockGlobal, mockInstanceOf, mockStructure } from "screeps-test-helper";

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
});

FAQs

Package last updated on 07 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc