[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
This commit is contained in:
Andrey Lushnikov
2017-07-12 11:42:36 -07:00
parent 64ebcdba9f
commit d99031ba46
26 changed files with 410 additions and 169 deletions

View File

@@ -0,0 +1,2 @@
class Foo {
}

View File

@@ -0,0 +1,3 @@
### class: Foo
### class: Bar

View File

@@ -0,0 +1,2 @@
class Foo {
}

View File

@@ -0,0 +1,2 @@
### class: Foo

View File

@@ -0,0 +1,4 @@
class Foo {
bar() {
}
}

View File

@@ -0,0 +1,4 @@
### class: Foo
#### foo.bar()

View File

@@ -0,0 +1,2 @@
class Foo {
}

View File

@@ -0,0 +1,3 @@
### class: Foo
#### new Foo()

View File

@@ -0,0 +1,5 @@
class Foo {
constructor() {
this.barProperty = 42;
}
}

View File

@@ -0,0 +1,3 @@
### class: Foo
#### foo.bazProperty

View File

@@ -0,0 +1,4 @@
class Foo {
constructor() {
}
}

View File

@@ -0,0 +1,4 @@
### class: Foo
#### new Foo(arg2)
- `arg2` <[string]> Some arg.

View File

@@ -0,0 +1,4 @@
class Foo {
constructor(arg1) {
}
}

View File

@@ -0,0 +1,8 @@
<!-- toc -->
- [class: Dialog](#class-dialog)
<!-- tocstop -->
### class: Foo

View File

@@ -0,0 +1,2 @@
class Foo {
}

View File

@@ -0,0 +1,73 @@
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);
}