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-13 08:25:32 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const rm = require('rimraf').sync;
|
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('..');
|
|
|
|
const SourceFactory = require('../../SourceFactory');
|
|
|
|
const GoldenUtils = require('../../../../test/golden-utils');
|
2017-07-13 08:25:32 +00:00
|
|
|
|
|
|
|
const OUTPUT_DIR = path.join(__dirname, 'output');
|
|
|
|
const GOLDEN_DIR = path.join(__dirname, 'golden');
|
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-07-13 08:25:32 +00:00
|
|
|
let specName;
|
|
|
|
|
|
|
|
jasmine.getEnv().addReporter({
|
|
|
|
specStarted: result => specName = result.description
|
|
|
|
});
|
2017-07-12 18:42:36 +00:00
|
|
|
|
|
|
|
beforeAll(SX(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-07-13 08:25:32 +00:00
|
|
|
if (fs.existsSync(OUTPUT_DIR))
|
|
|
|
rm(OUTPUT_DIR);
|
2017-07-12 18:42:36 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
afterAll(SX(async function() {
|
|
|
|
await browser.close();
|
|
|
|
}));
|
|
|
|
|
2017-07-31 04:49:04 +00:00
|
|
|
describe('checkPublicAPI', function() {
|
2017-07-13 08:25:32 +00:00
|
|
|
it('01-class-errors', SX(test));
|
|
|
|
it('02-method-errors', SX(test));
|
|
|
|
it('03-property-errors', SX(test));
|
|
|
|
it('04-bad-arguments', SX(test));
|
2017-07-21 17:27:53 +00:00
|
|
|
it('05-event-errors', SX(test));
|
2017-07-13 22:15:31 +00:00
|
|
|
it('06-duplicates', SX(test));
|
|
|
|
it('07-sorting', SX(test));
|
2017-07-13 22:54:37 +00:00
|
|
|
it('08-return', SX(test));
|
2017-07-12 18:42:36 +00:00
|
|
|
});
|
|
|
|
|
2017-07-13 08:25:32 +00:00
|
|
|
async function test() {
|
2017-07-31 04:49:04 +00:00
|
|
|
const dirPath = path.join(__dirname, specName);
|
2017-10-02 18:37:16 +00:00
|
|
|
GoldenUtils.addMatchers(jasmine, dirPath, dirPath);
|
2017-07-31 04:49:04 +00:00
|
|
|
const factory = new SourceFactory();
|
|
|
|
const mdSources = await factory.readdir(dirPath, '.md');
|
|
|
|
const jsSources = await factory.readdir(dirPath, '.js');
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|