mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
8185e1fd25
include() should not be used by libraries because it will pollute the global namespace. To discourage this behavior and bring Node more in-line with the current CommonJS module system, include() is removed. Small scripts like unit tests often times do want to pollute the global namespace for ease. To avoid the boiler plate code of var x = require("/x.js"); var foo = x.foo; var bar = x.bar; The function node.mixin() is stolen from jQuery's jQuery.extend. So that it can be written: node.mixin(require("/x.js")); Reference: http://docs.jquery.com/Utilities/jQuery.extend http://groups.google.com/group/nodejs/browse_thread/thread/f9ac83e5c11e7e87
47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
node.mixin(require("common.js"));
|
|
|
|
var WINDOW = 200; // why is does this need to be so big?
|
|
|
|
var interval_count = 0;
|
|
var setTimeout_called = false;
|
|
|
|
assertInstanceof(setTimeout, Function);
|
|
var starttime = new Date;
|
|
|
|
setTimeout(function () {
|
|
var endtime = new Date;
|
|
|
|
var diff = endtime - starttime;
|
|
if (diff < 0) diff = -diff;
|
|
puts("diff: " + diff);
|
|
|
|
assertTrue(1000 - WINDOW < diff && diff < 1000 + WINDOW);
|
|
setTimeout_called = true;
|
|
}, 1000);
|
|
|
|
// this timer shouldn't execute
|
|
var id = setTimeout(function () { assertTrue(false); }, 500);
|
|
clearTimeout(id);
|
|
|
|
setInterval(function () {
|
|
interval_count += 1;
|
|
var endtime = new Date;
|
|
|
|
var diff = endtime - starttime;
|
|
if (diff < 0) diff = -diff;
|
|
puts("diff: " + diff);
|
|
|
|
var t = interval_count * 1000;
|
|
|
|
assertTrue(t - WINDOW < diff && diff < t + WINDOW);
|
|
|
|
assertTrue(interval_count <= 3);
|
|
if (interval_count == 3)
|
|
clearInterval(this);
|
|
}, 1000);
|
|
|
|
process.addListener("exit", function () {
|
|
assertTrue(setTimeout_called);
|
|
assertEquals(3, interval_count);
|
|
});
|