Skip to content

Commit

Permalink
chore: fix doclint tests (#1098)
Browse files Browse the repository at this point in the history
This fixes the doclint tests so that `npm test` works. It also adds all the browsers to npm test.

Fixes #8
  • Loading branch information
JoelEinbinder authored Feb 25, 2020
1 parent 6acc439 commit b50e8b3
Show file tree
Hide file tree
Showing 26 changed files with 59 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/check_public_api/Documentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Documentation.Class = class {
}
}

validateOrder(errors) {
validateOrder(errors, cls) {
const members = this.membersArray;
// Events should go first.
let eventIndex = 0;
Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/check_public_api/JSBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/check_public_api/MDBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions utils/doclint/check_public_api/test/check-duplicates/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Foo {
test() {
}

title(arg: number) {
}
}

class Bar {
}

export {Bar};
export {Foo};
13 changes: 0 additions & 13 deletions utils/doclint/check_public_api/test/check-duplicates/foo.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ class Foo {
async asyncFunction() {
}
}

export {Foo};
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Foo {
constructor() {
this.ddd = 10;
}
ddd = 10;

aaa() {}

Expand All @@ -10,3 +8,4 @@ class Foo {
ccc() {}
}

export {Foo};
11 changes: 11 additions & 0 deletions utils/doclint/check_public_api/test/diff-arguments/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Foo {
foo(arg1: string, arg3 = {}) {
}

test(...filePaths : string[]) {
}

bar(options: {visibility?: boolean}) {
}
}
export {Foo};
19 changes: 0 additions & 19 deletions utils/doclint/check_public_api/test/diff-arguments/foo.js

This file was deleted.

2 changes: 2 additions & 0 deletions utils/doclint/check_public_api/test/diff-classes/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {Foo} from './foo';
export {Other} from './other';
2 changes: 0 additions & 2 deletions utils/doclint/check_public_api/test/diff-classes/foo.js

This file was deleted.

2 changes: 2 additions & 0 deletions utils/doclint/check_public_api/test/diff-classes/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export class Foo {
}
2 changes: 0 additions & 2 deletions utils/doclint/check_public_api/test/diff-classes/other.js

This file was deleted.

2 changes: 2 additions & 0 deletions utils/doclint/check_public_api/test/diff-classes/other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export class Other {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Foo {
}

export {Foo};
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ class Foo {
money$$money() {
}
}

export {Foo};
5 changes: 5 additions & 0 deletions utils/doclint/check_public_api/test/diff-properties/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo {
a = 42;
b = 'hello';
}
export {Foo};
7 changes: 0 additions & 7 deletions utils/doclint/check_public_api/test/diff-properties/foo.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class A {
property1 = 1;
_property2 = 2;
constructor(delegate) {
this.property1 = 1;
this._property2 = 2;
}

get getter() {
Expand All @@ -11,3 +11,5 @@ class A {
async method(foo, bar) {
}
}

export {A};
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ class B extends A {
bar(override) {
}
}

export {A};
export {B};
10 changes: 6 additions & 4 deletions utils/doclint/check_public_api/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let browserContext;
let page;

beforeAll(async function() {
browser = await playwright.launch();
browser = await playwright.chromium.launch();
page = await browser.newPage();
});

Expand Down Expand Up @@ -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');
}
Expand All @@ -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');
}

Expand Down

0 comments on commit b50e8b3

Please sign in to comment.