chore: fix doclint tests (#1098)

This fixes the doclint tests so that `npm test` works. It also adds all the browsers to npm test.

Fixes #8
This commit is contained in:
Joel Einbinder 2020-02-24 18:24:02 -08:00 committed by GitHub
parent 6acc439450
commit b50e8b377f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 59 additions and 56 deletions

View file

@ -21,7 +21,7 @@
"wunit": "npm run wtest",
"debug-test": "node --inspect-brk test/test.js",
"test-doclint": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js",
"test": "npm run lint --silent && npm run coverage && npm run test-doclint && node utils/testrunner/test/test.js",
"test": "npm run lint --silent && npm run ccoverage && npm run fcoverage && npm run wcoverage && npm run test-doclint && node utils/testrunner/test/test.js",
"prepare": "node prepare.js",
"lint": "([ \"$CI\" = true ] && eslint --quiet -f codeframe --ext js,ts ./src || eslint --ext js,ts ./src) && npm run tsc && npm run doc",
"doc": "node utils/doclint/cli.js",

View file

@ -73,7 +73,7 @@ Documentation.Class = class {
}
}
validateOrder(errors) {
validateOrder(errors, cls) {
const members = this.membersArray;
// Events should go first.
let eventIndex = 0;

View file

@ -28,7 +28,7 @@ module.exports = { checkSources, expandPrefix };
function checkSources(sources, externalDependencies) {
// special treatment for Events.js
const classEvents = new Map();
const eventsSources = sources.filter(source => source.name().startsWith('events.ts'));
const eventsSources = sources.filter(source => source.name().startsWith('events.'));
for (const eventsSource of eventsSources) {
const {Events} = require(eventsSource.filePath().endsWith('.js') ? eventsSource.filePath() : eventsSource.filePath().replace(/\bsrc\b/, 'lib').replace('.ts', '.js'));
for (const [className, events] of Object.entries(Events))

View file

@ -306,7 +306,7 @@ module.exports = async function(page, sources) {
// Push base class documentation to derived classes.
for (const [name, clazz] of documentation.classes.entries()) {
clazz.validateOrder(errors);
clazz.validateOrder(errors, clazz);
if (!clazz.extends || clazz.extends === 'EventEmitter' || clazz.extends === 'Error')
continue;

View file

@ -0,0 +1,13 @@
class Foo {
test() {
}
title(arg: number) {
}
}
class Bar {
}
export {Bar};
export {Foo};

View file

@ -1,13 +0,0 @@
class Foo {
test() {
}
/**
* @param {number} arg
*/
title(arg) {
}
}
class Bar {
}

View file

@ -18,3 +18,5 @@ class Foo {
async asyncFunction() {
}
}
export {Foo};

View file

@ -1,7 +1,5 @@
class Foo {
constructor() {
this.ddd = 10;
}
ddd = 10;
aaa() {}
@ -10,3 +8,4 @@ class Foo {
ccc() {}
}
export {Foo};

View file

@ -0,0 +1,11 @@
class Foo {
foo(arg1: string, arg3 = {}) {
}
test(...filePaths : string[]) {
}
bar(options: {visibility?: boolean}) {
}
}
export {Foo};

View file

@ -1,19 +0,0 @@
class Foo {
/**
* @param {string} arg1
*/
foo(arg1, arg3 = {}) {
}
/**
* @param {...string} filePaths
*/
test(...filePaths) {
}
/**
* @param {{visibility?: boolean}} options
*/
bar(options) {
}
}

View file

@ -0,0 +1,2 @@
export {Foo} from './foo';
export {Other} from './other';

View file

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

View file

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

View file

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

View file

@ -0,0 +1,2 @@
export class Other {
}

View file

@ -14,3 +14,5 @@ class Foo {
money$$money() {
}
}
export {Foo};

View file

@ -0,0 +1,5 @@
class Foo {
a = 42;
b = 'hello';
}
export {Foo};

View file

@ -1,7 +0,0 @@
class Foo {
constructor() {
this.a = 42;
this.b = 'hello';
this.emit('done');
}
}

View file

@ -1,7 +1,7 @@
class A {
property1 = 1;
_property2 = 2;
constructor(delegate) {
this.property1 = 1;
this._property2 = 2;
}
get getter() {
@ -11,3 +11,5 @@ class A {
async method(foo, bar) {
}
}
export {A};

View file

@ -13,3 +13,6 @@ class B extends A {
bar(override) {
}
}
export {A};
export {B};

View file

@ -34,7 +34,7 @@ let browserContext;
let page;
beforeAll(async function() {
browser = await playwright.launch();
browser = await playwright.chromium.launch();
page = await browser.newPage();
});
@ -65,8 +65,9 @@ async function testLint(state, test) {
});
const mdSources = await Source.readdir(dirPath, '.md');
const tsSources = await Source.readdir(dirPath, '.ts');
const jsSources = await Source.readdir(dirPath, '.js');
const messages = await checkPublicAPI(page, mdSources, jsSources);
const messages = await checkPublicAPI(page, mdSources, jsSources.concat(tsSources));
const errors = messages.map(message => message.text);
expect(errors.join('\n')).toBeGolden('result.txt');
}
@ -86,8 +87,9 @@ async function testJSBuilder(state, test) {
const {expect} = new Matchers({
toBeGolden: GoldenUtils.compare.bind(null, dirPath, dirPath)
});
const sources = await Source.readdir(dirPath, '.js');
const {documentation} = await jsBuilder(sources);
const jsSources = await Source.readdir(dirPath, '.js');
const tsSources = await Source.readdir(dirPath, '.ts');
const {documentation} = await jsBuilder.checkSources(jsSources.concat(tsSources));
expect(serialize(documentation)).toBeGolden('result.txt');
}