{"id":15669013,"url":"https://github.com/dcdunkan/grammy_tests","last_synced_at":"2025-05-06T19:48:24.331Z","repository":{"id":114588183,"uuid":"469790661","full_name":"dcdunkan/grammy_tests","owner":"dcdunkan","description":"Write tests for your Telegram Bots made using grammY.","archived":false,"fork":false,"pushed_at":"2023-05-03T18:28:58.000Z","size":183,"stargazers_count":16,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"refine-2","last_synced_at":"2025-03-31T02:22:03.526Z","etag":null,"topics":["grammy","grammyjs","telegram-bot","testing","testing-framework","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcdunkan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-14T15:21:51.000Z","updated_at":"2025-03-10T13:24:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc4acf61-b281-440f-ae44-4123529187c8","html_url":"https://github.com/dcdunkan/grammy_tests","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Fgrammy_tests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Fgrammy_tests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Fgrammy_tests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Fgrammy_tests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcdunkan","download_url":"https://codeload.github.com/dcdunkan/grammy_tests/tar.gz/refs/heads/refine-2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252758452,"owners_count":21799850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grammy","grammyjs","telegram-bot","testing","testing-framework","typescript"],"created_at":"2024-10-03T14:21:02.838Z","updated_at":"2025-05-06T19:48:24.305Z","avatar_url":"https://github.com/dcdunkan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e **Warning**: This is the re-write branch and it IS unstable. If you want to use a little-broken-and-old version of this library, switch to the main branch.\n\n# Test framework for grammY\n\nA **work-in-progress** framework for testing Telegram bots made using the grammY\nTelegram bot framework. grammY is a great framework for developing Telegram bots and it's ecosystem provides everything you need for that. You can read more about grammY here: **\u003chttps://grammy.dev\u003e**.\n\nHowever, grammY lacks one important thing. A testing framwork, a good one. And this repository is only an\nattempt to make one. I've regretted some choices that I made in the past about the architecture of the library. So, I'm re-writing the whole thing until I get it right.\n\n#### Installation\n\n**Note**: This library is **only available for Deno** at the moment. Node.js support will land when the library is stable and published on \u003chttps://deno.land/x\u003e.\n\nYou can import from GitHub raw URLs for now,\nas this haven't been published on \u003chttps://deno.land/x\u003e yet.\n\n```ts\nimport { Chats } from \"https://raw.githubusercontent.com/dcdunkan/tests/refine-2/mod.ts\";\n```\n\n\u003e The URL above imports from this branch. It is recommended to use a versioned URL than this.\n\n## Writing Tests\n\nHere is a simple setup showing how you can test your bot. Note that the example is pretty basic at the moment. It'll be extended more as the implementation progresses.\n\n**`bot.ts`**\n\nThis file is supposed to export the `Bot` instance. You can have the logic and handlers of the bot in this file.\n\n```ts\nimport { Bot } from \"https://deno.land/x/grammy/mod.ts\";\nexport const bot = new Bot(\"\"); // \u003c-- Put your token inside the quotes.\n// Middlewares and logic goes here. For this example,\n// we'll just register a /start command handler.\nbot.command(\"start\", (ctx) =\u003e ctx.reply(\"How you doin'?\"));\n```\n\n\u003e **Warning**:\n\u003e Don't start your bot in long polling (`bot.start()`) in the bot.ts file as this framework isn't supposed to be used like that. To start your bot in long polling, create another file (perhaps a main.ts?), import the bot there, start it there and run that file.\n\n\u003c!-- \u003e Never start your bot in long polling (`bot.start()`) in the bot.ts file (where you export the bot). It will cause issues with installing the transformer middlewares which is necessary for the test framework to function. To start your bot, create another file (perhaps main.ts?), import the bot there, start it there, and run that file. --\u003e\n\n**`bot_test.ts`**\n\n```ts\nimport { Chats } from \"...\";\nimport { bot } from \"./bot.ts\";\nimport { assertEquals } from \"https://deno.land/std/testing/asserts.ts\";\n\nconst chats = new Chats(bot);\n\n// Create a user to interact with the bot.\nconst user = chats.newUser({/* details of the user */});\n\n// Send a message to the bot.\nawait user.sendMessage(\"Hello there!\");\n\n// Looking good.\n\n// Let's actually test something: The start command.\nDeno.test(\"Start command\", async () =\u003e {\n  await user.command(\"start\");\n  // So the bot replies, and after the bot handles it,\n  // it's response payload becomes available in the last object.\n  assertEquals(user.last.text, \"How you doin'?\");\n});\n```\n\nThere are methods other than just `sendMessage` and `command`. You can try them out. If you want to see a more up-to-date (not exactly, but yes) example, that is used for testing the implementation while developing this library, checkout the **[example.ts](./example.ts)** file.\n\n\u003e **TIP**:\n\u003e Like the `user.last` has the payload of the latest response, there is `user.responses`, containing all of the responses and `user.updates` is another array containing all the\n\u003e updates that have been sent to the user.\n\nThat's a simple enough setup. Now you can run the test using `deno test`, and you should see a\nbunch of green OKs printing out in the terminal.\n\n## How Does This Work?\n\nFirst consider reading what the Official grammY Documentation says about testing your bots: \u003chttps://grammy.dev/advanced/deployment.html#testing\u003e.\n\nThis framework handles takes care of what you read there:\n\n- It handles all the outgoing API requests (from the bot) behind the curtain; and the dynamically generated API responses respects the environment the bot is in. So, it should work very well with all of the methods.\n- Generating updates for force-testing the bot can be hard and tedious. This framework provides enough methods to cover almost all of your needs.\n\n\u003e A much more detailed explanation will be added here later on.\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\nLicensed under MIT \u0026copy; 2023 Dunkan\n\n\u003c/div\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcdunkan%2Fgrammy_tests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcdunkan%2Fgrammy_tests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcdunkan%2Fgrammy_tests/lists"}