Fix tests for new error strategy

This commit is contained in:
Tom MacWright 2015-10-01 18:24:04 -04:00
parent a848202dcf
commit 74b9bd4e0e
10 changed files with 22 additions and 18 deletions

View File

@ -52,15 +52,12 @@ module.exports = function (indexes, options, callback) {
return inputStream.pipe(concat(function (inputs) {
try {
var errors = [];
var docs = inputs
.filter(filterJS)
.reduce(function (memo, file) {
return memo.concat(parse(file));
}, [])
.map(function (comment) {
comment.errors = [];
// compose nesting & membership to avoid intermediate arrays
comment = nestParams(inferMembership(inferKind(inferName(lint(comment)))));
if (options.github) {
@ -71,7 +68,7 @@ module.exports = function (indexes, options, callback) {
.sort(sort.bind(undefined, options.order))
.filter(filterAccess.bind(undefined, options.private ? [] : undefined));
callback(null, docs, errors);
callback(null, docs);
} catch (e) {
callback(e);
}

View File

@ -1,7 +1,5 @@
'use strict';
var error = require('../lib/error');
/**
* Add paths to each comment, making it possible to generate permalinks
* that differentiate between instance functions with the same name but

View File

@ -1,7 +1,5 @@
'use strict';
var error = require('../lib/error');
var CANONICAL = {
'String': 'string',
'Boolean': 'boolean',

View File

@ -13,5 +13,14 @@
* @return {undefined} calls callback
*/
module.exports = function (comments, opts, callback) {
opts = opts || {};
if (!opts.preserveErrors) {
comments.forEach(function (comment) {
delete comment.errors;
});
}
return callback(null, JSON.stringify(comments, null, 2));
};

View File

@ -30,6 +30,7 @@ module.exports = function (comment, loc, context) {
result.loc = loc;
result.context = context;
result.errors = [];
var i = 0;
var errors = [];
@ -37,7 +38,7 @@ module.exports = function (comment, loc, context) {
var tag = result.tags[i];
if (tag.errors) {
for (var j = 0; j < tag.errors.length; j++) {
errors.push(error(tag, result, tag.errors[j]));
result.errors.push(tag.errors[j]);
}
result.tags.splice(i, 1);
} else {

View File

@ -20,8 +20,7 @@ test('error', function (t) {
}
};
t.deepEqual(error(tag, comment, 'test'), 'file.js:3: test');
t.deepEqual(error(tag, comment, '%s', 'test'), 'file.js:3: test');
t.deepEqual(error(comment, 'test'), 'file.js:1: test');
t.end();
});

View File

@ -22,9 +22,9 @@ test('lint', function (t) {
* @param {array} bar
*/
return 0;
}), [
'input.js:3: type String found, string is standard',
'input.js:4: type array found, Array is standard'],
}).errors, [
'type String found, string is standard',
'type array found, Array is standard'],
'non-canonical');
t.deepEqual(evaluate(function () {
@ -32,7 +32,7 @@ test('lint', function (t) {
* @param {string} foo
*/
return 0;
}), [], 'no errors');
}).errors, [], 'no errors');
t.end();
});

View File

@ -1,7 +1,7 @@
'use strict';
var test = require('tap').test,
parse = require('../../lib/parsers/javascript');
parse = require('../../../lib/parsers/javascript');
function toComment(fn, filename) {
return parse({
@ -23,7 +23,7 @@ test('parse - error', function (t) {
/** @param {foo */
return 0;
})[0].errors, [
'test.js:2: Braces are not balanced',
'test.js:2: Missing or invalid tag name']);
'Braces are not balanced',
'Missing or invalid tag name']);
t.end();
});

View File

@ -13,6 +13,7 @@ test('polyglot', function (t) {
});
delete result[0].context.file;
t.deepEqual(result, [{
errors: [],
context: {
loc: { end: { column: 3, line: 40 }, start: { column: 1, line: 35 } } },
description: 'This method moves a hex to a color',

View File

@ -13,6 +13,7 @@ var UPDATE = !!process.env.UPDATE;
function normalize(result) {
result.forEach(function (item) {
delete item.errors;
item.context.file = path.relative(__dirname, item.context.file);
});
return result;