From 4b8eb6c68a627647df8b702880fd9853bf17c9a1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Sep 2023 10:30:17 +0600 Subject: [PATCH] chore: Add dotenv to simplify local development --- env.template | 19 +++++++++++++++++++ package.json | 3 +++ test/README.md | 12 ++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 env.template diff --git a/env.template b/env.template new file mode 100644 index 00000000..04ad16bd --- /dev/null +++ b/env.template @@ -0,0 +1,19 @@ +# Token to be used +TEST_TELEGRAM_TOKEN= + +# User Id which you want to send the messages. +TEST_USER_ID= + +# Group Id which to use in some of the tests, e.g. for TelegramBot#getChat() +TEST_GROUP_ID= + +# Game short name to use in some tests, e.g. TelegramBot#sendGame() +# Defaults to "medusalab_test". +TEST_GAME_SHORT_NAME= + +# Sticker set name to use in some tests, e.g. TelegramBot#getStickerSet() +# Defaults to "pusheen". +TEST_STICKER_SET_NAME= + +# Payment provider token to be used +TEST_PROVIDER_TOKEN= diff --git a/package.json b/package.json index e132fd91..caaec16c 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,12 @@ "scripts": { "gen-doc": "echo 'WARNING: `npm run gen-doc` is deprecated. Use `npm run doc` instead.' && npm run doc", "doc": "jsdoc2md --files src/telegram.js --template doc/api.hbs > doc/api.md", + "prepare-env": "cp env.template .env", "build": "babel -d ./lib src", "prepublishOnly": "npm run build && npm run gen-doc", "eslint": "eslint ./src ./test ./examples", "mocha": "mocha", + "mocha:dev": "mocha -r dotenv/config", "pretest": "npm run build", "test": "npm run eslint && istanbul cover ./node_modules/mocha/bin/_mocha" }, @@ -52,6 +54,7 @@ "babel-preset-es2015": "^6.24.1", "babel-register": "^6.26.0", "concat-stream": "^1.6.0", + "dotenv": "16.3.1", "eslint": "^2.13.1", "eslint-config-airbnb": "^6.2.0", "eslint-plugin-mocha": "^4.11.0", diff --git a/test/README.md b/test/README.md index fa6f19f0..41a7bbd9 100644 --- a/test/README.md +++ b/test/README.md @@ -26,6 +26,14 @@ npm run test # Run individual tests npm run eslint # static-analysis -npm run mocha # mocha tests ``` -Note: The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. \ No newline at end of file +Running the mocha: +```bash +npm run prepare-env +``` +Edit the [.env](../.env) file by filling in the value of the environment variables with your data. + +```bash +npm run mocha:dev # mocha tests +``` +Note: The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.