Fix indentation to 4 spaces in new require() tests

http://code.google.com/p/phantomjs/issues/detail?id=47
1.7
Juliusz Gonera 2012-06-23 18:42:47 -04:00 committed by Ariya Hidayat
parent fdd727e5da
commit b22e995337
6 changed files with 121 additions and 121 deletions

View File

@ -1,18 +1,18 @@
describe("Module", function() {
it("has filename property containing its absolute path", function() {
module.filename.should.match(/\/.*test\/module_spec.js/);
});
it("has filename property containing its absolute path", function() {
module.filename.should.match(/\/.*test\/module_spec.js/);
});
it("has id property equal to filename", function() {
module.id.should.equal(module.filename);
});
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(/\/.*test/);
});
it("has dirname property containing absolute path to its directory", function() {
module.dirname.should.match(/\/.*test/);
});
it("its require() can be used externally", function() {
var exposed = require('dummy_exposed');
exposed.require('./dummy_file').should.equal('spec/node_modules/dummy_file');
});
it("its require() can be used externally", function() {
var exposed = require('dummy_exposed');
exposed.require('./dummy_file').should.equal('spec/node_modules/dummy_file');
});
});

View File

@ -1,3 +1,3 @@
{
"message": "hello"
"message": "hello"
}

View File

@ -1,4 +1,4 @@
{
"name": "dummy",
"main": "./libdir/dummy_module.js"
"name": "dummy",
"main": "./libdir/dummy_module.js"
}

View File

@ -1,127 +1,127 @@
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 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'");
});
it("maintains proper .stack when an error is thrown in module's exports", function() {
try {
require('./thrower').fn();
} catch (e) {
e.stack.should.match(/^Error: fn\n *at .*thrower\.js:2/);
}
});
describe("stub()", function() {
it("stubs modules in given context", function() {
require('./stubber').stubbed.should.equal('stubbed module');
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("stubs modules in child context", function() {
require('./stubber').child.stubbed.should.equal('stubbed module');
it("loads CoffeeScript modules", function() {
require('./coffee_dummy').should.equal('require/coffee_dummy');
});
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("doesn't expose CoffeeScript", function() {
should.not.exist(window.CoffeeScript);
});
it("loads modules from the parent directory", function() {
require('../dummy').should.equal('spec/dummy');
it("loads JSON modules", function() {
require('./json_dummy').message.should.equal('hello');
});
it("loads modules from a child directory", function() {
require('./dir/dummy').should.equal('dir/dummy');
it("loads modules with specified extension", function() {
require('./dummy.js').should.equal('require/dummy');
});
it("loads modules from a deeper directory", function() {
require('./dir/subdir/dummy').should.equal('subdir/dummy');
it("caches modules", function() {
require('./empty').hello = 'hola';
require('./empty').hello.should.equal('hola');
});
it("loads modules when path has intertwined '..'", function() {
require('./dir/../dummy').should.equal('require/dummy');
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("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("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("loads from ../node_modules", function() {
require('dummy_file2').should.equal('spec/node_modules/dummy_file2');
it("throws an error with appropriate message when module not found", function() {
(function() {
require('dummy_missing');
}).should.Throw("Cannot find module 'dummy_missing'");
});
it("loads from further up the directory tree", function() {
require('./dir/subdir/loader').dummyFile2.should.equal('spec/node_modules/dummy_file2');
it("maintains proper .stack when an error is thrown in module's exports", function() {
try {
require('./thrower').fn();
} catch (e) {
e.stack.should.match(/^Error: fn\n *at .*thrower\.js:2/);
}
});
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');
});
describe("stub()", function() {
it("stubs modules in given context", function() {
require('./stubber').stubbed.should.equal('stubbed module');
});
it("loads index.js if package.json not found", function() {
require('dummy_module2').should.equal('require/node_modules/dummy_module2');
});
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');
});
});
});
});
});

View File

@ -1,5 +1,5 @@
require.stub('stubbed', 'stubbed module');
exports.stubbed = require('stubbed');
try {
exports.child = require('./stubber_child');
exports.child = require('./stubber_child');
} catch (e) {}

View File

@ -1,3 +1,3 @@
exports.fn = function() {
throw new Error('fn');
throw new Error('fn');
};