2017-07-28 08:09:26 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-07-12 18:42:36 +00:00
|
|
|
const path = require('path');
|
2017-08-15 01:08:06 +00:00
|
|
|
const puppeteer = require('../../../..');
|
2017-07-31 04:49:04 +00:00
|
|
|
const checkPublicAPI = require('..');
|
2018-04-26 01:07:20 +00:00
|
|
|
const Source = require('../../Source');
|
2017-10-02 18:45:00 +00:00
|
|
|
const mdBuilder = require('../MDBuilder');
|
|
|
|
const jsBuilder = require('../JSBuilder');
|
2017-07-31 04:49:04 +00:00
|
|
|
const GoldenUtils = require('../../../../test/golden-utils');
|
2017-07-13 08:25:32 +00:00
|
|
|
|
2017-12-08 00:37:22 +00:00
|
|
|
const {TestRunner, Reporter, Matchers} = require('../../../testrunner/');
|
|
|
|
const runner = new TestRunner();
|
|
|
|
const reporter = new Reporter(runner);
|
|
|
|
|
|
|
|
const {describe, xdescribe, fdescribe} = runner;
|
|
|
|
const {it, fit, xit} = runner;
|
|
|
|
const {beforeAll, beforeEach, afterAll, afterEach} = runner;
|
2017-07-12 18:42:36 +00:00
|
|
|
|
2017-08-15 01:08:06 +00:00
|
|
|
let browser;
|
2017-07-12 18:42:36 +00:00
|
|
|
let page;
|
|
|
|
|
2017-12-08 00:37:22 +00:00
|
|
|
beforeAll(async function() {
|
2017-08-15 01:08:06 +00:00
|
|
|
browser = await puppeteer.launch({args: ['--no-sandbox']});
|
2017-07-12 18:42:36 +00:00
|
|
|
page = await browser.newPage();
|
2017-12-08 00:37:22 +00:00
|
|
|
});
|
2017-07-12 18:42:36 +00:00
|
|
|
|
2017-12-08 00:37:22 +00:00
|
|
|
afterAll(async function() {
|
2017-07-12 18:42:36 +00:00
|
|
|
await browser.close();
|
2017-12-08 00:37:22 +00:00
|
|
|
});
|
2017-07-12 18:42:36 +00:00
|
|
|
|
2017-07-31 04:49:04 +00:00
|
|
|
describe('checkPublicAPI', function() {
|
2017-12-08 00:37:22 +00:00
|
|
|
it('diff-classes', testLint);
|
|
|
|
it('diff-methods', testLint);
|
|
|
|
it('diff-properties', testLint);
|
|
|
|
it('diff-arguments', testLint);
|
|
|
|
it('diff-events', testLint);
|
|
|
|
it('check-duplicates', testLint);
|
|
|
|
it('check-sorting', testLint);
|
|
|
|
it('check-returns', testLint);
|
|
|
|
it('js-builder-common', testJSBuilder);
|
|
|
|
it('js-builder-inheritance', testJSBuilder);
|
|
|
|
it('md-builder-common', testMDBuilder);
|
2017-07-12 18:42:36 +00:00
|
|
|
});
|
|
|
|
|
2017-12-08 00:37:22 +00:00
|
|
|
runner.run();
|
|
|
|
|
|
|
|
async function testLint(state, test) {
|
|
|
|
const dirPath = path.join(__dirname, test.name);
|
|
|
|
const {expect} = new Matchers({
|
|
|
|
toBeGolden: GoldenUtils.compare.bind(null, dirPath, dirPath)
|
|
|
|
});
|
|
|
|
|
2018-04-26 01:07:20 +00:00
|
|
|
const mdSources = await Source.readdir(dirPath, '.md');
|
|
|
|
const jsSources = await Source.readdir(dirPath, '.js');
|
2017-07-31 04:49:04 +00:00
|
|
|
const messages = await checkPublicAPI(page, mdSources, jsSources);
|
|
|
|
const errors = messages.map(message => message.text);
|
2017-10-02 18:37:16 +00:00
|
|
|
expect(errors.join('\n')).toBeGolden('result.txt');
|
2017-07-12 18:42:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 00:37:22 +00:00
|
|
|
async function testMDBuilder(state, test) {
|
|
|
|
const dirPath = path.join(__dirname, test.name);
|
|
|
|
const {expect} = new Matchers({
|
|
|
|
toBeGolden: GoldenUtils.compare.bind(null, dirPath, dirPath)
|
|
|
|
});
|
2018-04-26 01:07:20 +00:00
|
|
|
const sources = await Source.readdir(dirPath, '.md');
|
2017-10-02 18:45:00 +00:00
|
|
|
const {documentation} = await mdBuilder(page, sources);
|
|
|
|
expect(serialize(documentation)).toBeGolden('result.txt');
|
|
|
|
}
|
|
|
|
|
2017-12-08 00:37:22 +00:00
|
|
|
async function testJSBuilder(state, test) {
|
|
|
|
const dirPath = path.join(__dirname, test.name);
|
|
|
|
const {expect} = new Matchers({
|
|
|
|
toBeGolden: GoldenUtils.compare.bind(null, dirPath, dirPath)
|
|
|
|
});
|
2018-04-26 01:07:20 +00:00
|
|
|
const sources = await Source.readdir(dirPath, '.js');
|
2017-10-02 18:45:00 +00:00
|
|
|
const {documentation} = await jsBuilder(sources);
|
|
|
|
expect(serialize(documentation)).toBeGolden('result.txt');
|
|
|
|
}
|
|
|
|
|
|
|
|
function serialize(doc) {
|
|
|
|
const result = {classes: []};
|
|
|
|
for (let cls of doc.classesArray) {
|
|
|
|
const classJSON = {
|
|
|
|
name: cls.name,
|
|
|
|
members: []
|
|
|
|
};
|
|
|
|
result.classes.push(classJSON);
|
|
|
|
for (let member of cls.membersArray) {
|
|
|
|
classJSON.members.push({
|
|
|
|
name: member.name,
|
|
|
|
type: member.type,
|
|
|
|
hasReturn: member.hasReturn,
|
|
|
|
async: member.async,
|
|
|
|
args: member.argsArray.map(arg => arg.name)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return JSON.stringify(result, null, 2);
|
|
|
|
}
|
|
|
|
|