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
39 lines
1007 B
JavaScript
39 lines
1007 B
JavaScript
node.mixin(require("common.js"));
|
|
|
|
var testTxt = node.path.join(fixturesDir, "test.txt");
|
|
|
|
var libDir = node.path.join(testDir, "../../lib");
|
|
node.libraryPaths.unshift(libDir);
|
|
node.mixin(require("/file.js"));
|
|
|
|
var fileUnlinked = false;
|
|
|
|
var file = new File(testTxt, "w+");
|
|
file.write("hello\n");
|
|
file.write("world\n");
|
|
setTimeout(function () {
|
|
file.write("hello\n");
|
|
file.write("world\n");
|
|
file.close().addCallback(function () {
|
|
error("file closed...");
|
|
var out = node.fs.cat(testTxt).wait();
|
|
print("the file contains: ");
|
|
p(out);
|
|
assertEquals("hello\nworld\nhello\nworld\n", out);
|
|
var file2 = new File(testTxt, "r");
|
|
file2.read(5).addCallback(function (data) {
|
|
puts("read(5): " + JSON.stringify(data));
|
|
assertEquals("hello", data);
|
|
node.fs.unlink(testTxt).addCallback(function () {
|
|
fileUnlinked = true;
|
|
});
|
|
});
|
|
file2.close();
|
|
});
|
|
}, 10);
|
|
|
|
process.addListener("exit", function () {
|
|
assertTrue(fileUnlinked);
|
|
puts("done");
|
|
});
|