mineflayer-test-api
v1.1.1
Published
An automated testing library for Mineflayer and Mineflayer plugins with CI/CD.
Downloads
12
Maintainers
Readme
mineflayer-test-api
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.