Added tests for include.resolve function. Covers feature added in pull #122

This commit is contained in:
Michael Mathews 2012-05-30 21:59:28 +01:00
parent fed3fd076e
commit 95bb744fee
2 changed files with 44 additions and 17 deletions

View File

@ -66,6 +66,28 @@ env = {
opts: {}
};
/** @global
@param {string} filepath The path to the script file to include (read and execute).
*/
function include(filepath) {
try {
filepath = include.resolve(filepath);
load(filepath);
}
catch (e) {
console.log('Cannot include "' + __dirname + '/' + filepath + '": '+e);
}
}
include.resolve = function(filepath) {
if (filepath.indexOf('/') === 0) {
return filepath;
}
return __dirname + '/' + filepath;
}
/**
Data that must be shared across the entire application.
@namespace
@ -108,23 +130,6 @@ function dump() {
}
}
/** @global
@param {string} filepath The path to the script file to include (read and execute).
*/
function include(filepath) {
try {
if (filepath.indexOf('/') === 0) {
load(filepath);
}
else {
load(__dirname + '/' + filepath);
}
}
catch (e) {
console.log('Cannot include "' + __dirname + '/' + filepath + '": '+e);
}
}
/**
Cause the VM running jsdoc to exit running.
@param {number} [n = 0] The exit status.

View File

@ -0,0 +1,22 @@
describe("include", function() {
it("should be a function", function() {
expect(include).toBeDefined();
expect(typeof include).toEqual('function');
});
it("should have a static method named resolve", function() {
expect(include.resolve).toBeDefined();
expect(typeof include.resolve).toEqual('function');
});
it("should resolve absolute filepaths to themselves", function() {
expect( include.resolve('/a/b/c.js') ).toEqual('/a/b/c.js');
});
it("should resolve relative filepaths relative to the __dirname", function() {
expect( include.resolve('a/b/c') ).toEqual(__dirname+'/'+'a/b/c');
});
});