2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 13:27:44 +00:00

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.
This commit is contained in:
GochoMugo 2016-10-10 16:51:20 +03:00
parent bf5ca1340b
commit db3c5c3cc3
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4

View File

@ -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));
});