From db3c5c3cc3e547aa316b873eed38db1d1b3ebcfe Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 10 Oct 2016 16:51:20 +0300 Subject: [PATCH] Run test for TelegramBot#_formatSendData() on supported Node.js versions Bug: The test for `TelegramBot#_formatSendData()` is only applicable on newer versions of Node.js (v6+) that support passing a Buffer representation of the path to `fs.createReadStream()`. Fix: If the runtime does NOT supports passing the Buffer argument, do NOT run the test on it. This is safe since we are sure that `fs.ReadStream.path` will never be a Buffer on the runtime being tested. --- test/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 8488330..7f189aa 100644 --- a/test/index.js +++ b/test/index.js @@ -203,7 +203,14 @@ describe('Telegram', function telegramSuite() { describe('#_formatSendData', function _formatSendData() { it('should handle buffer path from fs.readStream', function test() { const bot = new Telegram(TOKEN); - const photo = fs.createReadStream(Buffer.from(`${__dirname}/bot.gif`)); + let photo; + try { + photo = fs.createReadStream(Buffer.from(`${__dirname}/bot.gif`)); + } catch(ex) { + // Older Node.js versions do not support passing a Buffer + // representation of the path to fs.createReadStream() + if (ex instanceof TypeError) return; + } return bot.sendPhoto(USERID, photo).then(resp => { assert.ok(is.object(resp)); });