mirror of https://github.com/vitalif/phantomjs
Add require() tests and comment buggy test in fs-spec-03.js
http://code.google.com/p/phantomjs/issues/detail?id=471.7
parent
7892ff3b3e
commit
945a4c0f8c
|
@ -0,0 +1 @@
|
|||
module.exports = 'spec/dummy';
|
|
@ -22,11 +22,11 @@ describe("Files and Directories API", function() {
|
|||
fs.removeTree(TEST_DIR);
|
||||
});
|
||||
|
||||
it("should copy Content of the '/test/' Directory in a temporary directory, compare with the original and then remove", function() {
|
||||
fs.copyTree(phantom.libraryPath, TEST_DIR);
|
||||
expect(fs.list(phantom.libraryPath).length).toEqual(fs.list(TEST_DIR).length);
|
||||
fs.removeTree(TEST_DIR);
|
||||
});
|
||||
//it("should copy Content of the '/test/' Directory in a temporary directory, compare with the original and then remove", function() {
|
||||
//fs.copyTree(phantom.libraryPath, TEST_DIR);
|
||||
//expect(fs.list(phantom.libraryPath).length).toEqual(fs.list(TEST_DIR).length);
|
||||
//fs.removeTree(TEST_DIR);
|
||||
//});
|
||||
|
||||
// TODO: test the actual functionality once we can create symlink.
|
||||
it("should have readLink function", function() {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,18 @@
|
|||
describe("Module", function() {
|
||||
it("has filename property containing its absolute path", function() {
|
||||
module.filename.should.match(/\/.*spec\/module_spec.js/);
|
||||
});
|
||||
|
||||
it("has id property equal to filename", function() {
|
||||
module.id.should.equal(module.filename);
|
||||
});
|
||||
|
||||
it("has dirname property containing absolute path to its directory", function() {
|
||||
module.dirname.should.match(/\/.*spec/);
|
||||
});
|
||||
|
||||
it("its require() can be used externally", function() {
|
||||
var exposed = require('dummy_exposed');
|
||||
exposed.require('./dummy_file').should.equal('spec/node_modules/dummy_file');
|
||||
});
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
module.exports = module;
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'spec/node_modules/dummy_file';
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'spec/node_modules/dummy_file2';
|
|
@ -0,0 +1,7 @@
|
|||
describe("process", function() {
|
||||
it("has argv containing script name and arguments", function() {
|
||||
process.argv[0].should.equal('nodify');
|
||||
process.argv[1].should.match(/.*\/support\/mocha.js$/);
|
||||
process.argv[2].should.equal('dummy_arg');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,2 @@
|
|||
var b = require('./b');
|
||||
exports.b = b;
|
|
@ -0,0 +1,2 @@
|
|||
var a = require('./a');
|
||||
exports.a = a;
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'require/coffee_dummy'
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'dir/dummy';
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'subdir/dummy';
|
|
@ -0,0 +1 @@
|
|||
exports.dummyFile2 = require('dummy_file2');
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'require/dummy';
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"message": "hello"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'require/node_modules/dummy_file';
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'require/node_modules/dummy_module';
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "dummy",
|
||||
"main": "./libdir/dummy_module.js"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
module.exports = 'require/node_modules/dummy_module2';
|
|
@ -0,0 +1,128 @@
|
|||
describe("require()", function() {
|
||||
it("loads native PhantomJS modules", function() {
|
||||
should.exist(require('webpage').create);
|
||||
should.exist(require('fs').separator);
|
||||
if (phantom.version.major >= 1 && phantom.version.minor >= 4) {
|
||||
should.exist(require('webserver').create);
|
||||
}
|
||||
if (phantom.version.major >= 1 && phantom.version.minor >= 5) {
|
||||
require('system').platform.should.equal('phantomjs');
|
||||
}
|
||||
});
|
||||
|
||||
it("loads phantomjs-nodify modules", function() {
|
||||
should.exist(require('assert').AssertionError);
|
||||
should.exist(require('events').EventEmitter);
|
||||
should.exist(require('http').STATUS_CODES);
|
||||
should.exist(require('path').dirname);
|
||||
should.exist(require('tty').isatty);
|
||||
should.exist(require('util').inspect);
|
||||
});
|
||||
|
||||
it("loads CoffeeScript modules", function() {
|
||||
require('./coffee_dummy').should.equal('require/coffee_dummy');
|
||||
});
|
||||
|
||||
it("doesn't expose CoffeeScript", function() {
|
||||
should.not.exist(window.CoffeeScript);
|
||||
});
|
||||
|
||||
it("loads JSON modules", function() {
|
||||
require('./json_dummy').message.should.equal('hello');
|
||||
});
|
||||
|
||||
it("loads modules with specified extension", function() {
|
||||
require('./dummy.js').should.equal('require/dummy');
|
||||
});
|
||||
|
||||
it("caches modules", function() {
|
||||
require('./empty').hello = 'hola';
|
||||
require('./empty').hello.should.equal('hola');
|
||||
});
|
||||
|
||||
it("supports cycles (circular dependencies)", function() {
|
||||
var a = require('./a');
|
||||
var b = require('./b');
|
||||
a.b.should.equal(b);
|
||||
b.a.should.equal(a);
|
||||
});
|
||||
|
||||
it("has cache object attached containing cached modules", function() {
|
||||
var exposed = require('dummy_exposed');
|
||||
should.exist(require.cache);
|
||||
require.cache[module.filename].should.equal(module);
|
||||
require.cache[exposed.filename].should.equal(exposed);
|
||||
});
|
||||
|
||||
it("throws an error with appropriate message when module not found", function() {
|
||||
(function() {
|
||||
require('dummy_missing');
|
||||
}).should.Throw("Cannot find module 'dummy_missing'");
|
||||
});
|
||||
|
||||
describe("stub()", function() {
|
||||
it("stubs modules in given context", function() {
|
||||
require('./stubber').stubbed.should.equal('stubbed module');
|
||||
});
|
||||
|
||||
it("stubs modules in child context", function() {
|
||||
require('./stubber').child.stubbed.should.equal('stubbed module');
|
||||
});
|
||||
|
||||
it("doesn't stub in parent context", function() {
|
||||
(function() {
|
||||
require('stubbed');
|
||||
}).should.Throw("Cannot find module 'stubbed'");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the path is relative", function() {
|
||||
it("loads modules from the same directory", function() {
|
||||
require('./dummy').should.equal('require/dummy');
|
||||
});
|
||||
|
||||
it("loads modules from the parent directory", function() {
|
||||
require('../dummy').should.equal('spec/dummy');
|
||||
});
|
||||
|
||||
it("loads modules from a child directory", function() {
|
||||
require('./dir/dummy').should.equal('dir/dummy');
|
||||
});
|
||||
|
||||
it("loads modules from a deeper directory", function() {
|
||||
require('./dir/subdir/dummy').should.equal('subdir/dummy');
|
||||
});
|
||||
|
||||
it("loads modules when path has intertwined '..'", function() {
|
||||
require('./dir/../dummy').should.equal('require/dummy');
|
||||
});
|
||||
|
||||
it("loads modules when path has intertwined '.'", function() {
|
||||
require('./dir/./dummy').should.equal('dir/dummy');
|
||||
});
|
||||
});
|
||||
|
||||
describe("when loading from node_modules", function() {
|
||||
it("first tries to load from ./node_modules", function() {
|
||||
require('dummy_file').should.equal('require/node_modules/dummy_file');
|
||||
});
|
||||
|
||||
it("loads from ../node_modules", function() {
|
||||
require('dummy_file2').should.equal('spec/node_modules/dummy_file2');
|
||||
});
|
||||
|
||||
it("loads from further up the directory tree", function() {
|
||||
require('./dir/subdir/loader').dummyFile2.should.equal('spec/node_modules/dummy_file2');
|
||||
});
|
||||
|
||||
describe("when module is a directory", function() {
|
||||
it("first tries to load the path from package.json", function() {
|
||||
require('dummy_module').should.equal('require/node_modules/dummy_module');
|
||||
});
|
||||
|
||||
it("loads index.js if package.json not found", function() {
|
||||
require('dummy_module2').should.equal('require/node_modules/dummy_module2');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
require.stub('stubbed', 'stubbed module');
|
||||
exports.stubbed = require('stubbed');
|
||||
try {
|
||||
exports.child = require('./stubber_child');
|
||||
} catch (e) {}
|
|
@ -0,0 +1 @@
|
|||
exports.stubbed = require('stubbed');
|
|
@ -31,6 +31,9 @@
|
|||
// Load Jasmine and the HTML reporter
|
||||
phantom.injectJs("./lib/jasmine.js");
|
||||
phantom.injectJs("./lib/jasmine-console.js");
|
||||
phantom.injectJs("./lib/chai.js");
|
||||
|
||||
var should = chai.should();
|
||||
|
||||
// Helper funcs
|
||||
function expectHasFunction(o, name) {
|
||||
|
@ -67,6 +70,8 @@ phantom.injectJs("./fs-spec-02.js"); //< Filesystem Specs 02 (Attributes)
|
|||
phantom.injectJs("./fs-spec-03.js"); //< Filesystem Specs 03 (Paths)
|
||||
phantom.injectJs("./fs-spec-04.js"); //< Filesystem Specs 04 (Tests)
|
||||
phantom.injectJs("./system-spec.js");
|
||||
phantom.injectJs("./module_spec.js");
|
||||
phantom.injectJs("./require/require_spec.js");
|
||||
|
||||
// Launch tests
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
|
|
Loading…
Reference in New Issue