Skip to content

Commit d47a224

Browse files
committed
Consolidate similar tests, bump coverage.
1 parent 6e919ef commit d47a224

38 files changed

+1465
-1278
lines changed

bin/documentation.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ function onFormatted(parsedArgs, err, output) {
5353
}
5454
}
5555

56-
if (parsedArgs.watch) {
57-
var watcher = chokidar.watch(parsedArgs.inputs);
58-
watcher.on('all', debounce(generator, 300));
59-
} else if (parsedArgs.command === 'lint') {
56+
if (parsedArgs.command === 'lint') {
6057
documentation.lint(parsedArgs.inputs, parsedArgs.options, function (err, lintOutput) {
58+
if (err) {
59+
throw err;
60+
}
6161
if (lintOutput) {
6262
console.log(lintOutput);
6363
process.exit(1);
@@ -67,6 +67,10 @@ if (parsedArgs.watch) {
6767
});
6868
} else {
6969
generator();
70+
if (parsedArgs.watch) {
71+
var watcher = chokidar.watch(parsedArgs.inputs);
72+
watcher.on('all', debounce(generator, 300));
73+
}
7074
}
7175

7276
function updateWatcher() {

index.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ module.exports = function (indexes, options, callback) {
125125
};
126126

127127
/**
128-
* Generate JavaScript documentation as a list of parsed JSDoc
129-
* comments, given a root file as a path.
128+
* Lint files for non-standard or incorrect documentation
129+
* information, returning a potentially-empty string
130+
* of lint information intended for human-readable output.
130131
*
131132
* @param {Array<string>|string} indexes files to process
132133
* @param {Object} options options
@@ -157,27 +158,23 @@ module.exports.lint = function lint(indexes, options, callback) {
157158
if (error) {
158159
return callback(error);
159160
}
160-
try {
161-
callback(null,
162-
formatLint(hierarchy(
163-
inputs
164-
.filter(filterJS)
165-
.reduce(function (memo, file) {
166-
return memo.concat(parseFn(file));
167-
}, [])
168-
.map(pipeline(
169-
lintComments,
170-
inferName(),
171-
inferKind(),
172-
inferParams(),
173-
inferProperties(),
174-
inferReturn(),
175-
inferMembership(),
176-
nest))
177-
.filter(Boolean))));
178-
} catch (e) {
179-
callback(e);
180-
}
161+
callback(null,
162+
formatLint(hierarchy(
163+
inputs
164+
.filter(filterJS)
165+
.reduce(function (memo, file) {
166+
return memo.concat(parseFn(file));
167+
}, [])
168+
.map(pipeline(
169+
lintComments,
170+
inferName(),
171+
inferKind(),
172+
inferParams(),
173+
inferProperties(),
174+
inferReturn(),
175+
inferMembership(),
176+
nest))
177+
.filter(Boolean))));
181178
});
182179
};
183180

test/bin.js

+49-33
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,25 @@ test('--shallow option', function (t) {
8787
});
8888
}, options);
8989

90-
test('bad -f option', function (t) {
91-
documentation(['build -f DOES-NOT-EXIST fixture/internal.input.js'], function (err) {
92-
t.ok(err, 'returns error');
93-
t.end();
94-
});
95-
}, options);
90+
test('invalid arguments', function (group) {
91+
group.test('bad -f option', function (t) {
92+
documentation(['build -f DOES-NOT-EXIST fixture/internal.input.js'], function (err) {
93+
t.ok(err, 'returns error');
94+
t.end();
95+
});
96+
}, options);
97+
98+
group.test('html with no destination', function (t) {
99+
documentation(['build -f html fixture/internal.input.js'], function (err) {
100+
t.ok(err.toString()
101+
.match(/The HTML output mode requires a destination directory set with -o/),
102+
'needs dest for html');
103+
t.end();
104+
});
105+
}, options);
106+
107+
group.end();
108+
});
96109

97110
test('--version', function (t) {
98111
documentation(['--version'], {}, function (err, output) {
@@ -101,35 +114,38 @@ test('--version', function (t) {
101114
}, false);
102115
}, options);
103116

104-
test('html with no destination', function (t) {
105-
documentation(['build -f html fixture/internal.input.js'], function (err) {
106-
t.ok(err.toString()
107-
.match(/The HTML output mode requires a destination directory set with -o/),
108-
'needs dest for html');
109-
t.end();
110-
});
111-
}, options);
117+
test('lint command', function (group) {
112118

113-
test('--lint option', function (t) {
114-
documentation(['lint fixture/lint/lint.input.js'], function (err, data) {
115-
var output = path.join(__dirname, 'fixture/lint/lint.output.js');
116-
data = data.toString().split('\n').slice(2).join('\n');
117-
if (process.env.UPDATE) {
118-
fs.writeFileSync(output, data);
119-
}
120-
t.equal(err.code, 1);
121-
t.equal(data, fs.readFileSync(output, 'utf8'), 'outputs lint');
122-
t.end();
123-
});
124-
}, options);
119+
group.test('generates lint output', function (t) {
120+
documentation(['lint fixture/lint/lint.input.js'], function (err, data) {
121+
var output = path.join(__dirname, 'fixture/lint/lint.output.js');
122+
data = data.toString().split('\n').slice(2).join('\n');
123+
if (process.env.UPDATE) {
124+
fs.writeFileSync(output, data);
125+
}
126+
t.equal(err.code, 1);
127+
t.equal(data, fs.readFileSync(output, 'utf8'), 'outputs lint');
128+
t.end();
129+
});
130+
}, options);
125131

126-
test('--lint option on good file', function (t) {
127-
documentation(['lint fixture/simple.input.js'], {}, function (err, data) {
128-
t.equal(err, null);
129-
t.equal(data, '', 'no output');
130-
t.end();
131-
}, false);
132-
}, options);
132+
group.test('generates no output on a good file', function (t) {
133+
documentation(['lint fixture/simple.input.js'], {}, function (err, data) {
134+
t.equal(err, null);
135+
t.equal(data, '', 'no output');
136+
t.end();
137+
}, false);
138+
}, options);
139+
140+
group.test('exposes syntax error on a bad file', function (t) {
141+
documentation(['lint fixture/bad/syntax.input.js'], {}, function (err, data) {
142+
t.ok(err.code > 0, 'exits with a > 0 exit code');
143+
t.end();
144+
}, false);
145+
}, options);
146+
147+
group.end();
148+
});
133149

134150
test('given no files', function (t) {
135151
documentation(['build'], function (err) {

test/fixture/es6-import.output.custom.md

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ Is it empty
1717

1818
This method says hello
1919

20+
# es6.input
21+
22+
This function returns the number one.
23+
24+
Returns **Number** numberone
25+
2026
# foo
2127

2228
This is an async method

0 commit comments

Comments
 (0)