mineflayer-test-api

    1.0.2 • 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 = mineflayer.createBot({
        host: 'localhost',
        port: server.port,
        username: 'bot123456'
      })
    
      // Wait for the bot to spawn
      await events.once(bot, 'spawn')
    
      // Make the bot op and teleport them to the start position
      await server.makeOp(bot)
      await server.teleport(bot, 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.

    Install

    npm i mineflayer-test-api

    DownloadsWeekly Downloads

    4

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    16.9 kB

    Total Files

    18

    Last publish

    Collaborators

    • rom1504