Browse Source

CommonJS testing for node.js

Refactored test suite to use the assert module for testing rather than
mjsunit.
v0.7.4-release
Felix Geisendörfer 15 years ago
committed by Ryan Dahl
parent
commit
530328f12b
  1. 176
      lib/assert.js
  2. 1033
      lib/util.js
  3. 5
      test/mjsunit/common.js
  4. 8
      test/mjsunit/disabled/test-cat.js
  5. 6
      test/mjsunit/disabled/test-http-stress.js
  6. 4
      test/mjsunit/fixtures/b/c.js
  7. 6
      test/mjsunit/test-buffered-file.js
  8. 16
      test/mjsunit/test-byte-length.js
  9. 4
      test/mjsunit/test-chdir.js
  10. 6
      test/mjsunit/test-delayed-require.js
  11. 8
      test/mjsunit/test-event-emitter-add-listeners.js
  12. 6
      test/mjsunit/test-exception-handler.js
  13. 10
      test/mjsunit/test-exec.js
  14. 4
      test/mjsunit/test-file-cat-noexist.js
  15. 4
      test/mjsunit/test-fs-sendfile.js
  16. 20
      test/mjsunit/test-fs-stat.js
  17. 2
      test/mjsunit/test-fs-write.js
  18. 6
      test/mjsunit/test-http-cat.js
  19. 4
      test/mjsunit/test-http-chunked.js
  20. 4
      test/mjsunit/test-http-client-race.js
  21. 8
      test/mjsunit/test-http-client-upload.js
  22. 2
      test/mjsunit/test-http-malformed-request.js
  23. 4
      test/mjsunit/test-http-proxy.js
  24. 30
      test/mjsunit/test-http-server.js
  25. 42
      test/mjsunit/test-http-tls.js
  26. 30
      test/mjsunit/test-http.js
  27. 10
      test/mjsunit/test-keep-alive.js
  28. 4
      test/mjsunit/test-memory-usage.js
  29. 4
      test/mjsunit/test-mkdir-rmdir.js
  30. 50
      test/mjsunit/test-module-loading.js
  31. 14
      test/mjsunit/test-multipart.js
  32. 8
      test/mjsunit/test-process-buffering.js
  33. 6
      test/mjsunit/test-process-kill.js
  34. 6
      test/mjsunit/test-process-simple.js
  35. 2
      test/mjsunit/test-process-spawn-loop.js
  36. 2
      test/mjsunit/test-promise-cancel.js
  37. 26
      test/mjsunit/test-promise-timeout.js
  38. 48
      test/mjsunit/test-promise-wait.js
  39. 4
      test/mjsunit/test-readdir.js
  40. 4
      test/mjsunit/test-remote-module-loading.js
  41. 4
      test/mjsunit/test-signal-handler.js
  42. 4
      test/mjsunit/test-stat-handler.js
  43. 4
      test/mjsunit/test-tcp-binary.js
  44. 6
      test/mjsunit/test-tcp-many-clients.js
  45. 32
      test/mjsunit/test-tcp-pingpong-delay.js
  46. 32
      test/mjsunit/test-tcp-pingpong.js
  47. 10
      test/mjsunit/test-tcp-reconnect.js
  48. 6
      test/mjsunit/test-tcp-throttle-kernel-buffer.js
  49. 8
      test/mjsunit/test-tcp-throttle.js
  50. 14
      test/mjsunit/test-tcp-timeout.js
  51. 40
      test/mjsunit/test-tcp-tls.js
  52. 14
      test/mjsunit/test-timers.js
  53. 2
      test/mjsunit/test-umask.js
  54. 2
      test/mjsunit/test-utf8-scripts.js
  55. 4
      test/mjsunit/test-wait-ordering.js

176
lib/assert.js

@ -0,0 +1,176 @@
var sys = require('sys');
var util = require('util');
var assert = exports;
assert.AssertionError = function (options) {
this.name = "AssertionError";
this.message = options.message;
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
Error.captureStackTrace(this, fail);
};
sys.inherits(assert.AssertionError, Error);
// assert.AssertionError instanceof Error
// assert.AssertionError.prototype = Object.create(Error.prototype);
// At present only the three keys mentioned above are used and
// understood by the spec. Implementations or sub modules can pass
// other keys to the AssertionError's constructor - they will be
// ignored.
// 3. All of the following functions must throw an AssertionError
// when a corresponding condition is not met, with a message that
// may be undefined if not provided. All assertion methods provide
// both the actual and expected values to the assertion error for
// display purposes.
function fail(actual, expected, message, operator) {
throw new assert.AssertionError({
message: message,
actual: actual,
expected: expected,
operator: operator
});
}
// 4. Pure assertion tests whether a value is truthy, as determined
// by !!guard.
// assert.ok(guard, message_opt);
// This statement is equivalent to assert.equal(true, guard,
// message_opt);. To test strictly for the value true, use
// assert.strictEqual(true, guard, message_opt);.
assert.ok = function (value, message) {
if (!!!value)
fail(value, true, message, "==");
};
// 5. The equality assertion tests shallow, coercive equality with
// ==.
// assert.equal(actual, expected, message_opt);
assert.equal = function (actual, expected, message) {
if (actual != expected)
fail(actual, expected, message, "==");
};
// 6. The non-equality assertion tests for whether two objects are not equal
// with != assert.notEqual(actual, expected, message_opt);
assert.notEqual = function (actual, expected, message) {
if (actual == expected)
fail(actual, expected, message, "!=");
};
// 7. The equivalence assertion tests a deep equality relation.
// assert.deepEqual(actual, expected, message_opt);
exports.deepEqual = function (actual, expected, message) {
if (!deepEqual(actual, expected))
fail(actual, expected, message, "deepEqual");
};
function deepEqual(actual, expected) {
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
// 7.2. If the expected value is a Date object, the actual value is
// equivalent if it is also a Date object that refers to the same time.
} else if (actual instanceof Date
&& expected instanceof Date) {
return actual.toValue() === expected.toValue();
// 7.3. Other pairs that do not both pass typeof value == "object",
// equivalence is determined by ==.
} else if (typeof actual != 'object'
&& typeof expected != 'object') {
return actual == expected;
// 7.4. For all other Object pairs, including Array objects, equivalence is
// determined by having the same number of owned properties (as verified
// with Object.prototype.hasOwnProperty.call), the same set of keys
// (although not necessarily the same order), equivalent values for every
// corresponding key, and an identical "prototype" property. Note: this
// accounts for both named and indexed properties on Arrays.
} else {
return actual.prototype === expected.prototype && objEquiv(actual, expected);
}
}
function objEquiv(a, b, stack) {
return (
!util.no(a) && !util.no(b) &&
arrayEquiv(
util.sort(util.object.keys(a)),
util.sort(util.object.keys(b))
) &&
util.object.keys(a).every(function (key) {
return deepEqual(a[key], b[key], stack);
})
);
}
function arrayEquiv(a, b, stack) {
return util.isArrayLike(b) &&
a.length == b.length &&
util.zip(a, b).every(util.apply(function (a, b) {
return deepEqual(a, b, stack);
}));
}
// 8. The non-equivalence assertion tests for any deep inequality.
// assert.notDeepEqual(actual, expected, message_opt);
exports.notDeepEqual = function (actual, expected, message) {
if (deepEqual(actual, expected))
fail(actual, expected, message, "notDeepEqual");
};
// 9. The strict equality assertion tests strict equality, as determined by ===.
// assert.strictEqual(actual, expected, message_opt);
assert.strictEqual = function (actual, expected, message) {
if (actual !== expected)
fail(actual, expected, message, "===");
};
// 10. The strict non-equality assertion tests for strict inequality, as determined by !==.
// assert.notStrictEqual(actual, expected, message_opt);
assert.notStrictEqual = function (actual, expected, message) {
if (actual === expected)
fail(actual, expected, message, "!==");
};
// 11. Expected to throw an error:
// assert.throws(block, Error_opt, message_opt);
assert["throws"] = function (block, Error, message) {
var threw = false,
exception = null;
if (typeof Error == "string") {
message = Error;
Error = undefined;
} else {
Error = message;
message = "";
}
try {
block();
} catch (e) {
threw = true;
exception = e;
}
if (!threw)
fail("Expected exception" + (message ? ": " + message : ""));
};

1033
lib/util.js

File diff suppressed because it is too large

5
test/mjsunit/common.js

@ -6,10 +6,11 @@ exports.libDir = path.join(exports.testDir, "../../lib");
require.paths.unshift(exports.libDir); require.paths.unshift(exports.libDir);
var mjsunit = require("mjsunit"); var assert = require('assert');
var sys = require("sys"); var sys = require("sys");
process.mixin(exports, mjsunit, sys); process.mixin(exports, sys);
exports.assert = require('assert');
exports.posix = require("posix"); exports.posix = require("posix");
exports.path = path; exports.path = path;

8
test/mjsunit/disabled/test-cat.js

@ -22,7 +22,7 @@ var successes = 0;
var promise = process.cat("http://localhost:"+PORT, "utf8"); var promise = process.cat("http://localhost:"+PORT, "utf8");
promise.addCallback(function (content) { promise.addCallback(function (content) {
assertEquals(body, content); assert.equal(body, content);
server.close(); server.close();
successes += 1; successes += 1;
}); });
@ -38,7 +38,7 @@ var x = process.path.join(fixtures, "x.txt");
promise = process.cat(x, "utf8"); promise = process.cat(x, "utf8");
promise.addCallback(function (content) { promise.addCallback(function (content) {
assertEquals("xyz", content.replace(/[\r\n]/, '')); assert.equal("xyz", content.replace(/[\r\n]/, ''));
successes += 1; successes += 1;
}); });
@ -47,6 +47,6 @@ promise.addErrback(function () {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(2, successes); assert.equal(2, successes);
assertEquals(0, errors); assert.equal(0, errors);
}); });

6
test/mjsunit/disabled/test-http-stress.js

@ -18,7 +18,7 @@ function onLoad () {
for (var i = 0; i < request_count; i++) { for (var i = 0; i < request_count; i++) {
process.http.cat('http://localhost:'+PORT+'/', 'utf8') process.http.cat('http://localhost:'+PORT+'/', 'utf8')
.addCallback(function (content) { .addCallback(function (content) {
assertEquals(response_body, content) assert.equal(response_body, content)
print("."); print(".");
requests_ok++; requests_ok++;
requests_complete++; requests_complete++;
@ -36,6 +36,6 @@ function onLoad () {
} }
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(request_count, requests_complete); assert.equal(request_count, requests_complete);
assertEquals(request_count, requests_ok); assert.equal(request_count, requests_ok);
}); });

4
test/mjsunit/fixtures/b/c.js

@ -1,10 +1,10 @@
var d = require("./d"); var d = require("./d");
var mjsunit = require("mjsunit"); var assert = require("assert");
var package = require("./package"); var package = require("./package");
mjsunit.assertEquals("world", package.hello); assert.equal("world", package.hello);
debug("load fixtures/b/c.js"); debug("load fixtures/b/c.js");

6
test/mjsunit/test-buffered-file.js

@ -19,11 +19,11 @@ setTimeout(function () {
var out = posix.cat(testTxt).wait(); var out = posix.cat(testTxt).wait();
print("the file contains: "); print("the file contains: ");
p(out); p(out);
assertEquals("hello\nworld\nhello\nworld\n", out); assert.equal("hello\nworld\nhello\nworld\n", out);
var file2 = new File(testTxt, "r"); var file2 = new File(testTxt, "r");
file2.read(5).addCallback(function (data) { file2.read(5).addCallback(function (data) {
puts("read(5): " + JSON.stringify(data)); puts("read(5): " + JSON.stringify(data));
assertEquals("hello", data); assert.equal("hello", data);
posix.unlink(testTxt).addCallback(function () { posix.unlink(testTxt).addCallback(function () {
fileUnlinked = true; fileUnlinked = true;
}); });
@ -33,6 +33,6 @@ setTimeout(function () {
}, 10); }, 10);
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(fileUnlinked); assert.equal(true, fileUnlinked);
puts("done"); puts("done");
}); });

16
test/mjsunit/test-byte-length.js

@ -1,11 +1,15 @@
process.mixin(require("./common")); process.mixin(require("./common"));
assertEquals(14, process._byteLength("Il était tué")); assert.equal(14, process._byteLength("Il était tué"));
assertEquals(14, process._byteLength("Il était tué", "utf8")); assert.equal(14, process._byteLength("Il était tué", "utf8"));
assertEquals(12, process._byteLength("Il était tué", "ascii")); assert.equal(12, process._byteLength("Il était tué", "ascii"));
assertEquals(12, process._byteLength("Il était tué", "binary")); assert.equal(12, process._byteLength("Il était tué", "binary"));
assertThrows('process._byteLength()'); assert.throws(function() {
assertThrows('process._byteLength(5)'); process._byteLength();
});
assert.throws(function() {
process._byteLength(5);
});

4
test/mjsunit/test-chdir.js

@ -2,8 +2,8 @@ process.mixin(require("./common"));
var dirname = path.dirname(__filename); var dirname = path.dirname(__filename);
assertTrue(process.cwd() !== dirname); assert.equal(true, process.cwd() !== dirname);
process.chdir(dirname); process.chdir(dirname);
assertTrue(process.cwd() === dirname); assert.equal(true, process.cwd() === dirname);

6
test/mjsunit/test-delayed-require.js

@ -5,7 +5,7 @@ setTimeout(function () {
}, 50); }, 50);
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue("A" in a); assert.equal(true, "A" in a);
assertEquals("A", a.A()); assert.equal("A", a.A());
assertEquals("D", a.D()); assert.equal("D", a.D());
}); });

8
test/mjsunit/test-event-emitter-add-listeners.js

@ -13,8 +13,8 @@ e.addListener("newListener", function (event, listener) {
e.addListener("hello", function (a, b) { e.addListener("hello", function (a, b) {
puts("hello"); puts("hello");
times_hello_emited += 1 times_hello_emited += 1
assertEquals("a", a); assert.equal("a", a);
assertEquals("b", b); assert.equal("b", b);
}); });
puts("start"); puts("start");
@ -22,8 +22,8 @@ puts("start");
e.emit("hello", "a", "b"); e.emit("hello", "a", "b");
process.addListener("exit", function () { process.addListener("exit", function () {
assertArrayEquals(["hello"], events_new_listener_emited); assert.deepEqual(["hello"], events_new_listener_emited);
assertEquals(1, times_hello_emited); assert.equal(1, times_hello_emited);
}); });

6
test/mjsunit/test-exception-handler.js

@ -5,13 +5,13 @@ var caughtException = false;
process.addListener('uncaughtException', function (e) { process.addListener('uncaughtException', function (e) {
puts("uncaught exception! 1"); puts("uncaught exception! 1");
assertEquals(MESSAGE, e.message); assert.equal(MESSAGE, e.message);
caughtException = true; caughtException = true;
}); });
process.addListener('uncaughtException', function (e) { process.addListener('uncaughtException', function (e) {
puts("uncaught exception! 2"); puts("uncaught exception! 2");
assertEquals(MESSAGE, e.message); assert.equal(MESSAGE, e.message);
caughtException = true; caughtException = true;
}); });
@ -21,5 +21,5 @@ setTimeout(function() {
process.addListener("exit", function () { process.addListener("exit", function () {
puts("exit"); puts("exit");
assertTrue(caughtException); assert.equal(true, caughtException);
}); });

10
test/mjsunit/test-exec.js

@ -18,13 +18,13 @@ exec("ls /").addCallback(function (out) {
exec("ls /DOES_NOT_EXIST").addCallback(function (out) { exec("ls /DOES_NOT_EXIST").addCallback(function (out) {
success_count++; success_count++;
p(out); p(out);
assertTrue(out != ""); assert.equal(true, out != "");
}).addErrback(function (code, out, err) { }).addErrback(function (code, out, err) {
error_count++; error_count++;
assertEquals("", out); assert.equal("", out);
assertTrue(code != 0); assert.equal(true, code != 0);
puts("error!: " + code); puts("error!: " + code);
puts("stdout: " + JSON.stringify(out)); puts("stdout: " + JSON.stringify(out));
@ -33,6 +33,6 @@ exec("ls /DOES_NOT_EXIST").addCallback(function (out) {
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(1, success_count); assert.equal(1, success_count);
assertEquals(1, error_count); assert.equal(1, error_count);
}); });

4
test/mjsunit/test-file-cat-noexist.js

@ -7,7 +7,7 @@ var promise = posix.cat(filename, "raw");
promise.addCallback(function (content) { promise.addCallback(function (content) {
debug("cat returned some content: " + content); debug("cat returned some content: " + content);
debug("this shouldn't happen as the file doesn't exist..."); debug("this shouldn't happen as the file doesn't exist...");
assertTrue(false); assert.equal(true, false);
}); });
promise.addErrback(function () { promise.addErrback(function () {
@ -16,5 +16,5 @@ promise.addErrback(function () {
process.addListener("exit", function () { process.addListener("exit", function () {
puts("done"); puts("done");
assertTrue(got_error); assert.equal(true, got_error);
}); });

4
test/mjsunit/test-fs-sendfile.js

@ -12,7 +12,7 @@ var server = tcp.createServer(function (socket) {
client.close(); client.close();
socket.close(); socket.close();
server.close(); server.close();
assertEquals(expected, found); assert.equal(expected, found);
}); });
}); });
server.listen(PORT); server.listen(PORT);
@ -21,7 +21,7 @@ var client = tcp.createConnection(PORT);
client.addListener("connect", function () { client.addListener("connect", function () {
posix.open(x,process.O_RDONLY, 0666).addCallback(function (fd) { posix.open(x,process.O_RDONLY, 0666).addCallback(function (fd) {
posix.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) { posix.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) {
assertEquals(expected.length, size); assert.equal(expected.length, size);
}); });
}); });
}); });

20
test/mjsunit/test-fs-stat.js

@ -22,33 +22,33 @@ posix.stat(__filename).addCallback(function (s) {
success_count++; success_count++;
puts("isDirectory: " + JSON.stringify( s.isDirectory() ) ); puts("isDirectory: " + JSON.stringify( s.isDirectory() ) );
assertFalse(s.isDirectory()); assert.equal(false, s.isDirectory());
puts("isFile: " + JSON.stringify( s.isFile() ) ); puts("isFile: " + JSON.stringify( s.isFile() ) );
assertTrue(s.isFile()); assert.equal(true, s.isFile());
puts("isSocket: " + JSON.stringify( s.isSocket() ) ); puts("isSocket: " + JSON.stringify( s.isSocket() ) );
assertFalse(s.isSocket()); assert.equal(false, s.isSocket());
puts("isBlockDevice: " + JSON.stringify( s.isBlockDevice() ) ); puts("isBlockDevice: " + JSON.stringify( s.isBlockDevice() ) );
assertFalse(s.isBlockDevice()); assert.equal(false, s.isBlockDevice());
puts("isCharacterDevice: " + JSON.stringify( s.isCharacterDevice() ) ); puts("isCharacterDevice: " + JSON.stringify( s.isCharacterDevice() ) );
assertFalse(s.isCharacterDevice()); assert.equal(false, s.isCharacterDevice());
puts("isFIFO: " + JSON.stringify( s.isFIFO() ) ); puts("isFIFO: " + JSON.stringify( s.isFIFO() ) );
assertFalse(s.isFIFO()); assert.equal(false, s.isFIFO());
puts("isSymbolicLink: " + JSON.stringify( s.isSymbolicLink() ) ); puts("isSymbolicLink: " + JSON.stringify( s.isSymbolicLink() ) );
assertFalse(s.isSymbolicLink()); assert.equal(false, s.isSymbolicLink());
}).addErrback(function () { }).addErrback(function () {
got_error = true; got_error = true;
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(2, success_count); assert.equal(2, success_count);
assertFalse(got_error); assert.equal(false, got_error);
assertTrue(stats.mtime instanceof Date); assert.equal(true, stats.mtime instanceof Date);
}); });

2
test/mjsunit/test-fs-write.js

@ -16,6 +16,6 @@ posix.open(fn, process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0644).addCa
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(expected, found); assert.equal(expected, found);
}); });

6
test/mjsunit/test-http-cat.js

@ -20,7 +20,7 @@ var bad_server_got_error = false;
http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) { http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) {
puts("got response"); puts("got response");
got_good_server_content = true; got_good_server_content = true;
assertEquals(body, content); assert.equal(body, content);
server.close(); server.close();
}); });
@ -31,6 +31,6 @@ http.cat("http://localhost:12312/", "utf8").addErrback(function () {
process.addListener("exit", function () { process.addListener("exit", function () {
puts("exit"); puts("exit");
assertTrue(got_good_server_content); assert.equal(true, got_good_server_content);
assertTrue(bad_server_got_error); assert.equal(true, bad_server_got_error);
}); });

4
test/mjsunit/test-http-chunked.js

@ -13,10 +13,10 @@ server.listen(PORT);
http.cat("http://localhost:"+PORT+"/", "utf8") http.cat("http://localhost:"+PORT+"/", "utf8")
.addCallback(function (data) { .addCallback(function (data) {
assertEquals(UTF8_STRING, data); assert.equal(UTF8_STRING, data);
server.close(); server.close();
}) })
.addErrback(function() { .addErrback(function() {
assertUnreachable('http.cat should succeed in < 1000ms'); assert.ok(false, 'http.cat should succeed in < 1000ms');
}) })
.timeout(1000); .timeout(1000);

4
test/mjsunit/test-http-client-race.js

@ -37,6 +37,6 @@ client.get("/1").finish(function (res1) {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(body1_s, body1); assert.equal(body1_s, body1);
assertEquals(body2_s, body2); assert.equal(body2_s, body2);
}); });

8
test/mjsunit/test-http-client-upload.js

@ -7,7 +7,7 @@ var server_req_complete = false;
var client_res_complete = false; var client_res_complete = false;
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
assertEquals("POST", req.method); assert.equal("POST", req.method);
req.setBodyEncoding("utf8"); req.setBodyEncoding("utf8");
req.addListener("body", function (chunk) { req.addListener("body", function (chunk) {
@ -45,7 +45,7 @@ req.finish(function(res) {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals("1\n2\n3\n", sent_body); assert.equal("1\n2\n3\n", sent_body);
assertTrue(server_req_complete); assert.equal(true, server_req_complete);
assertTrue(client_res_complete); assert.equal(true, client_res_complete);
}); });

2
test/mjsunit/test-http-malformed-request.js

@ -29,5 +29,5 @@ c.addListener("connect", function () {
// TODO add more! // TODO add more!
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(nrequests_expected, nrequests_completed); assert.equal(nrequests_expected, nrequests_completed);
}); });

4
test/mjsunit/test-http-proxy.js

@ -38,7 +38,7 @@ var req = client.get("/test");
// debug("client req") // debug("client req")
req.finish(function (res) { req.finish(function (res) {
// debug("got res"); // debug("got res");
assertEquals(200, res.statusCode); assert.equal(200, res.statusCode);
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.addListener("body", function (chunk) { body += chunk; }); res.addListener("body", function (chunk) { body += chunk; });
res.addListener("complete", function () { res.addListener("complete", function () {
@ -49,5 +49,5 @@ req.finish(function (res) {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(body, "hello world\n"); assert.equal(body, "hello world\n");
}); });

30
test/mjsunit/test-http-server.js

@ -14,23 +14,23 @@ http.createServer(function (req, res) {
req.id = request_number++; req.id = request_number++;
if (req.id == 0) { if (req.id == 0) {
assertEquals("GET", req.method); assert.equal("GET", req.method);
assertEquals("/hello", req.uri.path); assert.equal("/hello", req.uri.path);
assertEquals("world", req.uri.params["hello"]); assert.equal("world", req.uri.params["hello"]);
assertEquals("b==ar", req.uri.params["foo"]); assert.equal("b==ar", req.uri.params["foo"]);
} }
if (req.id == 1) { if (req.id == 1) {
assertEquals("POST", req.method); assert.equal("POST", req.method);
assertEquals("/quit", req.uri.path); assert.equal("/quit", req.uri.path);
} }
if (req.id == 2) { if (req.id == 2) {
assertEquals("foo", req.headers['x-x']); assert.equal("foo", req.headers['x-x']);
} }
if (req.id == 3) { if (req.id == 3) {
assertEquals("bar", req.headers['x-x']); assert.equal("bar", req.headers['x-x']);
this.close(); this.close();
//puts("server closed"); //puts("server closed");
} }
@ -64,7 +64,7 @@ c.addListener("receive", function (chunk) {
c.send("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n" c.send("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n"
+"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n"); +"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n");
c.close(); c.close();
assertEquals(c.readyState, "readOnly"); assert.equal(c.readyState, "readOnly");
requests_sent += 2; requests_sent += 2;
} }
@ -75,18 +75,18 @@ c.addListener("eof", function () {
}); });
c.addListener("close", function () { c.addListener("close", function () {
assertEquals(c.readyState, "closed"); assert.equal(c.readyState, "closed");
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(4, request_number); assert.equal(4, request_number);
assertEquals(4, requests_sent); assert.equal(4, requests_sent);
var hello = new RegExp("/hello"); var hello = new RegExp("/hello");
assertTrue(hello.exec(server_response) != null); assert.equal(true, hello.exec(server_response) != null);
var quit = new RegExp("/quit"); var quit = new RegExp("/quit");
assertTrue(quit.exec(server_response) != null); assert.equal(true, quit.exec(server_response) != null);
assertTrue(client_got_eof); assert.equal(true, client_got_eof);
}); });

42
test/mjsunit/test-http-tls.js

@ -28,25 +28,25 @@ var keyPem = posix.cat(fixturesDir+"/test_key.pem").wait();
var http_server=http.createServer(function (req, res) { var http_server=http.createServer(function (req, res) {
var verified = req.connection.verifyPeer(); var verified = req.connection.verifyPeer();
var peerDN = req.connection.getPeerCertificate("DNstring"); var peerDN = req.connection.getPeerCertificate("DNstring");
assertEquals(verified, 1); assert.equal(verified, 1);
assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,"
+ "OU=Test TLS Certificate,CN=localhost"); + "OU=Test TLS Certificate,CN=localhost");
if (responses_sent == 0) { if (responses_sent == 0) {
assertEquals("GET", req.method); assert.equal("GET", req.method);
assertEquals("/hello", req.uri.path); assert.equal("/hello", req.uri.path);
p(req.headers); p(req.headers);
assertTrue("accept" in req.headers); assert.equal(true, "accept" in req.headers);
assertEquals("*/*", req.headers["accept"]); assert.equal("*/*", req.headers["accept"]);
assertTrue("foo" in req.headers); assert.equal(true, "foo" in req.headers);
assertEquals("bar", req.headers["foo"]); assert.equal("bar", req.headers["foo"]);
} }
if (responses_sent == 1) { if (responses_sent == 1) {
assertEquals("POST", req.method); assert.equal("POST", req.method);
assertEquals("/world", req.uri.path); assert.equal("/world", req.uri.path);
this.close(); this.close();
} }
@ -57,7 +57,7 @@ var http_server=http.createServer(function (req, res) {
responses_sent += 1; responses_sent += 1;
}); });
//assertEquals("127.0.0.1", res.connection.remoteAddress); //assert.equal("127.0.0.1", res.connection.remoteAddress);
}); });
http_server.setSecure("X509_PEM", caPem, 0, keyPem, certPem); http_server.setSecure("X509_PEM", caPem, 0, keyPem, certPem);
http_server.listen(PORT); http_server.listen(PORT);
@ -68,10 +68,10 @@ var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"});
req.finish(function (res) { req.finish(function (res) {
var verified = res.connection.verifyPeer(); var verified = res.connection.verifyPeer();
var peerDN = res.connection.getPeerCertificate("DNstring"); var peerDN = res.connection.getPeerCertificate("DNstring");
assertEquals(verified, 1); assert.equal(verified, 1);
assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,"
+ "OU=Test TLS Certificate,CN=localhost"); + "OU=Test TLS Certificate,CN=localhost");
assertEquals(200, res.statusCode); assert.equal(200, res.statusCode);
responses_recvd += 1; responses_recvd += 1;
res.setBodyEncoding("ascii"); res.setBodyEncoding("ascii");
res.addListener("body", function (chunk) { body0 += chunk; }); res.addListener("body", function (chunk) { body0 += chunk; });
@ -83,10 +83,10 @@ setTimeout(function () {
req.finish(function (res) { req.finish(function (res) {
var verified = res.connection.verifyPeer(); var verified = res.connection.verifyPeer();
var peerDN = res.connection.getPeerCertificate("DNstring"); var peerDN = res.connection.getPeerCertificate("DNstring");
assertEquals(verified, 1); assert.equal(verified, 1);
assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,"
+ "OU=Test TLS Certificate,CN=localhost"); + "OU=Test TLS Certificate,CN=localhost");
assertEquals(200, res.statusCode); assert.equal(200, res.statusCode);
responses_recvd += 1; responses_recvd += 1;
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.addListener("body", function (chunk) { body1 += chunk; }); res.addListener("body", function (chunk) { body1 += chunk; });
@ -96,12 +96,12 @@ setTimeout(function () {
process.addListener("exit", function () { process.addListener("exit", function () {
debug("responses_recvd: " + responses_recvd); debug("responses_recvd: " + responses_recvd);
assertEquals(2, responses_recvd); assert.equal(2, responses_recvd);
debug("responses_sent: " + responses_sent); debug("responses_sent: " + responses_sent);
assertEquals(2, responses_sent); assert.equal(2, responses_sent);
assertEquals("The path was /hello", body0); assert.equal("The path was /hello", body0);
assertEquals("The path was /world", body1); assert.equal("The path was /world", body1);
}); });

30
test/mjsunit/test-http.js

@ -9,20 +9,20 @@ var body1 = "";
http.createServer(function (req, res) { http.createServer(function (req, res) {
if (responses_sent == 0) { if (responses_sent == 0) {
assertEquals("GET", req.method); assert.equal("GET", req.method);
assertEquals("/hello", req.uri.path); assert.equal("/hello", req.uri.path);
p(req.headers); p(req.headers);
assertTrue("accept" in req.headers); assert.equal(true, "accept" in req.headers);
assertEquals("*/*", req.headers["accept"]); assert.equal("*/*", req.headers["accept"]);
assertTrue("foo" in req.headers); assert.equal(true, "foo" in req.headers);
assertEquals("bar", req.headers["foo"]); assert.equal("bar", req.headers["foo"]);
} }
if (responses_sent == 1) { if (responses_sent == 1) {
assertEquals("POST", req.method); assert.equal("POST", req.method);
assertEquals("/world", req.uri.path); assert.equal("/world", req.uri.path);
this.close(); this.close();
} }
@ -33,13 +33,13 @@ http.createServer(function (req, res) {
responses_sent += 1; responses_sent += 1;
}); });
//assertEquals("127.0.0.1", res.connection.remoteAddress); //assert.equal("127.0.0.1", res.connection.remoteAddress);
}).listen(PORT); }).listen(PORT);
var client = http.createClient(PORT); var client = http.createClient(PORT);
var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"}); var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"});
req.finish(function (res) { req.finish(function (res) {
assertEquals(200, res.statusCode); assert.equal(200, res.statusCode);
responses_recvd += 1; responses_recvd += 1;
res.setBodyEncoding("ascii"); res.setBodyEncoding("ascii");
res.addListener("body", function (chunk) { body0 += chunk; }); res.addListener("body", function (chunk) { body0 += chunk; });
@ -49,7 +49,7 @@ req.finish(function (res) {
setTimeout(function () { setTimeout(function () {
req = client.post("/world"); req = client.post("/world");
req.finish(function (res) { req.finish(function (res) {
assertEquals(200, res.statusCode); assert.equal(200, res.statusCode);
responses_recvd += 1; responses_recvd += 1;
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.addListener("body", function (chunk) { body1 += chunk; }); res.addListener("body", function (chunk) { body1 += chunk; });
@ -59,12 +59,12 @@ setTimeout(function () {
process.addListener("exit", function () { process.addListener("exit", function () {
debug("responses_recvd: " + responses_recvd); debug("responses_recvd: " + responses_recvd);
assertEquals(2, responses_recvd); assert.equal(2, responses_recvd);
debug("responses_sent: " + responses_sent); debug("responses_sent: " + responses_sent);
assertEquals(2, responses_sent); assert.equal(2, responses_sent);
assertEquals("The path was /hello", body0); assert.equal("The path was /hello", body0);
assertEquals("The path was /world", body1); assert.equal("The path was /world", body1);
}); });

10
test/mjsunit/test-keep-alive.js

@ -43,19 +43,19 @@ function runAb(opts, callback) {
runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) { runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) {
keepAliveReqSec = reqSec; keepAliveReqSec = reqSec;
assertTrue(keepAliveRequests > 0); assert.equal(true, keepAliveRequests > 0);
puts("keep-alive: " + keepAliveReqSec + " req/sec"); puts("keep-alive: " + keepAliveReqSec + " req/sec");
runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) { runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) {
normalReqSec = reqSec; normalReqSec = reqSec;
assertEquals(0, keepAliveRequests); assert.equal(0, keepAliveRequests);
puts("normal: " + normalReqSec + " req/sec"); puts("normal: " + normalReqSec + " req/sec");
server.close(); server.close();
}); });
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(normalReqSec > 50); assert.equal(true, normalReqSec > 50);
assertTrue(keepAliveReqSec > 50); assert.equal(true, keepAliveReqSec > 50);
assertTrue(normalReqSec < keepAliveReqSec); assert.equal(true, normalReqSec < keepAliveReqSec);
}); });

4
test/mjsunit/test-memory-usage.js

@ -2,5 +2,5 @@ process.mixin(require("./common"));
var r = process.memoryUsage(); var r = process.memoryUsage();
puts(inspect(r)); puts(inspect(r));
assertTrue(r["rss"] > 0); assert.equal(true, r["rss"] > 0);
assertTrue(r["vsize"] > 0); assert.equal(true, r["vsize"] > 0);

4
test/mjsunit/test-mkdir-rmdir.js

@ -24,7 +24,7 @@ posix.mkdir(d, 0x666).addCallback(function () {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertFalse(mkdir_error); assert.equal(false, mkdir_error);
assertFalse(rmdir_error); assert.equal(false, rmdir_error);
puts("exit"); puts("exit");
}); });

50
test/mjsunit/test-module-loading.js

@ -10,44 +10,44 @@ var d3 = require(require('path').dirname(__filename)+"/fixtures/b/d");
// Relative // Relative
var d4 = require("../mjsunit/fixtures/b/d"); var d4 = require("../mjsunit/fixtures/b/d");
assertFalse(false, "testing the test program."); assert.equal(false, false, "testing the test program.");
assertInstanceof(a.A, Function); assert.equal(true, a.A instanceof Function);
assertEquals("A", a.A()); assert.equal("A", a.A());
assertInstanceof(a.C, Function); assert.equal(true, a.C instanceof Function);
assertEquals("C", a.C()); assert.equal("C", a.C());
assertInstanceof(a.D, Function); assert.equal(true, a.D instanceof Function);
assertEquals("D", a.D()); assert.equal("D", a.D());
assertInstanceof(d.D, Function); assert.equal(true, d.D instanceof Function);
assertEquals("D", d.D()); assert.equal("D", d.D());
assertInstanceof(d2.D, Function); assert.equal(true, d2.D instanceof Function);
assertEquals("D", d2.D()); assert.equal("D", d2.D());
assertInstanceof(d3.D, Function); assert.equal(true, d3.D instanceof Function);
assertEquals("D", d3.D()); assert.equal("D", d3.D());
assertInstanceof(d4.D, Function); assert.equal(true, d4.D instanceof Function);
assertEquals("D", d4.D()); assert.equal("D", d4.D());
process.addListener("exit", function () { process.addListener("exit", function () {
assertInstanceof(a.A, Function); assert.equal(true, a.A instanceof Function);
assertEquals("A done", a.A()); assert.equal("A done", a.A());
assertInstanceof(a.C, Function); assert.equal(true, a.C instanceof Function);
assertEquals("C done", a.C()); assert.equal("C done", a.C());
assertInstanceof(a.D, Function); assert.equal(true, a.D instanceof Function);
assertEquals("D done", a.D()); assert.equal("D done", a.D());
assertInstanceof(d.D, Function); assert.equal(true, d.D instanceof Function);
assertEquals("D done", d.D()); assert.equal("D done", d.D());
assertInstanceof(d2.D, Function); assert.equal(true, d2.D instanceof Function);
assertEquals("D done", d2.D()); assert.equal("D done", d2.D());
puts("exit"); puts("exit");
}); });

14
test/mjsunit/test-multipart.js

@ -18,9 +18,9 @@ var server = http.createServer(function(req, res) {
var name = part.name; var name = part.name;
if (parts_reveived == 1) { if (parts_reveived == 1) {
assertEquals('reply', name); assert.equal('reply', name);
} else if (parts_reveived == 2) { } else if (parts_reveived == 2) {
assertEquals('fileupload', name); assert.equal('fileupload', name);
} }
parts[name] = ''; parts[name] = '';
@ -28,11 +28,11 @@ var server = http.createServer(function(req, res) {
parts[name] += chunk; parts[name] += chunk;
}); });
part.addListener('complete', function(chunk) { part.addListener('complete', function(chunk) {
assertEquals(0, part.buffer.length); assert.equal(0, part.buffer.length);
if (parts_reveived == 1) { if (parts_reveived == 1) {
assertEquals('yes', parts[name]); assert.equal('yes', parts[name]);
} else if (parts_reveived == 2) { } else if (parts_reveived == 2) {
assertEquals('/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg', parts[name]); assert.equal('/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg', parts[name]);
} }
parts_complete++; parts_complete++;
}); });
@ -54,6 +54,6 @@ request.finish();
process.addListener('exit', function() { process.addListener('exit', function() {
puts("done"); puts("done");
assertEquals(2, parts_complete); assert.equal(2, parts_complete);
assertEquals(2, parts_reveived); assert.equal(2, parts_reveived);
}); });

8
test/mjsunit/test-process-buffering.js

@ -11,7 +11,7 @@ function pwd (callback) {
}); });
child.addListener("exit", function (c) { child.addListener("exit", function (c) {
puts("exit: " + c); puts("exit: " + c);
assertEquals(0, c); assert.equal(0, c);
callback(output); callback(output);
pwd_called = true; pwd_called = true;
}); });
@ -20,10 +20,10 @@ function pwd (callback) {
pwd(function (result) { pwd(function (result) {
p(result); p(result);
assertTrue(result.length > 1); assert.equal(true, result.length > 1);
assertEquals("\n", result[result.length-1]); assert.equal("\n", result[result.length-1]);
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(pwd_called); assert.equal(true, pwd_called);
}); });

6
test/mjsunit/test-process-kill.js

@ -4,12 +4,12 @@ var exit_status = -1;
var cat = process.createChildProcess("cat"); var cat = process.createChildProcess("cat");
cat.addListener("output", function (chunk) { assertEquals(null, chunk); }); cat.addListener("output", function (chunk) { assert.equal(null, chunk); });
cat.addListener("error", function (chunk) { assertEquals(null, chunk); }); cat.addListener("error", function (chunk) { assert.equal(null, chunk); });
cat.addListener("exit", function (status) { exit_status = status; }); cat.addListener("exit", function (status) { exit_status = status; });
cat.kill(); cat.kill();
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(exit_status > 0); assert.equal(true, exit_status > 0);
}); });

6
test/mjsunit/test-process-simple.js

@ -17,7 +17,7 @@ cat.addListener("output", function (chunk) {
}); });
cat.addListener("error", function (chunk) { cat.addListener("error", function (chunk) {
puts("stderr: " + JSON.stringify(chunk)); puts("stderr: " + JSON.stringify(chunk));
assertEquals(null, chunk); assert.equal(null, chunk);
}); });
cat.addListener("exit", function (status) { cat.addListener("exit", function (status) {
puts("exit event"); puts("exit event");
@ -29,6 +29,6 @@ cat.write(" ");
cat.write("world"); cat.write("world");
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(0, exit_status); assert.equal(0, exit_status);
assertEquals("hello world", response); assert.equal("hello world", response);
}); });

2
test/mjsunit/test-process-spawn-loop.js

@ -29,5 +29,5 @@ function spawn (i) {
spawn(0); spawn(0);
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(finished); assert.equal(true, finished);
}); });

2
test/mjsunit/test-promise-cancel.js

@ -4,7 +4,7 @@ var promise = new process.Promise();
var cancelled = false; var cancelled = false;
promise.addCancelback(function(){ promise.addCancelback(function(){
if(cancelled){ if(cancelled){
assertUnreachable("promise should not cancel more than once"); assert.ok(false, "promise should not cancel more than once");
} }
cancelled = true; cancelled = true;
}); });

26
test/mjsunit/test-promise-timeout.js

@ -4,15 +4,15 @@ var timeouts = 0;
var promise = new process.Promise(); var promise = new process.Promise();
promise.timeout(250); promise.timeout(250);
assertEquals(250, promise.timeout()); assert.equal(250, promise.timeout());
promise.addCallback(function() { promise.addCallback(function() {
assertUnreachable('addCallback should not fire after a promise error'); assert.ok(false, 'addCallback should not fire after a promise error');
}); });
promise.addErrback(function(e) { promise.addErrback(function(e) {
assertInstanceof(e, Error); assert.equal(true, e instanceof Error);
assertEquals('timeout', e.message); assert.equal('timeout', e.message);
timeouts++; timeouts++;
}); });
@ -24,8 +24,8 @@ var waitPromise = new process.Promise();
try { try {
waitPromise.timeout(250).wait() waitPromise.timeout(250).wait()
} catch (e) { } catch (e) {
assertInstanceof(e, Error); assert.equal(true, e instanceof Error);
assertEquals('timeout', e.message); assert.equal('timeout', e.message);
timeouts++; timeouts++;
} }
@ -36,7 +36,7 @@ setTimeout(function() {
}, 250); }, 250);
successPromise.addErrback(function() { successPromise.addErrback(function() {
assertUnreachable('addErrback should not fire if there is no timeout'); assert.ok(false, 'addErrback should not fire if there is no timeout');
}); });
var errorPromise = new process.Promise(); var errorPromise = new process.Promise();
@ -46,8 +46,8 @@ setTimeout(function() {
}, 250); }, 250);
errorPromise.addErrback(function(e) { errorPromise.addErrback(function(e) {
assertInstanceof(e, Error); assert.equal(true, e instanceof Error);
assertEquals('intentional', e.message); assert.equal('intentional', e.message);
}); });
var cancelPromise = new process.Promise(); var cancelPromise = new process.Promise();
@ -61,11 +61,11 @@ setTimeout(function() {
}, 400); }, 400);
cancelPromise.addCallback(function(e) { cancelPromise.addCallback(function(e) {
assertUnreachable('addCallback should not fire if the promise is canceled'); assert.ok(false, 'addCallback should not fire if the promise is canceled');
}); });
cancelPromise.addErrback(function(e) { cancelPromise.addErrback(function(e) {
assertUnreachable('addErrback should not fire if the promise is canceled'); assert.ok(false, 'addErrback should not fire if the promise is canceled');
}); });
var cancelTimeoutPromise = new process.Promise(); var cancelTimeoutPromise = new process.Promise();
@ -75,9 +75,9 @@ setTimeout(function() {
}, 250); }, 250);
cancelPromise.addErrback(function(e) { cancelPromise.addErrback(function(e) {
assertUnreachable('addErrback should not fire after a cancel event'); assert.ok(false, 'addErrback should not fire after a cancel event');
}); });
process.addListener('exit', function() { process.addListener('exit', function() {
assertEquals(2, timeouts); assert.equal(2, timeouts);
}); });

48
test/mjsunit/test-promise-wait.js

@ -3,8 +3,8 @@ process.mixin(require("./common"));
var p1_done = false; var p1_done = false;
var p1 = new process.Promise(); var p1 = new process.Promise();
p1.addCallback(function () { p1.addCallback(function () {
assertEquals(1, arguments.length); assert.equal(1, arguments.length);
assertEquals("single arg", arguments[0]); assert.equal("single arg", arguments[0]);
p1_done = true; p1_done = true;
}); });
@ -28,10 +28,10 @@ p3.addCallback(function () {
var p4_done = false; var p4_done = false;
var p4 = new process.Promise(); var p4 = new process.Promise();
p4.addCallback(function () { p4.addCallback(function () {
assertEquals(3, arguments.length); assert.equal(3, arguments.length);
assertEquals("a", arguments[0]); assert.equal("a", arguments[0]);
assertEquals("b", arguments[1]); assert.equal("b", arguments[1]);
assertEquals("c", arguments[2]); assert.equal("c", arguments[2]);
p4_done = true; p4_done = true;
}); });
@ -47,36 +47,36 @@ p5.addCallback(function () {
p2.emitSuccess(); p2.emitSuccess();
assertFalse(p1_done); assert.equal(false, p1_done);
assertTrue(p2_done); assert.equal(true, p2_done);
assertFalse(p3_done); assert.equal(false, p3_done);
var ret1 = p1.wait() var ret1 = p1.wait()
assertEquals("single arg", ret1); assert.equal("single arg", ret1);
assertTrue(p1_done); assert.equal(true, p1_done);
assertTrue(p2_done); assert.equal(true, p2_done);
assertFalse(p3_done); assert.equal(false, p3_done);
p3.emitSuccess(); p3.emitSuccess();
assertFalse(p4_done); assert.equal(false, p4_done);
assertFalse(p5_done); assert.equal(false, p5_done);
p5.emitSuccess(); p5.emitSuccess();
assertFalse(p4_done); assert.equal(false, p4_done);
assertTrue(p5_done); assert.equal(true, p5_done);
var ret4 = p4.wait(); var ret4 = p4.wait();
assertArrayEquals(["a","b","c"], ret4); assert.deepEqual(["a","b","c"], ret4);
assertTrue(p4_done); assert.equal(true, p4_done);
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(p1_done); assert.equal(true, p1_done);
assertTrue(p2_done); assert.equal(true, p2_done);
assertTrue(p3_done); assert.equal(true, p3_done);
assertTrue(p4_done); assert.equal(true, p4_done);
assertTrue(p5_done); assert.equal(true, p5_done);
}); });

4
test/mjsunit/test-readdir.js

@ -7,7 +7,7 @@ puts("readdir " + fixturesDir);
promise.addCallback(function (files) { promise.addCallback(function (files) {
p(files); p(files);
assertArrayEquals(["a.js", "b", "multipart.js", "test_ca.pem", "test_cert.pem", "test_key.pem", "x.txt"], files.sort()); assert.deepEqual(["a.js", "b", "multipart.js", "test_ca.pem", "test_cert.pem", "test_key.pem", "x.txt"], files.sort());
}); });
promise.addErrback(function () { promise.addErrback(function () {
@ -16,6 +16,6 @@ promise.addErrback(function () {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertFalse(got_error); assert.equal(false, got_error);
puts("exit"); puts("exit");
}); });

4
test/mjsunit/test-remote-module-loading.js

@ -17,7 +17,7 @@ var server = http.createServer(function(req, res) {
server.listen(PORT); server.listen(PORT);
var httpModule = require('http://localhost:'+PORT+'/moduleA.js'); var httpModule = require('http://localhost:'+PORT+'/moduleA.js');
assertEquals('/moduleA.js', httpModule.httpPath()); assert.equal('/moduleA.js', httpModule.httpPath());
modulesLoaded++; modulesLoaded++;
var nodeBinary = process.ARGV[0]; var nodeBinary = process.ARGV[0];
@ -34,5 +34,5 @@ sys
}); });
process.addListener('exit', function() { process.addListener('exit', function() {
assertEquals(2, modulesLoaded); assert.equal(2, modulesLoaded);
}); });

4
test/mjsunit/test-signal-handler.js

@ -29,6 +29,6 @@ setInterval(function () {
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(1, first); assert.equal(1, first);
assertEquals(1, second); assert.equal(1, second);
}); });

4
test/mjsunit/test-stat-handler.js

@ -11,7 +11,7 @@ var changes = 0;
process.watchFile(f, function (curr, prev) { process.watchFile(f, function (curr, prev) {
puts(f + " change"); puts(f + " change");
changes++; changes++;
assertTrue(curr.mtime != prev.mtime); assert.equal(true, curr.mtime != prev.mtime);
process.unwatchFile(f); process.unwatchFile(f);
}); });
@ -24,5 +24,5 @@ file.close().wait();
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(changes > 0); assert.equal(true, changes > 0);
}); });

4
test/mjsunit/test-tcp-binary.js

@ -60,7 +60,7 @@ c.addListener("close", function () {
process.addListener("exit", function () { process.addListener("exit", function () {
puts("recv: " + JSON.stringify(recv)); puts("recv: " + JSON.stringify(recv));
assertEquals(2*256, recv.length); assert.equal(2*256, recv.length);
var a = recv.split(""); var a = recv.split("");
@ -70,5 +70,5 @@ process.addListener("exit", function () {
var second = a.slice(256,2*256).join(""); var second = a.slice(256,2*256).join("");
puts("second: " + JSON.stringify(second)); puts("second: " + JSON.stringify(second));
assertEquals(first, second); assert.equal(first, second);
}); });

6
test/mjsunit/test-tcp-many-clients.js

@ -45,8 +45,8 @@ function runClient (callback) {
client.addListener("close", function (had_error) { client.addListener("close", function (had_error) {
print("."); print(".");
assertFalse(had_error); assert.equal(false, had_error);
assertEquals(bytes, client.recved.length); assert.equal(bytes, client.recved.length);
if (this.connections < connections_per_client) { if (this.connections < connections_per_client) {
this.connect(port); this.connect(port);
} else { } else {
@ -64,6 +64,6 @@ for (var i = 0; i < concurrency; i++) {
} }
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(connections_per_client * concurrency, total_connections); assert.equal(connections_per_client * concurrency, total_connections);
puts("\nokay!"); puts("\nokay!");
}); });

32
test/mjsunit/test-tcp-pingpong-delay.js

@ -15,30 +15,30 @@ function pingPongTest (port, host, on_complete) {
socket.addListener("receive", function (data) { socket.addListener("receive", function (data) {
puts(data); puts(data);
assertEquals("PING", data); assert.equal("PING", data);
assertEquals("open", socket.readyState); assert.equal("open", socket.readyState);
assertTrue(count <= N); assert.equal(true, count <= N);
setTimeout(function () { setTimeout(function () {
assertEquals("open", socket.readyState); assert.equal("open", socket.readyState);
socket.send("PONG"); socket.send("PONG");
}, DELAY); }, DELAY);
}); });
socket.addListener("timeout", function () { socket.addListener("timeout", function () {
debug("server-side timeout!!"); debug("server-side timeout!!");
assertFalse(true); assert.equal(false, true);
}); });
socket.addListener("eof", function () { socket.addListener("eof", function () {
puts("server-side socket EOF"); puts("server-side socket EOF");
assertEquals("writeOnly", socket.readyState); assert.equal("writeOnly", socket.readyState);
socket.close(); socket.close();
}); });
socket.addListener("close", function (had_error) { socket.addListener("close", function (had_error) {
puts("server-side socket close"); puts("server-side socket close");
assertFalse(had_error); assert.equal(false, had_error);
assertEquals("closed", socket.readyState); assert.equal("closed", socket.readyState);
socket.server.close(); socket.server.close();
}); });
}); });
@ -49,17 +49,17 @@ function pingPongTest (port, host, on_complete) {
client.setEncoding("utf8"); client.setEncoding("utf8");
client.addListener("connect", function () { client.addListener("connect", function () {
assertEquals("open", client.readyState); assert.equal("open", client.readyState);
client.send("PING"); client.send("PING");
}); });
client.addListener("receive", function (data) { client.addListener("receive", function (data) {
puts(data); puts(data);
assertEquals("PONG", data); assert.equal("PONG", data);
assertEquals("open", client.readyState); assert.equal("open", client.readyState);
setTimeout(function () { setTimeout(function () {
assertEquals("open", client.readyState); assert.equal("open", client.readyState);
if (count++ < N) { if (count++ < N) {
client.send("PING"); client.send("PING");
} else { } else {
@ -72,13 +72,13 @@ function pingPongTest (port, host, on_complete) {
client.addListener("timeout", function () { client.addListener("timeout", function () {
debug("client-side timeout!!"); debug("client-side timeout!!");
assertFalse(true); assert.equal(false, true);
}); });
client.addListener("close", function () { client.addListener("close", function () {
puts("client close"); puts("client close");
assertEquals(N+1, count); assert.equal(N+1, count);
assertTrue(client_closed); assert.equal(true, client_closed);
if (on_complete) on_complete(); if (on_complete) on_complete();
tests_run += 1; tests_run += 1;
}); });
@ -87,5 +87,5 @@ function pingPongTest (port, host, on_complete) {
pingPongTest(21988); pingPongTest(21988);
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(1, tests_run); assert.equal(1, tests_run);
}); });

32
test/mjsunit/test-tcp-pingpong.js

@ -10,12 +10,12 @@ function pingPongTest (port, host, on_complete) {
var sent_final_ping = false; var sent_final_ping = false;
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
assertTrue(socket.remoteAddress !== null); assert.equal(true, socket.remoteAddress !== null);
assertTrue(socket.remoteAddress !== undefined); assert.equal(true, socket.remoteAddress !== undefined);
if (host === "127.0.0.1") if (host === "127.0.0.1")
assertEquals(socket.remoteAddress, "127.0.0.1"); assert.equal(socket.remoteAddress, "127.0.0.1");
else if (host == null) else if (host == null)
assertEquals(socket.remoteAddress, "127.0.0.1"); assert.equal(socket.remoteAddress, "127.0.0.1");
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.setNoDelay(); socket.setNoDelay();
@ -23,21 +23,21 @@ function pingPongTest (port, host, on_complete) {
socket.addListener("receive", function (data) { socket.addListener("receive", function (data) {
puts("server got: " + JSON.stringify(data)); puts("server got: " + JSON.stringify(data));
assertEquals("open", socket.readyState); assert.equal("open", socket.readyState);
assertTrue(count <= N); assert.equal(true, count <= N);
if (/PING/.exec(data)) { if (/PING/.exec(data)) {
socket.send("PONG"); socket.send("PONG");
} }
}); });
socket.addListener("eof", function () { socket.addListener("eof", function () {
assertEquals("writeOnly", socket.readyState); assert.equal("writeOnly", socket.readyState);
socket.close(); socket.close();
}); });
socket.addListener("close", function (had_error) { socket.addListener("close", function (had_error) {
assertFalse(had_error); assert.equal(false, had_error);
assertEquals("closed", socket.readyState); assert.equal("closed", socket.readyState);
socket.server.close(); socket.server.close();
}); });
}); });
@ -48,19 +48,19 @@ function pingPongTest (port, host, on_complete) {
client.setEncoding("utf8"); client.setEncoding("utf8");
client.addListener("connect", function () { client.addListener("connect", function () {
assertEquals("open", client.readyState); assert.equal("open", client.readyState);
client.send("PING"); client.send("PING");
}); });
client.addListener("receive", function (data) { client.addListener("receive", function (data) {
assertEquals("PONG", data); assert.equal("PONG", data);
count += 1; count += 1;
if (sent_final_ping) { if (sent_final_ping) {
assertEquals("readOnly", client.readyState); assert.equal("readOnly", client.readyState);
return; return;
} else { } else {
assertEquals("open", client.readyState); assert.equal("open", client.readyState);
} }
if (count < N) { if (count < N) {
@ -73,8 +73,8 @@ function pingPongTest (port, host, on_complete) {
}); });
client.addListener("close", function () { client.addListener("close", function () {
assertEquals(N+1, count); assert.equal(N+1, count);
assertTrue(sent_final_ping); assert.equal(true, sent_final_ping);
if (on_complete) on_complete(); if (on_complete) on_complete();
tests_run += 1; tests_run += 1;
}); });
@ -86,5 +86,5 @@ pingPongTest(20988, null);
pingPongTest(20997, "::1"); pingPongTest(20997, "::1");
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(3, tests_run); assert.equal(3, tests_run);
}); });

10
test/mjsunit/test-tcp-reconnect.js

@ -18,7 +18,7 @@ var server = tcp.createServer(function (socket) {
socket.addListener("close", function (had_error) { socket.addListener("close", function (had_error) {
//puts("server had_error: " + JSON.stringify(had_error)); //puts("server had_error: " + JSON.stringify(had_error));
assertFalse(had_error); assert.equal(false, had_error);
}); });
}); });
server.listen(port); server.listen(port);
@ -34,13 +34,13 @@ client.addListener("connect", function () {
client.addListener("receive", function (chunk) { client.addListener("receive", function (chunk) {
client_recv_count += 1; client_recv_count += 1;
puts("client_recv_count " + client_recv_count); puts("client_recv_count " + client_recv_count);
assertEquals("hello\r\n", chunk); assert.equal("hello\r\n", chunk);
client.close(); client.close();
}); });
client.addListener("close", function (had_error) { client.addListener("close", function (had_error) {
puts("disconnect"); puts("disconnect");
assertFalse(had_error); assert.equal(false, had_error);
if (disconnect_count++ < N) if (disconnect_count++ < N)
client.connect(port); // reconnect client.connect(port); // reconnect
else else
@ -48,6 +48,6 @@ client.addListener("close", function (had_error) {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(N+1, disconnect_count); assert.equal(N+1, disconnect_count);
assertEquals(N+1, client_recv_count); assert.equal(N+1, client_recv_count);
}); });

6
test/mjsunit/test-tcp-throttle-kernel-buffer.js

@ -37,7 +37,7 @@ client.addListener("receive", function (d) {
puts("pause"); puts("pause");
x = chars_recved; x = chars_recved;
setTimeout(function () { setTimeout(function () {
assertEquals(chars_recved, x); assert.equal(chars_recved, x);
client.readResume(); client.readResume();
puts("resume"); puts("resume");
paused = false; paused = false;
@ -51,6 +51,6 @@ client.addListener("eof", function () {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(N, chars_recved); assert.equal(N, chars_recved);
assertTrue(npauses > 2); assert.equal(true, npauses > 2);
}); });

8
test/mjsunit/test-tcp-throttle.js

@ -32,11 +32,11 @@ client.addListener("receive", function (d) {
setTimeout(function () { setTimeout(function () {
chars_recved = recv.length; chars_recved = recv.length;
puts("pause at: " + chars_recved); puts("pause at: " + chars_recved);
assertTrue(chars_recved > 1); assert.equal(true, chars_recved > 1);
client.readPause(); client.readPause();
setTimeout(function () { setTimeout(function () {
puts("resume at: " + chars_recved); puts("resume at: " + chars_recved);
assertEquals(chars_recved, recv.length); assert.equal(chars_recved, recv.length);
client.readResume(); client.readResume();
setTimeout(function () { setTimeout(function () {
@ -46,7 +46,7 @@ setTimeout(function () {
setTimeout(function () { setTimeout(function () {
puts("resume at: " + chars_recved); puts("resume at: " + chars_recved);
assertEquals(chars_recved, recv.length); assert.equal(chars_recved, recv.length);
client.readResume(); client.readResume();
}, 500); }, 500);
@ -63,6 +63,6 @@ client.addListener("eof", function () {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(N, recv.length); assert.equal(N, recv.length);
debug("Exit"); debug("Exit");
}); });

14
test/mjsunit/test-tcp-timeout.js

@ -37,7 +37,7 @@ client.addListener("connect", function () {
}); });
client.addListener("receive", function (chunk) { client.addListener("receive", function (chunk) {
assertEquals("hello\r\n", chunk); assert.equal("hello\r\n", chunk);
if (exchanges++ < 5) { if (exchanges++ < 5) {
setTimeout(function () { setTimeout(function () {
puts("client send 'hello'"); puts("client send 'hello'");
@ -54,7 +54,7 @@ client.addListener("receive", function (chunk) {
client.addListener("timeout", function () { client.addListener("timeout", function () {
puts("client timeout - this shouldn't happen"); puts("client timeout - this shouldn't happen");
assertFalse(true); assert.equal(false, true);
}); });
client.addListener("eof", function () { client.addListener("eof", function () {
@ -65,16 +65,16 @@ client.addListener("eof", function () {
client.addListener("close", function (had_error) { client.addListener("close", function (had_error) {
puts("client disconnect"); puts("client disconnect");
echo_server.close(); echo_server.close();
assertFalse(had_error); assert.equal(false, had_error);
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(starttime != null); assert.equal(true, starttime != null);
assertTrue(timeouttime != null); assert.equal(true, timeouttime != null);
diff = timeouttime - starttime; diff = timeouttime - starttime;
puts("diff = " + diff); puts("diff = " + diff);
assertTrue(timeout < diff); assert.equal(true, timeout < diff);
// Allow for 800 milliseconds more // Allow for 800 milliseconds more
assertTrue(diff < timeout + 800); assert.equal(true, diff < timeout + 800);
}); });

40
test/mjsunit/test-tcp-tls.js

@ -10,12 +10,12 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
var sent_final_ping = false; var sent_final_ping = false;
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
assertTrue(socket.remoteAddress !== null); assert.equal(true, socket.remoteAddress !== null);
assertTrue(socket.remoteAddress !== undefined); assert.equal(true, socket.remoteAddress !== undefined);
if (host === "127.0.0.1") if (host === "127.0.0.1")
assertEquals(socket.remoteAddress, "127.0.0.1"); assert.equal(socket.remoteAddress, "127.0.0.1");
else if (host == null) else if (host == null)
assertEquals(socket.remoteAddress, "127.0.0.1"); assert.equal(socket.remoteAddress, "127.0.0.1");
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.setNoDelay(); socket.setNoDelay();
@ -24,25 +24,25 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
socket.addListener("receive", function (data) { socket.addListener("receive", function (data) {
var verified = socket.verifyPeer(); var verified = socket.verifyPeer();
var peerDN = socket.getPeerCertificate("DNstring"); var peerDN = socket.getPeerCertificate("DNstring");
assertEquals(verified, 1); assert.equal(verified, 1);
assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,"
+ "OU=Test TLS Certificate,CN=localhost"); + "OU=Test TLS Certificate,CN=localhost");
puts("server got: " + JSON.stringify(data)); puts("server got: " + JSON.stringify(data));
assertEquals("open", socket.readyState); assert.equal("open", socket.readyState);
assertTrue(count <= N); assert.equal(true, count <= N);
if (/PING/.exec(data)) { if (/PING/.exec(data)) {
socket.send("PONG"); socket.send("PONG");
} }
}); });
socket.addListener("eof", function () { socket.addListener("eof", function () {
assertEquals("writeOnly", socket.readyState); assert.equal("writeOnly", socket.readyState);
socket.close(); socket.close();
}); });
socket.addListener("close", function (had_error) { socket.addListener("close", function (had_error) {
assertFalse(had_error); assert.equal(false, had_error);
assertEquals("closed", socket.readyState); assert.equal("closed", socket.readyState);
socket.server.close(); socket.server.close();
}); });
}); });
@ -56,26 +56,26 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
client.setSecure('X509_PEM', caPem, 0, keyPem, caPem); client.setSecure('X509_PEM', caPem, 0, keyPem, caPem);
client.addListener("connect", function () { client.addListener("connect", function () {
assertEquals("open", client.readyState); assert.equal("open", client.readyState);
var verified = client.verifyPeer(); var verified = client.verifyPeer();
var peerDN = client.getPeerCertificate("DNstring"); var peerDN = client.getPeerCertificate("DNstring");
assertEquals(verified, 1); assert.equal(verified, 1);
assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,"
+ "OU=Test TLS Certificate,CN=localhost"); + "OU=Test TLS Certificate,CN=localhost");
client.send("PING"); client.send("PING");
}); });
client.addListener("receive", function (data) { client.addListener("receive", function (data) {
assertEquals("PONG", data); assert.equal("PONG", data);
count += 1; count += 1;
puts("client got PONG"); puts("client got PONG");
if (sent_final_ping) { if (sent_final_ping) {
assertEquals("readOnly", client.readyState); assert.equal("readOnly", client.readyState);
return; return;
} else { } else {
assertEquals("open", client.readyState); assert.equal("open", client.readyState);
} }
if (count < N) { if (count < N) {
@ -88,8 +88,8 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
}); });
client.addListener("close", function () { client.addListener("close", function () {
assertEquals(N+1, count); assert.equal(N+1, count);
assertTrue(sent_final_ping); assert.equal(true, sent_final_ping);
tests_run += 1; tests_run += 1;
}); });
} }
@ -114,7 +114,7 @@ if (have_tls) {
tlsTest(21443, null, caPem, keyPem, certPem); tlsTest(21443, null, caPem, keyPem, certPem);
process.addListener("exit", function () { process.addListener("exit", function () {
assertEquals(2, tests_run); assert.equal(2, tests_run);
}); });
} else { } else {
puts("Not compiled with TLS support."); puts("Not compiled with TLS support.");

14
test/mjsunit/test-timers.js

@ -5,7 +5,7 @@ var WINDOW = 200; // why is does this need to be so big?
var interval_count = 0; var interval_count = 0;
var setTimeout_called = false; var setTimeout_called = false;
assertInstanceof(setTimeout, Function); assert.equal(true, setTimeout instanceof Function);
var starttime = new Date; var starttime = new Date;
setTimeout(function () { setTimeout(function () {
@ -15,12 +15,12 @@ setTimeout(function () {
if (diff < 0) diff = -diff; if (diff < 0) diff = -diff;
puts("diff: " + diff); puts("diff: " + diff);
assertTrue(1000 - WINDOW < diff && diff < 1000 + WINDOW); assert.equal(true, 1000 - WINDOW < diff && diff < 1000 + WINDOW);
setTimeout_called = true; setTimeout_called = true;
}, 1000); }, 1000);
// this timer shouldn't execute // this timer shouldn't execute
var id = setTimeout(function () { assertTrue(false); }, 500); var id = setTimeout(function () { assert.equal(true, false); }, 500);
clearTimeout(id); clearTimeout(id);
setInterval(function () { setInterval(function () {
@ -33,14 +33,14 @@ setInterval(function () {
var t = interval_count * 1000; var t = interval_count * 1000;
assertTrue(t - WINDOW < diff && diff < t + WINDOW); assert.equal(true, t - WINDOW < diff && diff < t + WINDOW);
assertTrue(interval_count <= 3); assert.equal(true, interval_count <= 3);
if (interval_count == 3) if (interval_count == 3)
clearInterval(this); clearInterval(this);
}, 1000); }, 1000);
process.addListener("exit", function () { process.addListener("exit", function () {
assertTrue(setTimeout_called); assert.equal(true, setTimeout_called);
assertEquals(3, interval_count); assert.equal(3, interval_count);
}); });

2
test/mjsunit/test-umask.js

@ -3,4 +3,4 @@ process.mixin(require("./common"));
var mask = 0664; var mask = 0664;
var old = process.umask(mask); var old = process.umask(mask);
assertEquals(true, mask === process.umask(old)); assert.equal(true, mask === process.umask(old));

2
test/mjsunit/test-utf8-scripts.js

@ -4,5 +4,5 @@ process.mixin(require("./common"));
puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη"); puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη");
assertTrue( /Hellö Wörld/.test("Hellö Wörld") ); assert.equal(true, /Hellö Wörld/.test("Hellö Wörld") );

4
test/mjsunit/test-wait-ordering.js

@ -15,12 +15,12 @@ function test_timeout_order(delay, desired_order) {
timer(0).addCallback(function() { timer(0).addCallback(function() {
timer(delay).wait() timer(delay).wait()
var b = new Date(); var b = new Date();
assertTrue(b - a >= delay); assert.equal(true, b - a >= delay);
order++; order++;
// A stronger assertion would be that the ordering is correct. // A stronger assertion would be that the ordering is correct.
// With Poor Man's coroutines we cannot guarentee that. // With Poor Man's coroutines we cannot guarentee that.
// Replacing wait() with actual coroutines would solve that issue. // Replacing wait() with actual coroutines would solve that issue.
// assertEquals(desired_order, order); // assert.equal(desired_order, order);
}); });
} }
test_timeout_order(10, 6); // Why does this have the proper order?? test_timeout_order(10, 6); // Why does this have the proper order??

Loading…
Cancel
Save