Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
chore(tests): api documentation tests (#58)
Browse files Browse the repository at this point in the history
* chore(docs): converted to new style

* chore(tests): added test to verify api fns documented
  • Loading branch information
zkat committed Mar 9, 2017
1 parent 3987807 commit 7142eb4
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions test/docs.js
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')

0 comments on commit 7142eb4

Please sign in to comment.