Skip to content

Commit

Permalink
Initial fixture verifier test
Browse files Browse the repository at this point in the history
Seems to blow up after the first test instead of running all, got to
debug.
  • Loading branch information
felixge committed Sep 9, 2011
1 parent b9876eb commit 08111bd
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -5,7 +5,9 @@
"devDependencies": {
"gently": "0.8.0",
"far": "0.0.7",
"fast-or-slow": "0.0.5"
"fast-or-slow": "0.0.5",
"findit": "0.1.1",
"hashish": "0.0.4"
},
"directories": {
"lib": "./lib"
Expand Down
4 changes: 4 additions & 0 deletions test/common.js
Expand Up @@ -6,6 +6,10 @@ exports.dir = {
root: root,
lib: root + '/lib',
fixture: root + '/test/fixture',
tmp: root + '/test/tmp',
};

exports.port = 13532;

exports.formidable = require('..');
exports.fastOrSlow = require('fast-or-slow');
@@ -1,13 +1,10 @@
var properFilename = '/ \ ? % * | " < > . ☃ ; \' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt';

function expect(filename) {
return {
fields: [{name: 'title', value: 'Weird filename'}],
files: [{
name: filename,
fixture: properFilename,
}]
};
return [
{type: 'field', name: 'title', value: 'Weird filename'},
{type: 'file', name: filename, fixture: properFilename},
];
};

module.exports = {
Expand Down
72 changes: 72 additions & 0 deletions test/slow/test-fixtures.js
@@ -0,0 +1,72 @@
var hashish = require('hashish');
var fs = require('fs');
var findit = require('findit');
var path = require('path');
var http = require('http');
var net = require('net');
var assert = require('assert');

var common = require('../common');
var test = common.fastOrSlow.slow();
var formidable = common.formidable;

var server;
test.before(function(done) {
if (server) return done();

server = http.createServer();
server.listen(common.port, done);
});

function testFixture(name, fixture) {
test('fixture: ' + name, function(done) {
console.log(this.name);
uploadFixture(name, function(err, parts) {
if (err) return done(err);

fixture.forEach(function(expectedPart, i) {
var parsedPart = parts[i];
assert.equal(parsedPart.type, expectedPart.type);
});

done();
});
});
};

function uploadFixture(name, cb) {
server.once('request', function(req, res) {
var form = new formidable.IncomingForm();
form.uploadDir = common.dir.tmp;
form.parse(req);

var parts = [];
form
.on('error', cb)
.on('fileBegin', function(name, value) {
parts.push({type: 'file', name: name, value: value});
})
.on('field', function(name, value) {
parts.push({type: 'field', name: name, value: value});
})
.on('end', function() {
cb(null, parts);
});
});

var socket = net.createConnection(common.port);
var file = fs.createReadStream(common.dir.fixture + '/http/' + name);

file.pipe(socket);
}

findit
.sync(common.dir.fixture + '/js')
.forEach(function(jsPath) {
if (!/\.js$/.test(jsPath)) return;

var group = path.basename(jsPath, '.js');
hashish.forEach(require(jsPath), function(fixture, name) {
testFixture(group + '/' + name, fixture);
});
});

0 comments on commit 08111bd

Please sign in to comment.