mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Added tests for include.resolve function. Covers feature added in pull #122
This commit is contained in:
parent
fed3fd076e
commit
95bb744fee
39
jsdoc.js
39
jsdoc.js
@ -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.
|
||||
|
||||
22
test/specs/jsdoc/functions/include.js
Normal file
22
test/specs/jsdoc/functions/include.js
Normal 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');
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user