docs: explicitly annotate methods and parameters (#4771)

This commit is contained in:
Pavel Feldman 2020-12-18 15:31:34 -08:00 committed by GitHub
parent c81ec9ccca
commit 2e220df7ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 932 additions and 1199 deletions

File diff suppressed because it is too large Load diff

View file

@ -77,7 +77,7 @@ This object can be used to launch or connect to Chromium, returning instances of
#### playwright.devices #### playwright.devices
- returns: <[Object]> - returns: <[Object]>
Returns a list of devices to be used with [`browser.newContext([options])`](#browsernewcontextoptions) or [`browser.newPage([options])`](#browsernewpageoptions). Actual list of devices can be found in [src/server/deviceDescriptors.ts](https://github.com/Microsoft/playwright/blob/master/src/server/deviceDescriptors.ts). Returns a list of devices to be used with [`method: Browser.newContext`]() or [`method: Browser.newPage`](). Actual list of devices can be found in [src/server/deviceDescriptors.ts](https://github.com/Microsoft/playwright/blob/master/src/server/deviceDescriptors.ts).
```js ```js
const { webkit, devices } = require('playwright'); const { webkit, devices } = require('playwright');
@ -99,7 +99,7 @@ const iPhone = devices['iPhone 6'];
- returns: <[Object]> - returns: <[Object]>
- `TimeoutError` <[function]> A class of [TimeoutError]. - `TimeoutError` <[function]> A class of [TimeoutError].
Playwright methods might throw errors if they are unable to fulfill a request. For example, [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options) Playwright methods might throw errors if they are unable to fulfill a request. For example, [`method: Page.waitForSelector`]()
might fail if the selector doesn't match any nodes during the given timeframe. might fail if the selector doesn't match any nodes during the given timeframe.
For certain types of errors Playwright uses specific error classes. For certain types of errors Playwright uses specific error classes.

View file

@ -13,25 +13,25 @@ When to consider operation succeeded, defaults to `load`. Events can be either:
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
The default value can be changed by using the The default value can be changed by using the
[browserContext.setDefaultNavigationTimeout()](), [`method: BrowserContext.setDefaultNavigationTimeout`](),
[browserContext.setDefaultTimeout()](), [`method: BrowserContext.setDefaultTimeout`](),
[page.setDefaultNavigationTimeout()]() or [`method: Page.setDefaultNavigationTimeout`]() or
[page.setDefaultTimeout()]() methods. [`method: Page.setDefaultTimeout`]() methods.
## wait-for-timeout ## wait-for-timeout
- `timeout` <[number]> - `timeout` <[number]>
maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default
value can be changed by using the [browserContext.setDefaultTimeout()](). value can be changed by using the [`method: BrowserContext.setDefaultTimeout`]().
## input-timeout ## input-timeout
- `timeout` <[number]> - `timeout` <[number]>
Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
using the [browserContext.setDefaultTimeout()]() or using the [`method: BrowserContext.setDefaultTimeout`]() or
[page.setDefaultTimeout()]() methods. [`method: Page.setDefaultTimeout`]() methods.
## input-no-wait-after ## input-no-wait-after
@ -133,7 +133,7 @@ Defaults to `'visible'`. Can be either:
- `value` <[string]> - `value` <[string]>
Populates context with given storage state. This method can be used to initialize context with logged-in information Populates context with given storage state. This method can be used to initialize context with logged-in information
obtained via [browserContext.storageState()](). Either a path to the file with saved storage, or an object with the following fields: obtained via [`method: BrowserContext.storageState`](). Either a path to the file with saved storage, or an object with the following fields:
## context-option-acceptdownloads ## context-option-acceptdownloads
@ -218,7 +218,7 @@ request header value as well as number and date formatting rules.
- `permissions` <[Array]<[string]>> - `permissions` <[Array]<[string]>>
A list of permissions to grant to all pages in this context. See A list of permissions to grant to all pages in this context. See
[browserContext.grantPermissions()]() for more details. [`method: BrowserContext.grantPermissions`]() for more details.
## context-option-extrahttpheaders ## context-option-extrahttpheaders
@ -245,7 +245,7 @@ Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/W
- `colorScheme` <"light"|"dark"|"no-preference"> - `colorScheme` <"light"|"dark"|"no-preference">
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See
[page.emulateMedia()]() for more details. Defaults to '`light`'. [`method: Page.emulateMedia`]() for more details. Defaults to '`light`'.
## context-option-logger ## context-option-logger
@ -257,9 +257,9 @@ Logger sink for Playwright logging.
- `videosPath` <[string]> - `videosPath` <[string]>
**NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to **NOTE** Use [`param: recordVideo`]() instead, it takes precedence over `videosPath`. Enables video recording for all pages to
`videosPath` directory. If not specified, videos are not recorded. Make sure to await `videosPath` directory. If not specified, videos are not recorded. Make sure to await
[browserContext.close()]() for videos to be saved. [`method: BrowserContext.close`]() for videos to be saved.
## context-option-videosize ## context-option-videosize
@ -267,7 +267,7 @@ Logger sink for Playwright logging.
- `width` <[number]> Video frame width. - `width` <[number]> Video frame width.
- `height` <[number]> Video frame height. - `height` <[number]> Video frame height.
**NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically **NOTE** Use [`param: recordVideo`]() instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically
recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If
`viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled
down if necessary to fit specified size. down if necessary to fit specified size.
@ -280,7 +280,7 @@ down if necessary to fit specified size.
- `path` <[string]> Path on the filesystem to write the HAR file to. - `path` <[string]> Path on the filesystem to write the HAR file to.
Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not
specified, the HAR is not recorded. Make sure to await [browserContext.close()]() for the HAR to be specified, the HAR is not recorded. Make sure to await [`method: BrowserContext.close`]() for the HAR to be
saved. saved.
## context-option-recordvideo ## context-option-recordvideo
@ -294,7 +294,7 @@ saved.
- `height` <[number]> Video frame height. - `height` <[number]> Video frame height.
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make
sure to await [browserContext.close()]() for videos to be saved. sure to await [`method: BrowserContext.close`]() for videos to be saved.
## context-option-proxy ## context-option-proxy

File diff suppressed because it is too large Load diff

View file

@ -199,7 +199,7 @@ async function run() {
} }
} }
} }
api.setText([comment, header, renderMd(nodes), footer].join('\n')); api.setText([comment, header, renderMd(nodes, 10000), footer].join('\n'));
// Generate links // Generate links
preprocessor.generateLinks(api, signatures, messages); preprocessor.generateLinks(api, signatures, messages);

View file

@ -188,22 +188,32 @@ function generateLinks(source, signatures, messages) {
let match; let match;
while (match = linkRegex.exec(line)) { while (match = linkRegex.exec(line)) {
const [, name] = match; const [, name] = match;
const linkOffset = offset + lineNumber + match.index;
const hrefOffset = offset + lineNumber + match.index + 3 + name.length; const hrefOffset = offset + lineNumber + match.index + 3 + name.length;
const eventMatch = name.match(/.*on\('.*'\)/);
let replacement; let replacement;
if (eventMatch) { const memberMatch = name.match(/`(event|method|namespace):\s(JS|CDP|[A-Z])([^.]+)\.(.*)`/m);
replacement = eventMatch[0]; const paramMatch = name.match(/`(?:param|option):\s(.*)`/m);
} else { if (!memberMatch && !paramMatch) {
const method = name.substring(0, name.length - 2); messages.push(Message.error(`Bad link: ${source.filePath()}:${lineNumber + 1}: ${name}`));
return;
}
if (memberMatch && memberMatch[1] === 'event') {
replacement = `${memberMatch[2].toLowerCase() + memberMatch[3]}.on('${memberMatch[4]}')`;
sourceEdits.edit(linkOffset + 1, hrefOffset - 2, replacement);
} else if (memberMatch && memberMatch[1] === 'method') {
const method = memberMatch[2].toLowerCase() + memberMatch[3] + '.' + memberMatch[4];
let signature = signatures.get(method); let signature = signatures.get(method);
if (signature === undefined) { if (signature === undefined) {
messages.push(Message.error(`Bad method link: ${source.filePath()}:${lineNumber + 1}: ${method}`)); messages.push(Message.error(`Bad method link: ${source.filePath()}:${lineNumber + 1}: ${method}`));
signature = '\u2026'; signature = '(\u2026)';
} }
sourceEdits.edit(hrefOffset - 3, hrefOffset - 3, signature); replacement = method + '(' + signature + ')';
replacement = name + signature; sourceEdits.edit(linkOffset + 2, hrefOffset - 3, replacement);
} else if (paramMatch) {
sourceEdits.edit(linkOffset, hrefOffset + 1, '`' + paramMatch[1] + '`');
} }
sourceEdits.edit(hrefOffset, hrefOffset, '#' + replacement.toLowerCase().replace(/[^a-z]/gm, '')); if (replacement)
sourceEdits.edit(hrefOffset, hrefOffset, '#' + replacement.toLowerCase().replace(/[^a-z]/gm, ''));
} }
offset += line.length; offset += line.length;
}); });

View file

@ -14,8 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
const maxColumns = 120;
function normalizeLines(content) { function normalizeLines(content) {
const inLines = content.split('\n'); const inLines = content.split('\n');
let inCodeBlock = false; let inCodeBlock = false;
@ -133,23 +131,17 @@ function parseMd(content) {
return buildTree(normalizeLines(content)); return buildTree(normalizeLines(content));
} }
function renderMd(nodes) { function renderMd(nodes, maxColumns) {
const result = []; const result = [];
let lastNode; let lastNode;
for (let node of nodes) { for (let node of nodes) {
innerRenderMdNode(node, lastNode, result); innerRenderMdNode(node, lastNode, result, maxColumns);
lastNode = node; lastNode = node;
} }
return result.join('\n'); return result.join('\n');
} }
function renderMdNode(node, lastNode) { function innerRenderMdNode(node, lastNode, result, maxColumns = 120) {
const result = [];
innerRenderMdNode(node, lastNode, result);
return result.join('\n');
}
function innerRenderMdNode(node, lastNode, result) {
const newLine = () => { const newLine = () => {
if (result[result.length - 1] !== '') if (result[result.length - 1] !== '')
result.push(''); result.push('');
@ -161,7 +153,7 @@ function innerRenderMdNode(node, lastNode, result) {
result.push(`${'#'.repeat(i)} ${node[`h${i}`]}`); result.push(`${'#'.repeat(i)} ${node[`h${i}`]}`);
let lastNode = node; let lastNode = node;
for (const child of node.children) { for (const child of node.children) {
innerRenderMdNode(child, lastNode, result); innerRenderMdNode(child, lastNode, result, maxColumns);
lastNode = child; lastNode = child;
} }
break; break;
@ -172,7 +164,7 @@ function innerRenderMdNode(node, lastNode, result) {
const bothComments = node.text.startsWith('>') && lastNode && lastNode.text && lastNode.text.startsWith('>'); const bothComments = node.text.startsWith('>') && lastNode && lastNode.text && lastNode.text.startsWith('>');
if (!bothComments && lastNode && (lastNode.text || lastNode.li || lastNode.h1 || lastNode.h2 || lastNode.h3 || lastNode.h4)) if (!bothComments && lastNode && (lastNode.text || lastNode.li || lastNode.h1 || lastNode.h2 || lastNode.h3 || lastNode.h4))
newLine(); newLine();
printText(node, result); printText(node, result, maxColumns);
} }
if (node.code) { if (node.code) {
@ -207,7 +199,7 @@ function innerRenderMdNode(node, lastNode, result) {
} }
} }
function printText(node, result) { function printText(node, result, maxColumns) {
let line = node.text; let line = node.text;
while (line.length > maxColumns) { while (line.length > maxColumns) {
let index = line.lastIndexOf(' ', maxColumns); let index = line.lastIndexOf(' ', maxColumns);