puppeteer/utils/doclint/test/test.js
Andrey Lushnikov 0960dc38d1 Automatically generate table-of-contents for markdown
This patch teaches doclint to regenerate table of contents
automatically whenever it's needed.

This patch:
- splits lint.js into lint.js and cli.js
- teaches cli.js to generate table-of-contents
- removes the test for table-of-contents errors from doclint
- adds a test for doclint failing to parse object destructuring in
  method parameters.
2017-07-21 11:12:05 -07:00

55 lines
1.4 KiB
JavaScript

const fs = require('fs');
const rm = require('rimraf').sync;
const path = require('path');
const Browser = require('../../../lib/Browser');
const doclint = require('../lint');
const GoldenUtils = require('../../../test/golden-utils');
const OUTPUT_DIR = path.join(__dirname, 'output');
const GOLDEN_DIR = path.join(__dirname, 'golden');
const browser = new Browser({args: ['--no-sandbox']});
let page;
let specName;
jasmine.getEnv().addReporter({
specStarted: result => specName = result.description
});
beforeAll(SX(async function() {
page = await browser.newPage();
if (fs.existsSync(OUTPUT_DIR))
rm(OUTPUT_DIR);
}));
afterAll(SX(async function() {
await browser.close();
}));
beforeEach(function() {
GoldenUtils.addMatchers(jasmine, GOLDEN_DIR, OUTPUT_DIR);
});
describe('doclint', function() {
it('01-class-errors', SX(test));
it('02-method-errors', SX(test));
it('03-property-errors', SX(test));
it('04-bad-arguments', SX(test));
it('05-event-errors', SX(test));
it('06-duplicates', SX(test));
it('07-sorting', SX(test));
it('08-return', SX(test));
});
async function test() {
const filePath = path.join(__dirname, specName);
const errors = await doclint(page, filePath, filePath);
expect(errors.join('\n')).toBeGolden(specName + '.txt');
}
// Since Jasmine doesn't like async functions, they should be wrapped
// in a SX function.
function SX(fun) {
return done => Promise.resolve(fun()).then(done).catch(done.fail);
}