forked from node-formidable/formidable
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seems to blow up after the first test instead of running all, got to debug.
- Loading branch information
Showing
4 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 4 additions & 7 deletions
11
...fixture/js/special-chars-in-filename.json → test/fixture/js/special-chars-in-filename.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |