Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved timeout handling #410

Merged
merged 2 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile-build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM docker.io/library/openjdk:11-jdk as build

# https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
RUN curl -fsSL https://deb.nodesource.com/setup_17.x | bash - && apt install -y nodejs && node --version
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt install -y nodejs && node --version

WORKDIR /project
30 changes: 13 additions & 17 deletions test-mineflayer/storeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,42 @@ const createBot = (command) => {
return bot;
}

const handleError = (bot, done) => {
bot.on("error", (e) => {
done(e);
});
}

describe("Storeys plugin test", () => {
beforeAll(() => {
// Prevent jest from complaining about an import after the test is done (You are trying to `import` a file after the Jest environment has been torn down.)
jest.useFakeTimers('legacy');
console.log = () => { };
});
let bot;

const handleError = (done) => {
bot.on("error", (e) => {
done(e);
});
}

afterAll(() => bot.quit());
vorburger marked this conversation as resolved.
Show resolved Hide resolved

test("should connect to minecraft server and execute /make", (done) => {
// given
const bot = createBot("/make");
bot = createBot("/make");

// then
bot.on('messagestr', (msg) => {
if (msg !== "Player joined the game") {
expect(msg).toEqual("Click here to open Scratch and MAKE actions");
done();
bot.quit();
}
});

handleError(bot, done);
handleError(done);
}, TIMEOUT);

test("should execute /new", (done) => {
// given
const bot = createBot("/new");
bot = createBot("/new");

// then
bot.on('title', (msg) => {
expect(msg).toEqual("{\"text\":\"Hello\"}");
done();
bot.quit();
});

handleError(bot, done);
handleError(done);
}, TIMEOUT);
});