Skip to content

Commit 5bfc660

Browse files
committed
test(coverage): Improve test coverage of document exported
1 parent 4c66fb1 commit 5bfc660

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

bin/documentation.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ var argv = yargs
1212
.command(commands.build)
1313
.command(commands.lint)
1414
.command(commands.readme)
15+
.fail(function (msg, error) {
16+
throw error;
17+
})
1518
.version(function () {
1619
return require('../package').version;
1720
})

lib/commands/build.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,15 @@ module.exports.builder = extend({},
4949
* just a thin wrapper around this one.
5050
*/
5151
module.exports.handler = function build(argv, callback) {
52+
console.log(argv);
5253
argv._handled = true;
5354
argv = sharedOptions.expandInputs(argv);
5455
if (argv.f === 'html' && argv.o === 'stdout') {
5556
throw new Error('The HTML output mode requires a destination directory set with -o');
5657
}
5758

5859
var generator = documentation.build
59-
.bind(null, argv.input, argv, onDocumented);
60-
61-
function onDocumented(err, comments) {
62-
if (err) {
60+
.bind(null, argv.input, argv, onDocumented); function onDocumented(err, comments) { if (err) {
6361
if (typeof callback === 'function') {
6462
return callback(err);
6563
}

lib/extractors/exported.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ function walkExported(ast, data, addComment) {
103103
throw new Error('Unreachable');
104104
}
105105

106+
if (bindingPath === undefined) {
107+
throw new Error(`Unable to find the value ${exported} in ${specData.file}`);
108+
}
106109
traverseExportedSubtree(bindingPath, specData, addComments, exported);
107110
});
108111
return path.skip();
@@ -242,7 +245,10 @@ function findExportDeclaration(dataCache, name, exportKind, referrer, filename)
242245
}
243246
});
244247

245-
return {ast: rv, data: data};
248+
return {
249+
ast: rv,
250+
data: data
251+
};
246252
}
247253

248254
// Since we cannot use scope.getBinding for types this walks the current scope looking for a
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export var z = 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {y as x} from './exports-z.js';

test/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ if (fs.existsSync(path.join(__dirname, '../.git'))) {
5959
});
6060
}
6161

62+
test('document-exported error', function (t) {
63+
var file = path.join(__dirname, 'fixture', 'document-exported-bad', 'x.js');
64+
documentation.build([file], { documentExported: true }, function (err, result) {
65+
t.match(err.message, /Unable to find the value x/g, 'Produces a descriptive error');
66+
t.end();
67+
});
68+
});
69+
6270
test('external modules option', function (t) {
6371
documentation.build([
6472
path.join(__dirname, 'fixture', 'external.input.js')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy