mineflayer-test-api

1.1.1 • Public • Published

mineflayer-test-api

NPM version Build Status Discord Try it on gitpod

An automated testing library for Mineflayer and Mineflayer plugins with CI/CD.

Usage

In your project, create a folder called "test". In this folder, you can create as many test files as you want. Each of these will be iterated over and executed automatically. (Nested folders are allowed)

An example of a test script:

// Load the registerTest function
const { registerTest } = require('mineflayer-test-api')
const mineflayer = require('mineflayer')
const events = require('events')

// Register a new test with a name an an async test function
registerTest('run forward', async (server, startPosition) => {

  // Create your bot and have it join the server
  const bot = await server.createBot({
    makeOp: true,
    startPosition: startPosition
  })

  // Run our test
  bot.setControlState('sprint', true)
  bot.setControlState('forward', true)
  await bot.waitForTicks(20)

  // Validate the test results.
  if (bot.entity.position.distanceTo(startPosition) < 5) throw new Error('Bot move too little!')
  if (bot.entity.position.distanceTo(startPosition) > 15) throw new Error('Bot moved too far!')
})

In your CI file, simply run npm run mineflayer-test [mcVersion 1] [mcVersion 2] ... to run all test files.

Package Sidebar

Install

npm i mineflayer-test-api

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

17.2 kB

Total Files

18

Last publish

Collaborators

  • rom1504