Skip to content

Commit

Permalink
Reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Mar 22, 2017
1 parent aed57b7 commit 4d6028c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const glob = require('glob');
const net = require('net');
const path = require('path');
const url = require('url');
const Promise = require('bluebird');
const Session = require('./lib/session');


Expand Down Expand Up @@ -64,7 +65,7 @@ Nntp.prototype.listen = function (...args) {
}
}

return this.server.listen(...args);
return Promise.fromCallback(cb => { this.server.listen(...args, cb); });
};


Expand Down
33 changes: 17 additions & 16 deletions test/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@

const net = require('net');
const Server = require('../');
const drive = require('./helpers').drive;
const asline = require('./helpers').asline;


describe('commands', function () {
let port, socket;
let port, socket, client;

before(function (callback) {
let nntp = new Server('nntp://localhost', { requireAuth: true });

nntp.listen(function (err) {
if (err) {
callback(err);
return;
}
before(function () {
let nntp = new Server('nntp://localhost');

return nntp.listen().then(() => {
port = nntp.server.address().port;
callback();
});
});


beforeEach(function (callback) {
socket = net.connect(port, callback);
socket = net.connect(port, err => {
client = asline(socket, { timeout: 2000 });
callback(err);
});
});

afterEach(function (callback) {

afterEach(function () {
socket.end();
socket.once('close', callback);
});


it('DATE', function () {
return drive(socket, { timeout: 2000 })
.send('DATE')
.expect(/^111 \d{14}$/);
return client
.send('DATE')
.expect(/^111 \d{14}$/);
});

});
2 changes: 1 addition & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Promise.prototype._propagateFrom = function (src, ...args) {
};


module.exports.drive = function create_drive(stream, options = {}) {
module.exports.asline = function create_asline(stream, options = {}) {
stream.setEncoding('utf8');

let ret = Promise.resolve();
Expand Down

0 comments on commit 4d6028c

Please sign in to comment.