Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove src/api.ts #6191

Merged
merged 1 commit into from Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -65,7 +65,6 @@ jobs:
script:
- npm run compare-protocol-d-ts
- npm run lint
- npm run test-doclint
- npm run ensure-new-docs-up-to-date

# This bot runs separately as it changes package.json to test puppeteer-core
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -13,8 +13,7 @@
"assert-unit-coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js",
"funit": "PUPPETEER_PRODUCT=firefox npm run unit",
"debug-unit": "node --inspect-brk test/test.js",
"test-doclint": "mocha --config mocha-config/doclint-tests.js",
"test": "npm run tsc && npm run lint --silent && npm run unit-with-coverage && npm run test-doclint && npm run test-types",
"test": "npm run tsc && npm run lint --silent && npm run unit-with-coverage && npm run test-types",
"prepare": "node typescript-if-required.js",
"prepublishOnly": "npm run tsc",
"dev-install": "npm run tsc && node install.js",
Expand Down
48 changes: 0 additions & 48 deletions src/api.ts

This file was deleted.

62 changes: 50 additions & 12 deletions test/coverage-utils.js
Expand Up @@ -34,13 +34,43 @@ const path = require('path');
const fs = require('fs');

/**
* @param {Map<string, boolean>} apiCoverage
* @param {Object} events
* @param {string} className
* @param {!Object} classType
* This object is also used by DocLint to know which classes to check are
* documented. It's a pretty hacky solution but DocLint is going away soon as
* part of the TSDoc migration.
*/
function traceAPICoverage(apiCoverage, events, className, classType) {
className = className.substring(0, 1).toLowerCase() + className.substring(1);
const MODULES_TO_CHECK_FOR_COVERAGE = {
Accessibility: '../src/common/Accessibility',
Browser: '../src/common/Browser',
BrowserContext: '../src/common/Browser',
BrowserFetcher: '../src/node/BrowserFetcher',
CDPSession: '../src/common/Connection',
ConsoleMessage: '../src/common/ConsoleMessage',
Coverage: '../src/common/Coverage',
Dialog: '../src/common/Dialog',
ElementHandle: '../src/common/JSHandle',
ExecutionContext: '../src/common/ExecutionContext',
EventEmitter: '../src/common/EventEmitter',
FileChooser: '../src/common/FileChooser',
Frame: '../src/common/FrameManager',
JSHandle: '../src/common/JSHandle',
Keyboard: '../src/common/Input',
Mouse: '../src/common/Input',
Page: '../src/common/Page',
Puppeteer: '../src/common/Puppeteer',
HTTPRequest: '../src/common/HTTPRequest',
HTTPResponse: '../src/common/HTTPResponse',
SecurityDetails: '../src/common/SecurityDetails',
Target: '../src/common/Target',
TimeoutError: '../src/common/Errors',
Touchscreen: '../src/common/Input',
Tracing: '../src/common/Tracing',
WebWorker: '../src/common/WebWorker',
};

function traceAPICoverage(apiCoverage, className, modulePath) {
const loadedModule = require(modulePath);
const classType = loadedModule[className];

if (!classType || !classType.prototype) {
console.error(
`Coverage error: could not find class for ${className}. Is src/api.ts up to date?`
Expand All @@ -63,8 +93,14 @@ function traceAPICoverage(apiCoverage, events, className, classType) {
});
}

if (events[classType.name]) {
for (const event of Object.values(events[classType.name])) {
/**
* If classes emit events, those events are exposed via an object in the same
* module named XEmittedEvents, where X is the name of the class. For example,
* the Page module exposes PageEmittedEvents.
*/
const eventsName = `${className}EmittedEvents`;
if (loadedModule[eventsName]) {
for (const event of Object.values(loadedModule[eventsName])) {
if (typeof event !== 'symbol')
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, false);
}
Expand Down Expand Up @@ -108,10 +144,11 @@ const trackCoverage = () => {

return {
beforeAll: () => {
const api = require('../src/api');
const events = require('../src/common/Events');
for (const [className, classType] of Object.entries(api))
traceAPICoverage(coverageMap, events, className, classType);
for (const [className, moduleFilePath] of Object.entries(
MODULES_TO_CHECK_FOR_COVERAGE
)) {
traceAPICoverage(coverageMap, className, moduleFilePath);
}
},
afterAll: () => {
writeCoverage(coverageMap);
Expand All @@ -122,4 +159,5 @@ const trackCoverage = () => {
module.exports = {
trackCoverage,
getCoverageResults,
MODULES_TO_CHECK_FOR_COVERAGE,
};
15 changes: 6 additions & 9 deletions utils/doclint/check_public_api/index.js
Expand Up @@ -18,6 +18,9 @@ const jsBuilder = require('./JSBuilder');
const mdBuilder = require('./MDBuilder');
const Documentation = require('./Documentation');
const Message = require('../Message');
const {
MODULES_TO_CHECK_FOR_COVERAGE,
} = require('../../../test/coverage-utils');

const EXCLUDE_PROPERTIES = new Set([
'Browser.create',
Expand All @@ -39,10 +42,7 @@ const EXCLUDE_PROPERTIES = new Set([
module.exports = async function lint(page, mdSources, jsSources) {
const mdResult = await mdBuilder(page, mdSources);
const jsResult = await jsBuilder(jsSources);
const jsDocumentation = filterJSDocumentation(
jsSources,
jsResult.documentation
);
const jsDocumentation = filterJSDocumentation(jsResult.documentation);
const mdDocumentation = mdResult.documentation;

const jsErrors = jsResult.errors;
Expand Down Expand Up @@ -124,14 +124,11 @@ function checkSorting(doc) {
}

/**
* @param {!Array<!Source>} jsSources
* @param {!Documentation} jsDocumentation
* @returns {!Documentation}
*/
function filterJSDocumentation(jsSources, jsDocumentation) {
const apijs = jsSources.find((source) => source.name() === 'api.js');
let includedClasses = null;
if (apijs) includedClasses = new Set(Object.keys(require(apijs.filePath())));
function filterJSDocumentation(jsDocumentation) {
const includedClasses = new Set(Object.keys(MODULES_TO_CHECK_FOR_COVERAGE));
// Filter private classes and methods.
const classes = [];
for (const cls of jsDocumentation.classesArray) {
Expand Down
2 changes: 0 additions & 2 deletions utils/doclint/check_public_api/test/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions utils/doclint/check_public_api/test/check-duplicates/doc.md

This file was deleted.

13 changes: 0 additions & 13 deletions utils/doclint/check_public_api/test/check-duplicates/foo.js

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions utils/doclint/check_public_api/test/check-returns/doc.md

This file was deleted.

20 changes: 0 additions & 20 deletions utils/doclint/check_public_api/test/check-returns/foo.js

This file was deleted.

4 changes: 0 additions & 4 deletions utils/doclint/check_public_api/test/check-returns/result.txt

This file was deleted.

8 changes: 0 additions & 8 deletions utils/doclint/check_public_api/test/check-sorting/Events.js

This file was deleted.

15 changes: 0 additions & 15 deletions utils/doclint/check_public_api/test/check-sorting/doc.md

This file was deleted.

12 changes: 0 additions & 12 deletions utils/doclint/check_public_api/test/check-sorting/foo.js

This file was deleted.

4 changes: 0 additions & 4 deletions utils/doclint/check_public_api/test/check-sorting/result.txt

This file was deleted.

14 changes: 0 additions & 14 deletions utils/doclint/check_public_api/test/diff-arguments/doc.md

This file was deleted.

19 changes: 0 additions & 19 deletions utils/doclint/check_public_api/test/diff-arguments/foo.js

This file was deleted.

4 changes: 0 additions & 4 deletions utils/doclint/check_public_api/test/diff-arguments/result.txt

This file was deleted.

5 changes: 0 additions & 5 deletions utils/doclint/check_public_api/test/diff-classes/doc.md

This file was deleted.

2 changes: 0 additions & 2 deletions utils/doclint/check_public_api/test/diff-classes/foo.js

This file was deleted.

2 changes: 0 additions & 2 deletions utils/doclint/check_public_api/test/diff-classes/other.js

This file was deleted.

3 changes: 0 additions & 3 deletions utils/doclint/check_public_api/test/diff-classes/result.txt

This file was deleted.

8 changes: 0 additions & 8 deletions utils/doclint/check_public_api/test/diff-events/Events.js

This file was deleted.

5 changes: 0 additions & 5 deletions utils/doclint/check_public_api/test/diff-events/doc.md

This file was deleted.

3 changes: 0 additions & 3 deletions utils/doclint/check_public_api/test/diff-events/foo.js

This file was deleted.

2 changes: 0 additions & 2 deletions utils/doclint/check_public_api/test/diff-events/result.txt

This file was deleted.