Skip to content

Commit

Permalink
migrating to mocha testing
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Apr 12, 2016
1 parent da3c9dd commit 7fec8bc
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 293 deletions.
11 changes: 11 additions & 0 deletions .istanbul.yml
@@ -0,0 +1,11 @@
reporting:
reports:
- lcov
- text
- text-summary
check:
global:
statements: 100
lines: 100
branches: 100
functions: 100
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -2,4 +2,5 @@ language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
sudo: false
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -55,6 +55,7 @@ exports.extend = function(app, options) {
};

// Indicate whether the file was truncated
/*istanbul ignore next*/
file.on('limit', function() {
data.truncated = true;
});
Expand Down
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -5,7 +5,8 @@
"author": "Dav Glass <davglass@gmail.com>",
"main": "index.js",
"scripts": {
"test": "istanbul cover --print both vows -- --spec ./tests/*.js"
"test": "jenkins-mocha tests/*.js",
"posttest": "istanbul check-coverage"
},
"repository": {
"type": "git",
Expand All @@ -29,7 +30,8 @@
},
"devDependencies": {
"express": "~4.8.6",
"istanbul": "~0.3.6",
"istanbul": "^0.4.3",
"jenkins-mocha": "^2.6.0",
"portfinder": "~0.2.1",
"request": "~2.40.0",
"vows": "~0.8.1"
Expand Down
135 changes: 61 additions & 74 deletions tests/file.js
Expand Up @@ -3,8 +3,7 @@
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
var vows = require('vows'),
assert = require('assert'),
var assert = require('assert'),
bb = require('../'),
express = require('express'),
fs = require('fs'),
Expand All @@ -25,78 +24,66 @@ var setup = function(app) {
});
};

var tests = {
'setup hack': {
topic: function() {
var done = this.callback;
portfinder.getPort(function(e, p) {
port = p;
setup(app);
base += p;
done();
});
},
'complete': function() {},
'and should upload a file': {
topic: function() {
var done = this.callback;
var r = request({
method: 'POST',
url: base + '/',
json: true
}, function(err, res, body) {
done(err, body);
});
var form = r.form();
form.append('foobar', 1);
form.append('the-file', fs.createReadStream(__filename));
},
'properly': function(d) {
assert.ok(d);
assert.ok(d.body);
assert.equal(d.body.foobar, 1);
assert.ok(d.files);
assert.ok(d.files['the-file']);
assert.ok(d.files['the-file'].file);
assert.ok(fs.existsSync(d.files['the-file'].file));
}
},
'and should upload files of the same name': {
topic: function() {
var done = this.callback;
var r = request({
method: 'POST',
url: base + '/',
json: true
}, function(err, res, body) {
done(err, body);
});
var form = r.form();
form.append('foobar', 1);
form.append('the-file', fs.createReadStream(__filename));
form.append('the-file', fs.createReadStream(__filename));
form.append('the-file', fs.createReadStream(__filename));
},
'properly': function(d) {
assert.ok(d);
assert.ok(d.body);
assert.equal(d.body.foobar, 1);
assert.ok(d.files);
assert.ok(d.files['the-file']);
assert.isArray(d.files['the-file']);
assert.ok(d.files['the-file'][0].file);
assert.ok(d.files['the-file'][1].file);
assert.ok(d.files['the-file'][2].file);
assert.ok(fs.existsSync(d.files['the-file'][0].file));
assert.ok(fs.existsSync(d.files['the-file'][1].file));
assert.ok(fs.existsSync(d.files['the-file'][2].file));
}
}
},
teardown: function() {
describe('express-busboy: file upload', function() {

before(function(done) {
portfinder.getPort(function(e, p) {
port = p;
setup(app);
base += p;
done();
});
});

after(function() {
app._server.close();
}
};
});

vows.describe('express-busboy: file upload').addBatch(tests).export(module);
it('should upload a file', function(done) {
var r = request({
method: 'POST',
url: base + '/',
json: true
}, function(err, res, d) {
assert.ok(d);
assert.ok(d.body);
assert.equal(d.body.foobar, 1);
assert.ok(d.files);
assert.ok(d.files['the-file']);
assert.ok(d.files['the-file'].file);
assert.ok(fs.existsSync(d.files['the-file'].file));
done();
});
var form = r.form();
form.append('foobar', 1);
form.append('the-file', fs.createReadStream(__filename));
});

it('should upload files of the same name', function(done) {
var r = request({
method: 'POST',
url: base + '/',
json: true
}, function(err, res, d) {
assert.ok(d);
assert.ok(d.body);
assert.equal(d.body.foobar, 1);
assert.ok(d.files);
assert.ok(d.files['the-file']);
assert.equal(true, Array.isArray(d.files['the-file']));
assert.ok(d.files['the-file'][0].file);
assert.ok(d.files['the-file'][1].file);
assert.ok(d.files['the-file'][2].file);
assert.ok(fs.existsSync(d.files['the-file'][0].file));
assert.ok(fs.existsSync(d.files['the-file'][1].file));
assert.ok(fs.existsSync(d.files['the-file'][2].file));
done();
});
var form = r.form();
form.append('foobar', 1);
form.append('the-file', fs.createReadStream(__filename));
form.append('the-file', fs.createReadStream(__filename));
form.append('the-file', fs.createReadStream(__filename));
});

});
45 changes: 16 additions & 29 deletions tests/index.js
Expand Up @@ -3,37 +3,24 @@
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
var vows = require('vows'),
assert = require('assert'),
var assert = require('assert'),
bb = require('../'),
express = require('express'),
app = express();

var tests = {
'should export': {
topic: function() {
return bb;
},
'an extend method': function(d) {
assert.isFunction(d.extend);
}
},
'should extend': {
topic: function() {
return bb.extend(app, { upload: true });
},
'app': function(d) {
assert.equal(d, app);
}
},
'should not extend': {
topic: function() {
return bb.extend(app);
},
'app twice': function(d) {
assert.equal(d, app);
}
}
};
describe('express-busboy', function() {

it('should export an extend method', function() {
assert.equal(typeof bb.extend, 'function');
});

it('should extend', function() {
var d = bb.extend(app, { upload: true });
assert.equal(d, app);
});
it('should not extend app twice', function() {
var d = bb.extend(app);
assert.equal(d, app);
});
});

vows.describe('express-busboy').addBatch(tests).export(module);

0 comments on commit 7fec8bc

Please sign in to comment.