Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/test/externalTests/exampleInventory.js
Views: 789
const assert = require('assert')12const tests = [3{4command: 'list',5wantedMessage: 'dirt x 64, stick x 7, iron_ore x 64, diamond_boots x 1'6},7{8command: 'equip off-hand dirt',9wantedMessage: 'equipped dirt'10},11{12command: 'list',13wantedMessage: 'stick x 7, iron_ore x 64, diamond_boots x 1, dirt x 64'14},15{16command: 'equip hand dirt',17wantedMessage: 'equipped dirt'18},19{20command: 'toss 64 dirt',21wantedMessage: 'tossed 64 x dirt'22},23{24command: 'craft 1 ladder',25wantedMessage: 'I can make ladder'26},27{28command: '',29wantedMessage: 'did the recipe for ladder 1 times'30},31{32command: 'equip feet diamond_boots',33wantedMessage: 'equipped diamond_boots'34},35{36command: 'toss iron_ore',37wantedMessage: 'tossed iron_ore'38},39{40command: 'unequip feet',41wantedMessage: 'unequipped'42},43{ // after tests layout44command: 'list',45wantedMessage: 'ladder x 3, diamond_boots x 1'46}47]48module.exports = () => async (bot) => {49await bot.test.runExample('examples/inventory.js', async (name) => {50assert.strictEqual(name, 'inventory')51bot.chat('/op inventory') // to counteract spawn protection52bot.chat('/clear inventory')53bot.chat(`/setblock 52 ${bot.test.groundY} 0 crafting_table`) // to make stone bricks stairs54bot.chat('/give inventory dirt 64')55bot.chat('/give inventory stick 7')56bot.chat('/give inventory iron_ore 64')57bot.chat('/give inventory diamond_boots 1')58await bot.test.wait(2000)59if (bot.registry.isOlderThan('1.9')) {60tests.splice(tests.indexOf(tests.find(t => t.command.includes('off-hand'))), 2) // Delete off-hand command and the command after it as they don't work in 1.961}62const testFuncs = tests.map(test => makeTest(test.command, test.wantedMessage))63for (const test of testFuncs) {64await test()65await bot.test.wait(100)66}67// cleanup68bot.chat(`/setblock 52 ${bot.test.groundY} 0 air`)6970function makeTest (inStr, outStr) {71return () => bot.test.tellAndListen(name, inStr, makeListener(outStr))72}73})74}7576function makeListener (wantedMessage) {77return (message) => {78if (!message.startsWith(wantedMessage)) {79assert.fail(`Unexpected message: ${message}, wanted ${wantedMessage}`) // error80}81return true // stop listening82}83}848586