Skip to content

Commit

Permalink
Merge 5c7a1ac into 61fe603
Browse files Browse the repository at this point in the history
  • Loading branch information
jehy authored Mar 12, 2018
2 parents 61fe603 + 5c7a1ac commit 48a6e3f
Show file tree
Hide file tree
Showing 19 changed files with 4,845 additions and 709 deletions.
9 changes: 4 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"node": true,
"mocha": true
},
"extends": "airbnb",
"extends": "airbnb-base",
"plugins": [
"standard",
"promise"
],
"rules": {
"prefer-destructuring": "warn",
"one-var": "off",
"indent": "off",
"padded-blocks": "off",
"no-plusplus": "off",
"arrow-spacing": "off",
"object-curly-spacing": "off",
Expand All @@ -24,7 +23,7 @@
"no-multi-spaces": "off",
"linebreak-style": [
"error",
"windows"
"unix"
]
}
}
}
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package-lock.json
coverage
node_modules
.travis.yml
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: node_js
node_js:
- "4"
- "5"
- "6"
- "7"
- "node"
- "iojs"
- "8"
- "9"
after_success:
- npm run coverage && npm run coveralls
- npm run coverage && npm run coveralls
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ or include it in your node.js module and use like this:
let server = new TelegramServer(serverConfig);
server.start().then(()=>yourTests());
```

### Options

You can pass options like this:
Expand Down Expand Up @@ -118,21 +117,43 @@ Client emulation is very easy. You can use built in client class:
Or you can take a look at `src/modules/telegramClient` and make client in any
language you want.

### Stop server
```js
server.stop().then(()=>doMore());
```
Please beware that server needs much time (about 4 seconds) to stop (that's express issue).

### Full sample
Your test code can look like this:
```js
const TelegramServer = require('telegram-test-api');
const TelegramBot = require('node-telegram-bot-api');

describe('Telegram bot test', () => {
let serverConfig = {port: 9001};
const token = 'sampleToken';
let server;
let client;
beforeEach(() => {
server = new TelegramServer(serverConfig);
return server.start().then(() => {
client = server.getClient(token);
});
});

afterEach(function () {
this.slow(2000);
this.timeout(10000);
return server.stop();
});

it('should greet Masha and Sasha', function testFull() {
this.slow(400);
this.timeout(800);
let serverConfig = {port: 9000};
let server = new TelegramServer(serverConfig);
let token = 'sampleToken';
let client = server.getClient(token);
let message = client.makeMessage('/start');
let telegramBot,
testBot;
return server.start()
.then(()=> client.sendMessage(message))
return client.sendMessage(message)
.then(()=> {
let botOptions = {polling: true, baseApiUrl: server.ApiURL};
telegramBot = new TelegramBot(token, botOptions);
Expand Down Expand Up @@ -160,4 +181,5 @@ Your test code can look like this:
return true;
})
});
});
```
12 changes: 6 additions & 6 deletions bin/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const
TelegramServer = require('../index'),
config = require('../config/config.json'),
server = new TelegramServer(config);

server.start();
const
TelegramServer = require('../index'),
config = require('../config/config.json'),
server = new TelegramServer(config);

server.start();
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* If running on Nodejs 5.x and below, we load the transpiled code.
* Otherwise, we use the ES6 code.
*/

/* eslint-disable global-require*/

const majorVersion = parseInt(process.versions.node.split('.')[0], 10);
if (majorVersion <= 5) {
module.exports = require('./lib/telegramServer');
} else {
module.exports = require('./src/telegramServer');
}
/**
* If running on Nodejs below 6.4, we load the transpiled code.
* Otherwise, we use the ES6 code.
*/

/* eslint-disable global-require */
const semver = require('semver');

if (semver.satisfies(process.version, '>=6.4.0')) {
module.exports = require('./src/telegramServer');
} else {
module.exports = require('./lib/telegramServer');
}
Loading

0 comments on commit 48a6e3f

Please sign in to comment.