mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Testing Framework Upgrade Part II
The second half of the first phase of the testing framework upgrade. This finishes moving the exisintg tests to jasmine and the new test directory structure
This commit is contained in:
parent
2d73440b3d
commit
034205baa8
@ -1,4 +0,0 @@
|
||||
// Simple inheritance model with correct constructor
|
||||
function Test() {}
|
||||
function Test2() { Test.call(this); }
|
||||
Test2.prototype = Object.create(Test.prototype, {constructor: {value: Test2}});
|
||||
@ -1,17 +0,0 @@
|
||||
Call(
|
||||
{
|
||||
methodA: function()
|
||||
{
|
||||
this.id = this.createUUID();
|
||||
},
|
||||
|
||||
valueOf: function()
|
||||
{
|
||||
return this.id;
|
||||
},
|
||||
|
||||
toString: function()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
});
|
||||
22
test/fixtures/objectpropertykeys.js
vendored
Normal file
22
test/fixtures/objectpropertykeys.js
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
Call(
|
||||
{
|
||||
methodA: function()
|
||||
{
|
||||
this.id = this.createUUID();
|
||||
},
|
||||
|
||||
valueOf: function()
|
||||
{
|
||||
return this.id;
|
||||
},
|
||||
|
||||
toString: function()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
});
|
||||
|
||||
//Simple inheritance model with correct constructor
|
||||
function Test() {}
|
||||
function Test2() { Test.call(this); }
|
||||
Test2.prototype = Object.create(Test.prototype, {constructor: {value: Test2}});
|
||||
@ -7,6 +7,6 @@ function Page(title) {
|
||||
heading: '',
|
||||
main: ''
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
181
test/runner.js
181
test/runner.js
@ -1,5 +1,3 @@
|
||||
var assert = require('common/assert');
|
||||
|
||||
/*
|
||||
* Tests Steps:
|
||||
* 1. Get Jasmine
|
||||
@ -33,51 +31,6 @@ for (var key in jasmine) {
|
||||
this[key] = jasmine[key];
|
||||
}
|
||||
|
||||
// --------------OLD------------------
|
||||
var passCount = 0,
|
||||
failCount = 0,
|
||||
errorLog = [],
|
||||
currentTestFile = '';
|
||||
|
||||
//helpers
|
||||
var testhelpers = {
|
||||
getDocSetFromFile: function(filename) {
|
||||
var sourceCode = readFile(__dirname + '/' + filename),
|
||||
testParser,
|
||||
doclets;
|
||||
|
||||
testParser = new (require('jsdoc/src/parser')).Parser();
|
||||
require('jsdoc/src/handlers').attachTo(testParser);
|
||||
|
||||
doclets = testParser.parse('javascript:' + sourceCode);
|
||||
testhelpers.indexAll(doclets);
|
||||
|
||||
require('jsdoc/augment').addInherited(doclets);
|
||||
|
||||
// test assume borrows have not yet been resolved
|
||||
// require('jsdoc/borrow').resolveBorrows(doclets);
|
||||
|
||||
return {
|
||||
doclets: doclets,
|
||||
getByLongname: function(longname) {
|
||||
return doclets.filter(function(doclet) {
|
||||
return (doclet.longname || doclet.name) === longname;
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
indexAll: function(docs) {
|
||||
var index = {};
|
||||
docs.forEach(function(doc) {
|
||||
if (!index.hasOwnProperty(doc.longname)){index[doc.longname] = [];}
|
||||
index[doc.longname].push(doc);
|
||||
});
|
||||
docs.index = index;
|
||||
}
|
||||
};
|
||||
|
||||
//--------------END OLD------------------
|
||||
|
||||
var onComplete = function(runner, log) {
|
||||
if (runner.results().failedCount != 0) {
|
||||
failedCount++;
|
||||
@ -98,136 +51,4 @@ var runNextFolder = function() {
|
||||
};
|
||||
|
||||
runNextFolder();
|
||||
//process.exit(failedCount);
|
||||
|
||||
//--------------OLD------------------
|
||||
function test(description, f) {
|
||||
try {
|
||||
f();
|
||||
passCount++;
|
||||
}
|
||||
catch(e) {
|
||||
errorLog.push(description + (currentTestFile? ' ['+currentTestFile+']':'') + '\n' + (e.message||'') + '\n - Expected: ' + e.expected + '\n - Actual: ' + e.actual);
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
function testFile(filepath) {
|
||||
currentTestFile = filepath;
|
||||
include(filepath);
|
||||
currentTestFile = '';
|
||||
}
|
||||
|
||||
function report() {
|
||||
console.log('\033[032mPASSED: ' + passCount + ' test' + (passCount == 1? '' : 's') + '.\033[0m');
|
||||
if (failCount) {
|
||||
console.log('\033[031mFAILED: '+ failCount + ' test' + (passCount == 1? '' : 's') + '.\033[0m');
|
||||
for (var i = 0, leni = errorLog.length; i < leni; i++) {
|
||||
console.log(' ' + (i+1) + '. ' + (i+1 < 10? ' ' : '') + (errorLog[i]||'') + '\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testFile('test/specs/tags/file.js');
|
||||
|
||||
testFile('test/specs/documentation/virtual.js');
|
||||
|
||||
testFile('test/specs/documentation/objectlit.js');
|
||||
testFile('test/specs/documentation/objectlit2.js');
|
||||
|
||||
testFile('test/specs/documentation/this.js');
|
||||
testFile('test/specs/documentation/this2.js');
|
||||
testFile('test/specs/documentation/this3.js');
|
||||
|
||||
testFile('test/specs/documentation/this-and-objectlit.js');
|
||||
|
||||
testFile('test/specs/documentation/var.js');
|
||||
|
||||
testFile('test/specs/documentation/inner.js');
|
||||
testFile('test/specs/documentation/innerscope.js');
|
||||
testFile('test/specs/documentation/innerscope2.js');
|
||||
|
||||
testFile('test/specs/tags/abstracttag.js');
|
||||
testFile('test/specs/tags/accesstag.js');
|
||||
testFile('test/specs/tags/alias.js');
|
||||
testFile('test/specs/tags/alias2.js');
|
||||
testFile('test/specs/tags/alias3.js');
|
||||
testFile('test/specs/tags/aliasglobal.js');
|
||||
testFile('test/specs/tags/aliasresolve.js');
|
||||
testFile('test/specs/tags/aliasresolve2.js');
|
||||
testFile('test/specs/documentation/also.js');
|
||||
testFile('test/specs/tags/augmentstag.js');
|
||||
testFile('test/specs/tags/authortag.js');
|
||||
testFile('test/specs/tags/borrowstag.js');
|
||||
testFile('test/specs/tags/borrowstag2.js');
|
||||
testFile('test/specs/tags/classtag.js');
|
||||
testFile('test/specs/tags/constructstag.js');
|
||||
testFile('test/specs/tags/constructstag2.js');
|
||||
testFile('test/specs/tags/constructstag3.js');
|
||||
testFile('test/specs/tags/constructstag4.js');
|
||||
testFile('test/specs/tags/constructstag5.js');
|
||||
testFile('test/specs/tags/constructortag.js');
|
||||
testFile('test/specs/documentation/constructorproperty.js');
|
||||
testFile('test/specs/tags/copyrighttag.js');
|
||||
testFile('test/specs/tags/defaulttag.js');
|
||||
testFile('test/specs/tags/deprecatedtag.js');
|
||||
testFile('test/specs/tags/enumtag.js');
|
||||
testFile('test/specs/tags/eventfirestag.js');
|
||||
testFile('test/specs/documentation/exports.js');
|
||||
testFile('test/specs/tags/exportstag.js');
|
||||
testFile('test/specs/tags/exportstag2.js');
|
||||
testFile('test/specs/tags/exportstag3.js');
|
||||
testFile('test/specs/tags/exportstag4.js');
|
||||
testFile('test/specs/tags/exceptiontag.js');
|
||||
testFile('test/specs/tags/globaltag.js');
|
||||
testFile('test/specs/tags/ignoretag.js');
|
||||
testFile('test/specs/documentation/inlinecomment.js');
|
||||
testFile('test/specs/tags/lends.js');
|
||||
testFile('test/specs/tags/lends2.js');
|
||||
testFile('test/specs/tags/lendsglobal.js');
|
||||
testFile('test/specs/documentation/moduleinner.js');
|
||||
testFile('test/specs/tags/memberoftag.js');
|
||||
testFile('test/specs/tags/memberoftag2.js');
|
||||
testFile('test/specs/tags/memberoftag3.js');
|
||||
testFile('test/specs/tags/memberoftag4.js');
|
||||
testFile('test/specs/tags/memberoftagforced.js');
|
||||
testFile('test/specs/tags/moduletag.js');
|
||||
testFile('test/specs/tags/moduletag2.js');
|
||||
testFile('test/specs/documentation/namedFuncStatement.js');
|
||||
testFile('test/specs/tags/paramtag.js');
|
||||
testFile('test/specs/tags/privatetag.js');
|
||||
testFile('test/specs/documentation/quotename.js');
|
||||
testFile('test/specs/documentation/quotename2.js');
|
||||
testFile('test/specs/tags/readonlytag.js');
|
||||
testFile('test/specs/tags/requirestag.js');
|
||||
testFile('test/specs/tags/returnstag.js');
|
||||
testFile('test/specs/tags/seetag.js');
|
||||
testFile('test/specs/tags/sincetag.js');
|
||||
testFile('test/specs/documentation/starbangstar.js');
|
||||
testFile('test/specs/tags/thistag.js');
|
||||
testFile('test/specs/tags/typekind.js');
|
||||
testFile('test/specs/tags/typetag.js');
|
||||
testFile('test/specs/tags/typedeftag.js');
|
||||
testFile('test/specs/documentation/variations.js');
|
||||
testFile('test/specs/tags/variations3.js');
|
||||
testFile('test/specs/tags/versiontag.js');
|
||||
|
||||
|
||||
var os = java.lang.System.getProperty('os.name'),
|
||||
isWin = !!os.startsWith('Windows');
|
||||
|
||||
/** Add codes to display string in color (red) on the console (if OS supports). */
|
||||
function red(str) {
|
||||
if (isWin) { return str; }
|
||||
else { return '\033[031m' + str + '\033[0m'; }
|
||||
}
|
||||
|
||||
/** Add codes to display string in color (red) on the console (if OS supports). */
|
||||
function green(str) {
|
||||
if (isWin) { return str; }
|
||||
else { return '\033[032m' + str + '\033[0m'; }
|
||||
}
|
||||
|
||||
|
||||
report();
|
||||
//--------------END OLD------------------
|
||||
process.exit(failedCount);
|
||||
59
test/specs/documentation/alias.js
Normal file
59
test/specs/documentation/alias.js
Normal file
@ -0,0 +1,59 @@
|
||||
describe("aliases", function() {
|
||||
describe("standard", function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/alias.js'),
|
||||
found = docSet.getByLongname('myObject').filter(function($) {
|
||||
return ! $.undocumented;
|
||||
}),
|
||||
foundMember = docSet.getByLongname('myObject.myProperty');
|
||||
|
||||
it('When a symbol is given an alias it is documented as if the name is the alias value.', function() {
|
||||
expect(found[0].longname).toEqual('myObject');
|
||||
});
|
||||
|
||||
it('When a symbol is a member of an alias it is documented as if the memberof is the alias value.', function() {
|
||||
expect(foundMember[0].longname).toEqual('myObject.myProperty');
|
||||
expect(foundMember[0].memberof).toEqual('myObject');
|
||||
});
|
||||
});
|
||||
|
||||
it('When a symbol is a member of an alias of a nested name it is documented as if the memberof is the nested alias value.', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/alias2.js'),
|
||||
foundMember = docSet.getByLongname('ns.Myclass#myProperty');
|
||||
|
||||
expect(foundMember[0].longname).toEqual('ns.Myclass#myProperty');
|
||||
expect(foundMember[0].name).toEqual('myProperty');
|
||||
expect(foundMember[0].memberof).toEqual('ns.Myclass');
|
||||
expect(foundMember[0].scope).toEqual('instance');
|
||||
});
|
||||
|
||||
it('When a symbol is a member of an aliased class, a this-variables is documented as if it were a member that class.', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/alias3.js'),
|
||||
tcm = docSet.getByLongname('trackr.CookieManager')[0],
|
||||
tcmValue = docSet.getByLongname('trackr.CookieManager#value')[0];
|
||||
|
||||
expect(tcmValue.memberof).toEqual('trackr.CookieManager');
|
||||
});
|
||||
|
||||
it('When a symbol is documented as a static member of <global> it\'s scope is "global" and not "static".', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal.js'),
|
||||
log = docSet.getByLongname('log')[0];
|
||||
|
||||
expect(log.scope).toEqual('global');
|
||||
});
|
||||
|
||||
describe("resolving", function() {
|
||||
it('When a local reference has alias, put all members into aliased definition. Local modifications should be visible to outside.', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasresolve.js'),
|
||||
method = docSet.getByLongname('A.F.method');
|
||||
|
||||
expect(method.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('When a reference in an outer scope has alias, put all members into aliased definition. Local modifications are visible to outside.', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasresolve2.js'),
|
||||
method = docSet.getByLongname('A.F.method');
|
||||
|
||||
expect(method.length).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,11 +1,10 @@
|
||||
(function() {
|
||||
var docSet = testhelpers.getDocSetFromFile('test/cases/also.js'),
|
||||
describe("multiple doclets per symbol", function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/also.js'),
|
||||
name = docSet.getByLongname('Asset#name').filter(function($) {
|
||||
return ! $.undocumented;
|
||||
});
|
||||
|
||||
test('When a symbol has two doclets adjacent to each other both doclets apply to the symbol.', function() {
|
||||
assert.equal(name.length, 2, 'myObject');
|
||||
it('When a symbol has two doclets adjacent to each other both doclets apply to the symbol.', function() {
|
||||
expect(name.length).toEqual(2);
|
||||
});
|
||||
|
||||
})();
|
||||
});
|
||||
@ -1,8 +0,0 @@
|
||||
(function() {
|
||||
|
||||
test('Should not crash when "contructor" property is used in Object.create() parameter', function() {
|
||||
var docSet = testhelpers.getDocSetFromFile('test/cases/contructorproperty.js');
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
})();
|
||||
@ -1,11 +1,11 @@
|
||||
(function() {
|
||||
var docSet = testhelpers.getDocSetFromFile('test/cases/exports.js'),
|
||||
describe("'exports' symbol in modules", function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/exports.js'),
|
||||
helloworld = docSet.getByLongname('module:hello/world')[0],
|
||||
sayhello = docSet.getByLongname('module:hello/world.sayHello')[0];
|
||||
|
||||
test('When a symbol starts with the special name "exports" and is in a file with a @module tag, the symbol is documented as a member of that module.', function() {
|
||||
assert.equal(typeof sayhello, 'object');
|
||||
assert.equal(sayhello.kind, 'function');
|
||||
assert.equal(sayhello.memberof, 'module:hello/world');
|
||||
|
||||
it('When a symbol starts with the special name "exports" and is in a file with a @module tag, the symbol is documented as a member of that module.', function() {
|
||||
expect(typeof sayhello).toEqual('object');
|
||||
expect(sayhello.kind).toEqual('function');
|
||||
expect(sayhello.memberof).toEqual('module:hello/world');
|
||||
});
|
||||
})();
|
||||
});
|
||||
@ -1,10 +1,12 @@
|
||||
(function() {
|
||||
var docSet = testhelpers.getDocSetFromFile('test/cases/inlinecomment.js'),
|
||||
t = docSet.getByLongname('test'),
|
||||
t2 = docSet.getByLongname('test2');
|
||||
|
||||
test('When there is an inline comment on a line ending with no semicolon, that comment and the next comment are still captured', function() {
|
||||
assert.equal(t.length, 1, "Inline comment on line without semicolon is captured");
|
||||
assert.equal(t2.length, 1, "Inline comment on line after line without semicolon is captured");
|
||||
});
|
||||
})();
|
||||
describe("inline comments", function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/inlinecomment.js'),
|
||||
t = docSet.getByLongname('test'),
|
||||
t2 = docSet.getByLongname('test2');
|
||||
|
||||
it('When there is an inline comment on a line ending with no semicolon, that comment and the next comment are still captured', function() {
|
||||
//Inline comment on line without semicolon is captured
|
||||
expect(t.length).toEqual(1);
|
||||
//Inline comment on line after line without semicolon is captured
|
||||
expect(t2.length).toEqual(1);
|
||||
});
|
||||
});
|
||||
@ -1,19 +1,24 @@
|
||||
(function() {
|
||||
var docSet = testhelpers.getDocSetFromFile('test/cases/inner.js'),
|
||||
describe("when a documented var memeber is inside a named function", function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/inner.js'),
|
||||
found1 = docSet.getByLongname('sendMessage~encoding'),
|
||||
found2 = docSet.getByLongname('sendMessage~encrypt');
|
||||
|
||||
test('When a documented var member is inside a named function.', function() {
|
||||
assert.equal(found1.length, 1, 'A doclet with the correct longname should be found.');
|
||||
assert.equal(found1[0].name, 'encoding', 'The short name should be correct.');
|
||||
assert.equal(found1[0].memberof, 'sendMessage', 'The memberof should be correct.');
|
||||
assert.equal(found1[0].scope, 'inner', 'The scope should default to "static".');
|
||||
|
||||
it("A Doclet with the correct longname should be found", function() {
|
||||
expect(found1.length).toEqual(1);
|
||||
expect(found2.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('When a documented function is inside a named function.', function() {
|
||||
assert.equal(found2.length, 1, 'A doclet with the correct longname should be found.');
|
||||
assert.equal(found2[0].name, 'encrypt', 'The short name should be correct.');
|
||||
assert.equal(found2[0].memberof, 'sendMessage', 'The memberof should be correct.');
|
||||
assert.equal(found2[0].scope, 'inner', 'The scope should default to "static".');
|
||||
|
||||
it("The short name should be correct", function() {
|
||||
expect(found1[0].name).toEqual('encoding');
|
||||
expect(found2[0].name).toEqual('encrypt');
|
||||
});
|
||||
})();
|
||||
|
||||
it("The member of should be correct", function() {
|
||||
expect(found1[0].memberof).toEqual('sendMessage');
|
||||
expect(found2[0].memberof).toEqual('sendMessage');
|
||||
});
|
||||
it("The scope should default to 'inner'", function() {
|
||||
expect(found1[0].scope).toEqual('inner');
|
||||
expect(found2[0].scope).toEqual('inner');
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user