All Projects → TiagoDanin → Telegraf-Test

TiagoDanin / Telegraf-Test

Licence: MIT license
Telegraf Test - Simple Test ToolKit of Telegram Bots

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Telegraf-Test

Testcafe
A Node.js tool to automate end-to-end web testing.
Stars: ✭ 9,176 (+41609.09%)
Mutual labels:  test, test-automation, test-framework, testing-tools
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-9.09%)
Mutual labels:  test, test-automation, test-framework, testing-tools
PixelTest
Fast, modern, simple iOS snapshot testing written purely in Swift.
Stars: ✭ 56 (+154.55%)
Mutual labels:  test, tests, test-framework, testing-tools
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (+86.36%)
Mutual labels:  test, test-automation, test-framework, testing-tools
IO-TESTER
A functional test framework
Stars: ✭ 32 (+45.45%)
Mutual labels:  test, test-automation, test-framework, testing-tools
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+159650%)
Mutual labels:  test, test-automation, tests, testing-tools
Mocha
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+95290.91%)
Mutual labels:  mocha, test, test-framework, testing-tools
playwright-test
Run unit tests with several runners or benchmark inside real browsers with playwright.
Stars: ✭ 81 (+268.18%)
Mutual labels:  mocha, test, tests, testing-tools
Testfx
MSTest V2 framework and adapter
Stars: ✭ 391 (+1677.27%)
Mutual labels:  test, test-framework, testing-tools
Carina
Carina automation framework: Web, Mobile, API, DB
Stars: ✭ 549 (+2395.45%)
Mutual labels:  test, test-automation, testing-tools
tropic
🍍 Test Runner Library
Stars: ✭ 29 (+31.82%)
Mutual labels:  mocha, test-automation, test-framework
BDTest
BDTest - A Testing Framework for .NET
Stars: ✭ 58 (+163.64%)
Mutual labels:  test, test-automation, tests
Recheck Web
recheck for web apps – change comparison tool with local Golden Masters, Git-like ignore syntax and "Unbreakable Selenium" tests.
Stars: ✭ 224 (+918.18%)
Mutual labels:  test-automation, test-framework, testing-tools
Swagger meqa
Auto generate and run tests using swagger/OpenAPI spec, no coding needed
Stars: ✭ 151 (+586.36%)
Mutual labels:  test, test-automation, testing-tools
alexa-skill-test-framework
Framework for easy offline black-box testing of Alexa skills.
Stars: ✭ 64 (+190.91%)
Mutual labels:  mocha, test, test-framework
Hitchhiker
a Restful Api test tool
Stars: ✭ 2,175 (+9786.36%)
Mutual labels:  test, test-automation, testing-tools
Qtools
QTools collection of open source tools for embedded systems development on Windows, Linux and MacOS
Stars: ✭ 64 (+190.91%)
Mutual labels:  test-automation, test-framework, testing-tools
Zunit
A powerful testing framework for ZSH projects
Stars: ✭ 140 (+536.36%)
Mutual labels:  test-automation, test-framework, testing-tools
arduino-ci-script
Bash script for continuous integration of Arduino projects
Stars: ✭ 25 (+13.64%)
Mutual labels:  test, test-automation, tests
carina
Carina automation framework: Web, Mobile, API, DB etc testing...
Stars: ✭ 652 (+2863.64%)
Mutual labels:  test, test-automation, testing-tools

Telegraf Test

Travis Downloads Node Version XO code style

Telegraf Test - Simple Test ToolKit of Telegram Bots

Features

  • Telegram bot api server emulator.
  • Compatible with Telegraf <3.
  • Compatible with Mocha e others test framework.
  • Send message, inline query and callback query.
  • Work in local network.
  • Offline

Installation

Module available through the npm registry. It can be installed using the npm or yarn command line tool.

# Yarn (Recomend)
yarn add telegraf-test
# NPM 
npm install telegraf-test --save

Example

const Telegraf = require('telegraf')
const TelegrafTest = require('telegraf-test')

const port = 3000
const secretPath = 'secret-path'

const bot = new Telegraf('ABCD:1234567890')
const test = new TelegrafTest({
	url: `http://127.0.0.1:${port}/${secretPath}`
})

test.setUser({
	id: 1234,
	username: '@TiagoEDGE'
	// ...//
}) /* Return {
	id: 1234,
	is_bot: false,
	first_name: 'FIST-NAME',
	last_name: '',
	username: '@TiagoEDGE',
	language_code: 'en-US'
} */

bot.hears(/ping/i, ctx => {
	ctx.reply('Pong!')
})

bot.startWebhook(`/${secretPath}`, null, port)

test.sendMessageWithText('/ping')
	.then(res => {
		console.log(res.data)
		// { method: 'sendMessage', chat_id: 1234567890, text: 'Pong!' }
	})
	.catch(error => {
		console.error(error)
	})

Documentation

Options of Class TelegrafTest({options})

  • url - String

Webhook url of your bot.
Default value: http://127.0.0.1:3000/secret-path

  • axios - Object

Config/option of Axios.
Default value: {headers: {'content-type': 'application/json'}, method: 'POST'}

  • port - Number

Server emulator port.
Default value: 2000

  • token - String

Bot token.
Default value: ABCD:1234567890

API

Set & Get Objects

Update id.
Default value: Start in 0

Get Objects

  • getUser()
  • getChat()
  • getMessage()
  • getInlineQuery()
  • getCallbackQuery()
  • getUpdateId()
  • getWebhook()
  • getAllowedUpdates()

Send Requests

Return request of axios or false in updates ignored.

  • sendUpdate({params})
  • sendMessage({params})
  • sendMessageWithText(text: String, {params})
  • sendInlineQuery(query: String, {params})
  • sendCallbackQuery({params})
  • sendCallbackQueryWithData(data: String, {params})

[WIP] Web Server

Telegram Bot Api Server Emulator. Start with startServer().

  • startServer() - Return Express App Object

Support methods:

Using with a Test Framework

You create a test suite with Mocha and ExpectJS.

Example test.js:

const expect = require('expect.js')
describe('bot', function() {
	it('/ping', async function() {
		var r = await test.sendMessageWithText('/ping')
		expect(r.data.text).to.be.a('string')
		expect(r.data.text).to.contain('Pong!')
	})
})

Run with $ mocha --exit --timeout 100000

Using Debug

Set environment variables DEBUG=telgraf:test.

Tests

To run the test suite, first install the dependencies, then run test:

# Using Yarn
yarn test
# Using NPM
npm run test

Dependencies

axios: Promise based HTTP client for the browser and node.js Author: Matt Zabriskie
License: MIT
Version: ^0.19.2
debug: small debugging utility Author: TJ Holowaychuk
License: MIT
Version: ^4.1.1
express: Fast, unopinionated, minimalist web framework Author: TJ Holowaychuk
License: MIT
Version: ^4.17.1

Dev Dependencies

mocha: simple, flexible, fun test framework Author: TJ Holowaychuk
License: MIT
Version: 7.0.1
telegraf: Modern Telegram Bot Framework Author: Vitaly Domnikov
License: MIT
Version: ^3.36.0
xo: JavaScript linter with great defaults Author: Sindre Sorhus
License: MIT
Version: ^0.25.3

Contributors

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. List of all contributors.

License

MIT © Tiago Danin

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].