mirror of https://github.com/lukechilds/node.git
Browse Source
- No more single line "node.js:176:9" errors - No more strange output when error happens on first line due to module wrapper function. - A few tests to check these thingsv0.7.4-release
Ryan Dahl
15 years ago
6 changed files with 115 additions and 47 deletions
@ -1,40 +1,40 @@ |
|||
require("../common"); |
|||
|
|||
http = require("http"); |
|||
|
|||
var request_count = 1000; |
|||
var response_body = '{"ok": true}'; |
|||
var body = '{"ok": true}'; |
|||
|
|||
var server = process.http.createServer(function(req, res) { |
|||
res.sendHeader(200, {'Content-Type': 'text/javascript'}); |
|||
res.sendBody(response_body); |
|||
res.finish(); |
|||
var server = http.createServer(function(req, res) { |
|||
res.writeHead(200, {'Content-Type': 'text/javascript'}); |
|||
res.write(body); |
|||
res.end(); |
|||
}); |
|||
server.listen(PORT, 4024); |
|||
server.listen(PORT); |
|||
|
|||
var requests_ok = 0; |
|||
var requests_complete = 0; |
|||
|
|||
function onLoad () { |
|||
server.addListener('listening', function () { |
|||
for (var i = 0; i < request_count; i++) { |
|||
process.http.cat('http://localhost:'+PORT+'/', 'utf8') |
|||
.addCallback(function (content) { |
|||
assert.equal(response_body, content) |
|||
http.cat('http://localhost:'+PORT+'/', 'utf8', function (err, content) { |
|||
requests_complete++; |
|||
if (err) { |
|||
print("-"); |
|||
} else { |
|||
assert.equal(body, content) |
|||
print("."); |
|||
requests_ok++; |
|||
requests_complete++; |
|||
if (requests_ok == request_count) { |
|||
puts("\nrequests ok: " + requests_ok); |
|||
server.close(); |
|||
} |
|||
}) |
|||
.addErrback(function() { |
|||
print("-"); |
|||
requests_complete++; |
|||
//process.debug("error " + i);
|
|||
}); |
|||
} |
|||
if (requests_complete == request_count) { |
|||
puts("\nrequests ok: " + requests_ok); |
|||
server.close(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
|
|||
process.addListener("exit", function () { |
|||
assert.equal(request_count, requests_complete); |
|||
assert.equal(request_count, requests_ok); |
|||
assert.equal(request_count, requests_complete); |
|||
assert.equal(request_count, requests_ok); |
|||
}); |
|||
|
@ -0,0 +1,3 @@ |
|||
|
|||
JSON.parse(undefined); |
|||
|
@ -0,0 +1,3 @@ |
|||
process.nextTick(function () { |
|||
JSON.parse(undefined); |
|||
}); |
@ -0,0 +1,50 @@ |
|||
require("../common"); |
|||
exec = require('child_process').exec, |
|||
path = require('path'); |
|||
|
|||
exits = 0; |
|||
|
|||
function errExec (script, callback) { |
|||
var cmd = process.argv[0] + ' ' + path.join(fixturesDir, script); |
|||
return exec(cmd, function (err, stdout, stderr) { |
|||
// There was some error
|
|||
assert.ok(err); |
|||
|
|||
// More than one line of error output.
|
|||
assert.ok(stderr.split('\n').length > 2); |
|||
|
|||
// Assert the script is mentioned in error output.
|
|||
assert.ok(stderr.indexOf(script) >= 0); |
|||
|
|||
// Proxy the args for more tests.
|
|||
callback(err, stdout, stderr); |
|||
|
|||
// Count the tests
|
|||
exits++; |
|||
|
|||
puts('.'); |
|||
}); |
|||
} |
|||
|
|||
|
|||
// Simple throw error
|
|||
errExec('throws_error.js', function (err, stdout, stderr) { |
|||
assert.ok(/blah/.test(stderr)); |
|||
}); |
|||
|
|||
|
|||
// Trying to JSON.parse(undefined)
|
|||
errExec('throws_error2.js', function (err, stdout, stderr) { |
|||
assert.ok(/JSON/.test(stderr)); |
|||
}); |
|||
|
|||
|
|||
// Trying to JSON.parse(undefined) in nextTick
|
|||
errExec('throws_error3.js', function (err, stdout, stderr) { |
|||
assert.ok(/JSON/.test(stderr)); |
|||
}); |
|||
|
|||
|
|||
process.addListener('exit', function () { |
|||
assert.equal(3, exits); |
|||
}); |
Loading…
Reference in new issue