puppeteer/utils/doclint/test/test.js
Andrey Lushnikov d99031ba46 [doclint] Move doclint under utils/
This patch:
- moves doclint under utils/ folder
- adds tests to verify doclint basic functionality

This patch also drops the jasmine as a spec runner for the doclint
checks. It turned out it's hard to customize jasmine's behavior,
so instead this patch implements a dummy spec runner.

The dummy spec runner allows us:
- to format messages however we want (the custom jasmine reporter would
  also allow us to do this)
- to avoid `beforeAll` functions which pollute global to pass
  initialized variables over to specs

References #14
2017-07-13 00:28:52 -07:00

74 lines
2.3 KiB
JavaScript

const path = require('path');
const jsBuilder = require('../JSBuilder');
const mdBuilder = require('../MDBuilder');
const Documentation = require('../Documentation');
const Browser = require('../../../lib/Browser');
const browser = new Browser({args: ['--no-sandbox']});
let page;
beforeAll(SX(async function() {
page = await browser.newPage();
}));
afterAll(SX(async function() {
await browser.close();
}));
describe('doclint', function() {
test('01-missing-class', diff => {
expect(diff.missingClasses.length).toBe(1);
expect(diff.missingClasses[0]).toBe('Foo');
});
test('02-extra-class', diff => {
expect(diff.extraClasses.length).toBe(1);
expect(diff.extraClasses[0]).toBe('Bar');
});
test('03-missing-method', diff => {
expect(diff.missingMethods.length).toBe(1);
expect(diff.missingMethods[0]).toBe('Foo.bar');
});
test('04-extra-method', diff => {
expect(diff.extraMethods.length).toBe(1);
expect(diff.extraMethods[0]).toBe('Foo.bar');
});
test('05-missing-property', diff => {
expect(diff.missingProperties.length).toBe(1);
expect(diff.missingProperties[0]).toBe('Foo.barProperty');
});
test('06-extra-property', diff => {
expect(diff.extraProperties.length).toBe(1);
expect(diff.extraProperties[0]).toBe('Foo.bazProperty');
});
test('07-bad-arguments', diff => {
expect(diff.badArguments.length).toBe(1);
expect(diff.badArguments[0]).toEqual({
method: 'Foo.constructor',
missingArgs: ['arg1'],
extraArgs: ['arg2']
});
});
test('08-outdated-table-of-contents', (diff, mdErrors) => {
expect(mdErrors.length).toBe(1);
expect(mdErrors[0]).toBe('Markdown TOC is outdated, run `yarn generate-toc`');
});
});
async function test(folderName, func) {
it(folderName, SX(async () => {
const [jsResult, mdResult] = await Promise.all([
jsBuilder(path.join(__dirname, folderName)),
mdBuilder(page, path.join(__dirname, folderName))
]);
const jsDocumentation = jsResult;
const mdDocumentation = mdResult.documentation;
func(Documentation.diff(mdDocumentation, jsDocumentation), mdResult.errors);
}));
}
// 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);
}