Skip to content

Commit

Permalink
switch 'cache' option with 'no-cache'.. guaranteed exit.. linting, mo…
Browse files Browse the repository at this point in the history
…re tests
  • Loading branch information
75lb committed Oct 8, 2016
1 parent 25dfd18 commit 0f47f2d
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 251 deletions.
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Returns raw data direct from the underlying [jsdoc3](https://github.com/jsdoc3/j
| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>object</code> | the options |
| [options.cache] | <code>boolean</code> | Set to false to disable memoisation cache. Defaults to true. |
| [options.no-cache] | <code>boolean</code> | By default results are cached to speed up repeat invocations. Set to true to disable this. |
| [options.files] | <code>string</code> &#124; <code>Array.&lt;string&gt;</code> | One or more filenames to process. Accepts globs (e.g. `*.js`). Either `files`, `source` or `data` must be supplied. |
| [options.source] | <code>string</code> | A string containing source code to process. Either `files`, `source` or `data` must be supplied. |
| [options.configure] | <code>string</code> | The path to the [jsdoc configuration file](http://usejsdoc.org/about-configuring-jsdoc.html). Default: path/to/jsdoc/conf.json. |
Expand Down
8 changes: 2 additions & 6 deletions es5/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ var cli = parseCommandLine();
var options = cli.options._all;
options = loadStoredConfig(options);

if (options['no-cache']) {
options.cache = false;
delete options['no-cache'];
}

if (options.help) {
tool.printOutput(cli.usage);
} else if (options.version) {
Expand Down Expand Up @@ -55,7 +50,8 @@ if (options.help) {
if (options.template) options.template = fs.readFileSync(options.template, 'utf8');

_jsdoc2md.render(options).then(function (output) {
return process.stdout.write(output);
process.stdout.write(output);
process.exit(0);
}).catch(handleError);
}
}
Expand Down
34 changes: 3 additions & 31 deletions es5/lib/dmd-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var DmdOptions = function DmdOptions(options) {
_classCallCheck(this, DmdOptions);

var arrayify = require('array-back');

this.template = options.template || '{{>main}}';

this['heading-depth'] = options['heading-depth'] || 2;

this['example-lang'] = options['example-lang'] || 'js';

this.plugin = arrayify(options.plugin);

this.helper = arrayify(options.helper);

this.partial = arrayify(options.partial);

this['name-format'] = options['name-format'];

this['no-gfm'] = options['no-gfm'];

this.separators = options.separators;

this['module-index-format'] = options['module-index-format'] || 'dl';

this['global-index-format'] = options['global-index-format'] || 'dl';

this['param-list-format'] = options['param-list-format'] || 'table';

this['property-list-format'] = options['property-list-format'] || 'table';

this['member-index-format'] = options['member-index-format'] || 'grouped';

this.private = options.private;
Object.assign(this, options);
this.noCache = options['no-cache'];
delete this['no-cache'];
};

module.exports = DmdOptions;
5 changes: 4 additions & 1 deletion es5/lib/jsdoc-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ var JsdocOptions = function JsdocOptions(options) {
_classCallCheck(this, JsdocOptions);

Object.assign(this, options);
this.cache = options.cache === undefined ? true : options.cache;
if (options['no-cache']) {
this.cache = !options['no-cache'];
delete this['no-cache'];
}
};

module.exports = JsdocOptions;
1 change: 0 additions & 1 deletion es5/lib/jsdoc-to-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var stats = require('jsdoc2md-stats');
var jsdocApi = require('jsdoc-api');
var dmd = require('dmd');
var os = require('os');
var DmdOptions = require('./dmd-options');
var JsdocOptions = require('./jsdoc-options');

Expand Down
117 changes: 90 additions & 27 deletions es5/test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,127 @@ var runner = new TestRunner();
var inputFile = 'src/test/fixture/ignore.js';

runner.test('.render({ files })', function () {
return jsdoc2md.render({ files: inputFile, cache: false }).then(function (result) {
return jsdoc2md.render({ files: inputFile }).then(function (result) {
return a.ok(/a visible global/.test(result));
});
});

runner.test('.render({ data })', function () {
var data = [{
"id": "visible",
"longname": "visible",
"name": "visible",
"kind": "member",
"scope": "global",
"description": "a visible global",
"meta": {
"lineno": 4,
"filename": "ignore.js"
id: 'visible',
longname: 'visible',
name: 'visible',
kind: 'member',
scope: 'global',
description: 'a visible global',
meta: {
lineno: 4,
filename: 'ignore.js'
},
"order": 0
order: 0
}, {
"id": "invisible",
"longname": "invisible",
"name": "invisible",
"kind": "member",
"scope": "global",
"description": "an ignored global",
"ignore": true,
"meta": {
"lineno": 10,
"filename": "ignore.js"
id: 'invisible',
longname: 'invisible',
name: 'invisible',
kind: 'member',
scope: 'global',
description: 'an ignored global',
ignore: true,
meta: {
lineno: 10,
filename: 'ignore.js'
},
"order": 1
order: 1
}];
return jsdoc2md.render({ data: data, cache: false }).then(function (result) {
return jsdoc2md.render({ data: data }).then(function (result) {
return a.ok(/a visible global/.test(result));
});
});

runner.test('.render({ files, heading-depth: 4 })', function () {
return jsdoc2md.render({ files: inputFile, cache: false, 'heading-depth': 4 }).then(function (result) {
return jsdoc2md.render({ files: inputFile, 'heading-depth': 4 }).then(function (result) {
return a.ok(/#### visible/.test(result));
});
});

runner.test('.render({ files, param-list-format: list })', function () {
var inputFile = 'src/test/fixture/params.js';
return jsdoc2md.render({ files: inputFile, cache: false, 'param-list-format': 'list' }).then(function (result) {
return jsdoc2md.render({ files: inputFile, 'param-list-format': 'list' }).then(function (result) {
return a.ok(/- one/.test(result));
});
});

runner.test('.getTemplateData({ files })', function () {
return jsdoc2md.getTemplateData({ files: inputFile, cache: false }).then(function (result) {
return jsdoc2md.getTemplateData({ files: inputFile }).then(function (result) {
return a.ok(result[0].id);
});
});

runner.test('.getJsdocData({ files })', function () {
return jsdoc2md.getJsdocData({ files: inputFile, cache: false }).then(function (result) {
return jsdoc2md.getJsdocData({ files: inputFile }).then(function (result) {
return a.ok(result[0].longname);
});
});

runner.test('.render({ files, noCache })', function () {
return jsdoc2md.render({ files: inputFile, noCache: true }).then(function (result) {
return a.ok(/a visible global/.test(result));
});
});

runner.test('.render({ data, noCache })', function () {
var data = [{
id: 'visible',
longname: 'visible',
name: 'visible',
kind: 'member',
scope: 'global',
description: 'a visible global',
meta: {
lineno: 4,
filename: 'ignore.js'
},
order: 0
}, {
id: 'invisible',
longname: 'invisible',
name: 'invisible',
kind: 'member',
scope: 'global',
description: 'an ignored global',
ignore: true,
meta: {
lineno: 10,
filename: 'ignore.js'
},
order: 1
}];
return jsdoc2md.render({ data: data, noCache: true }).then(function (result) {
return a.ok(/a visible global/.test(result));
});
});

runner.test('.render({ files, heading-depth: 4, noCache })', function () {
return jsdoc2md.render({ files: inputFile, 'heading-depth': 4, noCache: true }).then(function (result) {
return a.ok(/#### visible/.test(result));
});
});

runner.test('.render({ files, param-list-format: list, noCache })', function () {
var inputFile = 'src/test/fixture/params.js';
return jsdoc2md.render({ files: inputFile, 'param-list-format': 'list', noCache: true }).then(function (result) {
return a.ok(/- one/.test(result));
});
});

runner.test('.getTemplateData({ files, noCache })', function () {
return jsdoc2md.getTemplateData({ files: inputFile, noCache: true }).then(function (result) {
return a.ok(result[0].id);
});
});

runner.test('.getJsdocData({ files, noCache })', function () {
return jsdoc2md.getJsdocData({ files: inputFile, noCache: true }).then(function (result) {
return a.ok(result[0].longname);
});
});
43 changes: 21 additions & 22 deletions es5/test/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ if (!require('child_process').spawnSync) process.exit(0);
var TestRunner = require('test-runner');
var jsdoc2md = require('../../');
var a = require('assert');
var path = require('path');
var fs = require('fs');

try {
Expand All @@ -21,30 +20,30 @@ runner.test('.renderSync({ files })', function () {

runner.test('.renderSync({ data })', function () {
var data = [{
"id": "visible",
"longname": "visible",
"name": "visible",
"kind": "member",
"scope": "global",
"description": "a visible global",
"meta": {
"lineno": 4,
"filename": "ignore.js"
id: 'visible',
longname: 'visible',
name: 'visible',
kind: 'member',
scope: 'global',
description: 'a visible global',
meta: {
lineno: 4,
filename: 'ignore.js'
},
"order": 0
order: 0
}, {
"id": "invisible",
"longname": "invisible",
"name": "invisible",
"kind": "member",
"scope": "global",
"description": "an ignored global",
"ignore": true,
"meta": {
"lineno": 10,
"filename": "ignore.js"
id: 'invisible',
longname: 'invisible',
name: 'invisible',
kind: 'member',
scope: 'global',
description: 'an ignored global',
ignore: true,
meta: {
lineno: 10,
filename: 'ignore.js'
},
"order": 1
order: 1
}];
var result = jsdoc2md.renderSync({ data: data, cache: false });
a.ok(/a visible global/.test(result));
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"command-line-tool": "^0.6.4",
"config-master": "^2.0.4",
"core-js": "^2.4.1",
"dmd": "^2.0.3",
"dmd": "^2.1.0",
"feature-detect-es6": "^1.3.1",
"jsdoc-api": "^2.0.3",
"jsdoc-api": "^2.0.5",
"jsdoc-parse": "^2.0.5",
"jsdoc2md-stats": "^1.0.1",
"walk-back": "^2.0.1"
Expand Down
11 changes: 4 additions & 7 deletions src/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ const cli = parseCommandLine()
let options = cli.options._all
options = loadStoredConfig(options)

/* jsdoc2md --no-cache */
if (options['no-cache']) {
options.cache = false
delete options['no-cache']
}

/* jsdoc2md --help */
if (options.help) {
tool.printOutput(cli.usage)
Expand Down Expand Up @@ -79,7 +73,10 @@ if (options.help) {

jsdoc2md
.render(options)
.then(output => process.stdout.write(output))
.then(output => {
process.stdout.write(output)
process.exit(0)
})
.catch(handleError)
}
}
Expand Down
Loading

0 comments on commit 0f47f2d

Please sign in to comment.