This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): api documentation tests (#58)
* chore(docs): converted to new style * chore(tests): added test to verify api fns documented
- Loading branch information
Showing
1 changed file
with
39 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
'use strict' | ||
|
||
var fs = require('fs') | ||
var path = require('path') | ||
var test = require('tap').test | ||
const BB = require('bluebird') | ||
|
||
test('all fixtures are documented', function (t) { | ||
const fs = BB.promisifyAll(require('fs')) | ||
const path = require('path') | ||
const test = require('tap').test | ||
|
||
test('all fixtures are documented', t => { | ||
// TODO - actually parse that table and make sure the | ||
// important bits are documented? | ||
var readmePath = path.join(__dirname, 'fixtures', 'README.md') | ||
fs.readFile(readmePath, 'utf8', function (err, text) { | ||
if (err) { throw err } | ||
fs.readdir(path.dirname(readmePath), function (err, files) { | ||
if (err) { throw err } | ||
return BB.join( | ||
fs.readFileAsync(readmePath, 'utf8'), | ||
fs.readdirAsync(path.dirname(readmePath)), | ||
(text, files) => { | ||
files.forEach(function (f) { | ||
if (f !== 'README.md') { | ||
t.match(text, f, f + ' is mentioned.') | ||
} | ||
}) | ||
t.end() | ||
} | ||
) | ||
}) | ||
|
||
test('all toplevel api calls are documented', t => { | ||
const pacote = require('../') | ||
function getFns (obj) { | ||
const fns = [] | ||
for (let k in obj) { | ||
if (obj.hasOwnProperty(k) && typeof obj[k] === 'function') { | ||
fns.push(k) | ||
fns.push.apply(fns, getFns(obj[k], k).map(n => `${k}.${n}`)) | ||
} | ||
} | ||
return fns | ||
} | ||
let apiFns = getFns(pacote) | ||
t.comment(apiFns) | ||
return fs.readFileAsync( | ||
path.join(__dirname, '..', 'README.md'), | ||
'utf8' | ||
).then(readme => { | ||
apiFns.forEach(fn => { | ||
t.match( | ||
readme, | ||
new RegExp(`#### <a name="[^"]+"></a> \`> pacote.${fn}\\([^)]+\\)\``, 'g'), | ||
`pacote.${fn} has a docs entry` | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
test('all toplevel api calls are documented') | ||
test('all options are documented') |