mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
remove Envjs from test harness; remove broken --coffee option; add --nocolor option
This commit is contained in:
parent
cdee70fe4c
commit
e17601feb1
@ -33,8 +33,8 @@ argParser.addOption('u', 'tutorials', true, 'Directory in which JSDoc should
|
||||
|
||||
//Here are options specific to tests
|
||||
argParser.addOption(null, 'verbose', false, 'Display verbose output for tests');
|
||||
argParser.addOption(null, 'match', true, 'only run tests containing <value>', true);
|
||||
argParser.addOption(null, 'coffee', false, 'load coffee-script which allows execution .coffee files');
|
||||
argParser.addOption(null, 'match', true, 'Only run tests containing <value>', true);
|
||||
argParser.addOption(null, 'nocolor', false, 'Do not use color in console output from tests');
|
||||
|
||||
/**
|
||||
Set the options for this app.
|
||||
|
||||
3
rhino_modules/util.js
Normal file
3
rhino_modules/util.js
Normal file
@ -0,0 +1,3 @@
|
||||
exports.print = require('common/util').print;
|
||||
|
||||
exports.puts = require('common/util').puts;
|
||||
@ -1,12 +1,26 @@
|
||||
/*First load envjs to give us a browser environment for jasmine.
|
||||
*Jasmine wants things like set/clearInterval,set/clearTimeout.
|
||||
*Then load jasmine itself
|
||||
*/
|
||||
load('test/lib/env.rhino.js');
|
||||
load('test/lib/jasmine.js');
|
||||
load('test/async-callback.js');
|
||||
var jasmineNode = require('./reporter').jasmineNode,
|
||||
util = require('common/util');
|
||||
/*global env: true, expect: true, runs: true, waits: true */
|
||||
/*jshint evil: true */
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
|
||||
var jasmineAll = require('test/lib/jasmine');
|
||||
var jasmine = jasmineAll.jasmine;
|
||||
|
||||
// due to scoping issues, requiring this file doesn't work
|
||||
eval( fs.readFileSync(env.dirname + '/test/async-callback.js') );
|
||||
|
||||
var jasmineNode = require('test/reporter').jasmineNode;
|
||||
|
||||
var globalRoot = (function() {
|
||||
return this;
|
||||
}).call(null);
|
||||
|
||||
// set up jasmine's global functions
|
||||
['spyOn', 'it', 'xit', 'expect', 'runs', 'waitsFor', 'beforeEach', 'afterEach', 'describe',
|
||||
'xdescribe'].forEach(function(item) {
|
||||
globalRoot[item] = jasmineAll[item];
|
||||
});
|
||||
|
||||
jasmine.loadHelpersInFolder = function(folder, matcher) {
|
||||
var helpers = [], helperCollection = require('./spec-collection');
|
||||
@ -15,44 +29,41 @@ jasmine.loadHelpersInFolder = function(folder, matcher) {
|
||||
helpers = helperCollection.getSpecs();
|
||||
for ( var i = 0, len = helpers.length; i < len; ++i) {
|
||||
var file = helpers[i].path();
|
||||
var helper = require(file.replace(/\\/g, '/').replace(new RegExp('^' + env.dirname + '/'), "").replace(/\.*$/, ""));
|
||||
var helper = require(file.replace(/\\/g, '/').
|
||||
replace(new RegExp('^' + env.dirname + '/'), "").
|
||||
replace(/\.*$/, ""));
|
||||
|
||||
for (var key in helper) {
|
||||
this[key] = helper[key];
|
||||
if ( helper.hasOwnProperty(key) ) {
|
||||
this[key] = helper[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function removeJasmineFrames(text) {
|
||||
var lines = [];
|
||||
text.split(/\n/).forEach(function(line) {
|
||||
if (line.indexOf(filename) == -1) {
|
||||
lines.push(line);
|
||||
}
|
||||
});
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
var reporter = null;
|
||||
jasmine.initialize = function(done, verbose) {
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
|
||||
if (reporter !== null) {
|
||||
//If we've run before, we need to reset the runner
|
||||
if (reporter !== null) {
|
||||
// If we've run before, we need to reset the runner
|
||||
jasmineEnv.currentRunner_ = new jasmine.Runner(jasmineEnv);
|
||||
//And clear the reporter
|
||||
// And clear the reporter
|
||||
jasmineEnv.reporter.subReporters_.splice(jasmineEnv.reporter.subReporters_.indexOf(reporter));
|
||||
}
|
||||
reporter = new (verbose ? jasmineNode.TerminalVerboseReporter : jasmineNode.TerminalReporter)({
|
||||
print : util.print,
|
||||
color : true,
|
||||
onComplete : done,
|
||||
stackFilter : removeJasmineFrames
|
||||
});
|
||||
|
||||
var reporterOpts = {
|
||||
print: util.print,
|
||||
color: env.opts.nocolor === true ? false : true,
|
||||
onComplete: done
|
||||
};
|
||||
|
||||
reporter = env.opts.verbose ? new jasmineNode.TerminalVerboseReporter(reporterOpts) :
|
||||
new jasmineNode.TerminalReporter(reporterOpts);
|
||||
jasmineEnv.addReporter(reporter);
|
||||
|
||||
//updateInterval is set to 0 because there were not-fully-understood
|
||||
//issues with asynchronous behavior in jasmine otherwise.
|
||||
// updateInterval is set to 0 because there were not-fully-understood
|
||||
// issues with asynchronous behavior in jasmine otherwise.
|
||||
jasmineEnv.updateInterval = 0;
|
||||
|
||||
return jasmineEnv;
|
||||
@ -62,27 +73,32 @@ jasmine.initialize = function(done, verbose) {
|
||||
* Execute the specs in the specified folder. Helpers in each folder will be
|
||||
* added to the environment. Helpers in parent directories will be available to child
|
||||
* directories.
|
||||
* @param {string} folder the folder in which the specs are to be found
|
||||
* @param {function?} done callback function to execute when finished
|
||||
* @param {boolean} verbose whether or not output verbose results
|
||||
* @param {RegExp} matcher a regular expression to filter specs by. Only matching specs will run
|
||||
* @param {string} folder The folder in which the specs are to be found.
|
||||
* @param {function?} done Callback function to execute when finished.
|
||||
* @param {object} opts Options for executing the specs.
|
||||
* @param {boolean} opts.verbose Whether or not to output verbose results.
|
||||
* @param {RegExp} opts.matcher A regular expression to filter specs by. Only matching specs run.
|
||||
*/
|
||||
jasmine.executeSpecsInFolder = function(folder, done, verbose, matcher) {
|
||||
var fileMatcher = matcher || new RegExp(".(js)$", "i"),
|
||||
jasmine.executeSpecsInFolder = function(folder, done, opts) {
|
||||
var fileMatcher = opts.matcher || new RegExp(".(js)$", "i"),
|
||||
specs = require('./spec-collection'),
|
||||
jasmineEnv = jasmine.initialize(done, verbose);
|
||||
jasmineEnv = jasmine.initialize(done, opts.verbose);
|
||||
|
||||
//Load the specs
|
||||
// Load the specs
|
||||
specs.load(folder, fileMatcher, true);
|
||||
|
||||
//Add the specs to the context
|
||||
var specsList = specs.getSpecs();
|
||||
for ( var i = 0, len = specsList.length; i < len; ++i) {
|
||||
var filename = specsList[i];
|
||||
require(filename.path().replace(/\\/g, '/').replace(new RegExp('^' + env.dirname + '/'), "").replace(/\.\w+$/, ""));
|
||||
var filename;
|
||||
|
||||
// Add the specs to the context
|
||||
for (var i = 0, len = specsList.length; i < len; ++i) {
|
||||
filename = specsList[i];
|
||||
require(filename.path().replace(/\\/g, '/').
|
||||
replace(new RegExp('^' + env.dirname + '/'), "").
|
||||
replace(/\.\w+$/, ""));
|
||||
}
|
||||
|
||||
//Run Jasmine
|
||||
// Run Jasmine
|
||||
jasmineEnv.execute();
|
||||
};
|
||||
|
||||
@ -112,17 +128,8 @@ jasmine.asyncSpecDone = function() {
|
||||
jasmine.asyncSpecWait.done = true;
|
||||
};
|
||||
|
||||
for ( var key in jasmine) {
|
||||
exports[key] = jasmine[key];
|
||||
for (var key in jasmine) {
|
||||
if ( jasmine.hasOwnProperty(key) ) {
|
||||
exports[key] = jasmine[key];
|
||||
}
|
||||
}
|
||||
|
||||
exports.spyOn = spyOn;
|
||||
exports.it = it;
|
||||
exports.xit = xit;
|
||||
exports.expect = expect;
|
||||
exports.runs = runs;
|
||||
exports.waitsFor = waitsFor;
|
||||
exports.beforeEach = beforeEach;
|
||||
exports.afterEach = afterEach;
|
||||
exports.describe = describe;
|
||||
exports.xdescribe = xdescribe;
|
||||
14006
test/lib/env.rhino.js
14006
test/lib/env.rhino.js
File diff suppressed because one or more lines are too long
@ -1,54 +1,61 @@
|
||||
/*global env: true */
|
||||
/*
|
||||
* Tests Steps:
|
||||
* Test Steps:
|
||||
* 1. Get Jasmine
|
||||
* 2. Get the test options
|
||||
* 3. Get the list of directories to run tests from
|
||||
* 4. Run Jasmine on each directory
|
||||
*/
|
||||
var fs = require('fs');
|
||||
var jasmine = require('test/jasmine-jsdoc');
|
||||
var extensions = "js";
|
||||
var match = ".";
|
||||
var verbose = env.opts.verbose || false;
|
||||
var coffee = env.opts.coffee || false;
|
||||
var matches = env.opts.match || false;
|
||||
if (coffee) {
|
||||
extensions = "js|coffee";
|
||||
}
|
||||
if (matches) {
|
||||
if (matches instanceof Array) {
|
||||
match = matches.join("|");
|
||||
} else {
|
||||
match = matches;
|
||||
var path = require('path');
|
||||
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
var hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
|
||||
for (var key in jasmine) {
|
||||
if (hasOwnProp.call(jasmine, key)) {
|
||||
this[key] = jasmine[key];
|
||||
}
|
||||
}
|
||||
|
||||
var opts = {
|
||||
verbose: env.opts.verbose || false,
|
||||
showColors: env.opts.nocolor === true ? false : true
|
||||
};
|
||||
|
||||
var extensions = 'js';
|
||||
var match = env.opts.match || '.';
|
||||
if (match instanceof Array) {
|
||||
match = match.join("|");
|
||||
}
|
||||
opts.matcher = new RegExp("(" + match + ")\\.(" + extensions + ")$", 'i');
|
||||
|
||||
var helperCollection = require('test/spec-collection');
|
||||
var specFolders = ['test/specs', 'plugins/test/specs'];
|
||||
|
||||
var failedCount = 0;
|
||||
var index = 0;
|
||||
|
||||
for (var key in jasmine) {
|
||||
this[key] = jasmine[key];
|
||||
var onComplete;
|
||||
|
||||
function runNextFolder() {
|
||||
if (index < specFolders.length) {
|
||||
jasmine.loadHelpersInFolder(specFolders[index],
|
||||
new RegExp("helpers?\\.(" + extensions + ")$", 'i'));
|
||||
|
||||
jasmine.executeSpecsInFolder(specFolders[index], onComplete, opts);
|
||||
}
|
||||
}
|
||||
|
||||
var onComplete = function(runner, log) {
|
||||
if (runner.results().failedCount != 0) {
|
||||
failedCount++;
|
||||
onComplete = function(runner, log) {
|
||||
if (runner.results().failedCount !== 0) {
|
||||
failedCount += runner.results().failedCount;
|
||||
}
|
||||
index++;
|
||||
runNextFolder();
|
||||
};
|
||||
|
||||
var specFolder = null;
|
||||
|
||||
var runNextFolder = function() {
|
||||
if (index < specFolders.length) {
|
||||
jasmine.loadHelpersInFolder(specFolders[index], new RegExp("helpers\\.(" + extensions + ")$", 'i'));
|
||||
|
||||
var regExpSpec = new RegExp("(" + match + ")\\.(" + extensions + ")$", 'i');
|
||||
jasmine.executeSpecsInFolder(specFolders[index], onComplete, verbose, regExpSpec);
|
||||
}
|
||||
};
|
||||
|
||||
runNextFolder();
|
||||
process.exit(failedCount);
|
||||
process.exit(failedCount);
|
||||
|
||||
@ -1,24 +1,27 @@
|
||||
/*global env: true */
|
||||
var wrench = require('wrench/wrench');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var specs = [];
|
||||
|
||||
var createSpecObj = function(path, root) {
|
||||
var createSpecObj = function(_path, root) {
|
||||
function relativePath() {
|
||||
return _path.replace(root, '').replace(/^[\/\\]/, '').replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
return {
|
||||
path : function() {
|
||||
return path;
|
||||
path: function() {
|
||||
return _path;
|
||||
},
|
||||
relativePath : function() {
|
||||
return path.replace(root, '').replace(/^[\/\\]/, '').replace(/\\/g, '/');
|
||||
relativePath: relativePath,
|
||||
directory: function() {
|
||||
return _path.replace(/[\/\\][\s\w\.\-]*$/, "").replace(/\\/g, '/');
|
||||
},
|
||||
directory : function() {
|
||||
return path.replace(/[\/\\][\s\w\.-]*$/, "").replace(/\\/g, '/');
|
||||
relativeDirectory: function() {
|
||||
return relativePath().replace(/[\/\\][\s\w\.\-]*$/, "").replace(/\\/g, '/');
|
||||
},
|
||||
relativeDirectory : function() {
|
||||
return relativePath().replace(/[\/\\][\s\w\.-]*$/, "").replace(/\\/g, '/');
|
||||
},
|
||||
filename : function() {
|
||||
return path.replace(/^.*[\\\/]/, '');
|
||||
filename: function() {
|
||||
return _path.replace(/^.*[\\\/]/, '');
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -28,9 +31,10 @@ var clearSpecs = exports.clearSpecs = function() {
|
||||
};
|
||||
|
||||
exports.load = function(loadpath, matcher, clear) {
|
||||
if(clear === true) {
|
||||
if (clear === true) {
|
||||
clearSpecs();
|
||||
}
|
||||
|
||||
var wannaBeSpecs = wrench.readdirSyncRecursive(loadpath);
|
||||
for (var i = 0; i < wannaBeSpecs.length; i++) {
|
||||
var file = path.join(env.dirname, loadpath, wannaBeSpecs[i]);
|
||||
@ -48,4 +52,4 @@ exports.load = function(loadpath, matcher, clear) {
|
||||
|
||||
exports.getSpecs = function() {
|
||||
return specs;
|
||||
};
|
||||
};
|
||||
|
||||
@ -176,7 +176,7 @@ describe("jsdoc/opts/parser", function() {
|
||||
expect(r.tutorials).toEqual('mytutorials');
|
||||
});
|
||||
|
||||
it("should accept a naked option (i.e. no '-') and return an object with a '_' pproperty", function() {
|
||||
it("should accept a naked option (i.e. no '-') and return an object with a '_' property", function() {
|
||||
opts.parse(['myfile1', 'myfile2']);
|
||||
var r = opts.get();
|
||||
|
||||
@ -190,11 +190,11 @@ describe("jsdoc/opts/parser", function() {
|
||||
expect(r.verbose).toEqual(true);
|
||||
});
|
||||
|
||||
it("should accept a '--coffee' option and return an object with a 'coffee' property", function() {
|
||||
opts.parse(['--coffee']);
|
||||
it("should accept a '--nocolor' option and return an object with a 'nocolor' property", function() {
|
||||
opts.parse(['--nocolor']);
|
||||
var r = opts.get();
|
||||
|
||||
expect(r.coffee).toEqual(true);
|
||||
expect(r.nocolor).toEqual(true);
|
||||
});
|
||||
|
||||
it("should accept a '--match' option and return an object with a 'match' property", function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user