Skip to content

Commit 21dc346

Browse files
authored
devops: auto-correct links in our documentation (#1955)
1 parent 6296614 commit 21dc346

File tree

7 files changed

+203
-97
lines changed

7 files changed

+203
-97
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- [Pages and frames](./core-concepts.md#pages-and-frames)
88
- [Selectors](./core-concepts.md#selectors)
99
- [Auto-waiting](./core-concepts.md#auto-waiting)
10-
- [Node.js and browser execution contexts](./core-concepts.md#node-js-and-browser-execution-contexts)
10+
- [Node.js and browser execution contexts](./core-concepts.md#nodejs-and-browser-execution-contexts)
1111
- [Object & element handles](./core-concepts.md#object--element-handles)
1212
1. [Input](./input.md)
1313
- [Text input](./input.md#text-input)

docs/core-concepts.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ the following primitives.
1414
- [Pages and frames](#pages-and-frames)
1515
- [Selectors](#selectors)
1616
- [Auto-waiting](#auto-waiting)
17-
- [Node.js and browser execution contexts](#node-js-and-browser-execution-contexts)
17+
- [Node.js and browser execution contexts](#nodejs-and-browser-execution-contexts)
1818
- [Object & element handles](#object--element-handles)
1919

2020
<br/>
2121

2222
## Browser
2323

24-
A [`Browser`](../api.md#class-browser) refers to an instance of Chromium, Firefox
24+
A [`Browser`](api.md#class-browser) refers to an instance of Chromium, Firefox
2525
or WebKit. Playwright scripts generally start with launching a browser instance
2626
and end with closing the browser. Browser instances can be launched in headless
2727
(without a GUI) or headful mode.
@@ -44,7 +44,7 @@ maximize what a single instance can do through multiple browser contexts.
4444

4545
## Browser contexts
4646

47-
A [`BrowserContext`](../api.md#class-browsercontext) is an isolated incognito-alike
47+
A [`BrowserContext`](api.md#class-browsercontext) is an isolated incognito-alike
4848
session within a browser instance. Browser contexts are fast and cheap to create.
4949
Browser contexts can be used to parallelize isolated test executions.
5050

@@ -71,13 +71,13 @@ const context = await browser.newContext({
7171

7272
#### API reference
7373

74-
- [class `BrowserContext`](./api.md#class-browser-context)
74+
- [class `BrowserContext`](./api.md#class-browsercontext)
7575

7676
<br/>
7777

7878
## Pages and frames
7979

80-
A Browser context can have multiple pages. A [`Page`](../api.md#class-page)
80+
A Browser context can have multiple pages. A [`Page`](api.md#class-page)
8181
refers to a single tab or a popup window within a browser context. It should be used to navigate to URLs and interact with the page content.
8282

8383
```js
@@ -104,7 +104,7 @@ console.log(page.url());
104104
window.location.href = 'https://example.com';
105105
```
106106

107-
A page can have one or more [Frame](../api.md#class-frame) objects attached to
107+
A page can have one or more [Frame](api.md#class-frame) objects attached to
108108
it. Each page has a main frame and page-level interactions (like `click`) are
109109
assumed to operate in the main frame.
110110

docs/loading.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Explicit loading handling may be required for more complicated scenarios though.
6464

6565
### Loading a popup
6666

67-
When popup is opened, explicitly calling [`page.waitForLoadState()`](#pagewaitforloadstatestate-options) ensures that popup is loaded to the desired state.
67+
When popup is opened, explicitly calling [`page.waitForLoadState()`](api.md#pagewaitforloadstatestate-options) ensures that popup is loaded to the desired state.
6868
```js
6969
const [ popup ] = await Promise.all([
7070
page.waitForEvent('popup'),
@@ -76,7 +76,7 @@ await popup.evaluate(() => window.globalVariableInitializedByOnLoadHandler);
7676

7777
### Unusual client-side redirects
7878

79-
Usually, the client-side redirect happens before the `load` event, and `page.goto()` method automatically waits for the redirect. However, when redirecting from a link click or after the `load` event, it would be easier to explicitly [`waitForNavigation()`](#pagewaitfornavigationoptions) to a specific url.
79+
Usually, the client-side redirect happens before the `load` event, and `page.goto()` method automatically waits for the redirect. However, when redirecting from a link click or after the `load` event, it would be easier to explicitly [`waitForNavigation()`](api.md#pagewaitfornavigationoptions) to a specific url.
8080
```js
8181
await Promise.all([
8282
page.waitForNavigation({ url: '**/login' }),
@@ -88,7 +88,7 @@ Notice the `Promise.all` to click and wait for navigation. Awaiting these method
8888

8989
### Click triggers navigation after a timeout
9090

91-
When `onclick` handler triggers a navigation from a `setTimeout`, use an explicit [`waitForNavigation()`](#pagewaitfornavigationoptions) call as a last resort.
91+
When `onclick` handler triggers a navigation from a `setTimeout`, use an explicit [`waitForNavigation()`](api.md#pagewaitfornavigationoptions) call as a last resort.
9292
```js
9393
await Promise.all([
9494
page.waitForNavigation(), // Waits for the next navigation.
@@ -108,7 +108,7 @@ await page.waitForFunction(() => window.amILoadedYet());
108108
await page.screenshot();
109109
```
110110

111-
When clicking on a button triggers some asynchronous processing, issues a couple GET requests and pushes a new history state multiple times, explicit [`waitForNavigation()`](#pagewaitfornavigationoptions) to a specific url is the most reliable option.
111+
When clicking on a button triggers some asynchronous processing, issues a couple GET requests and pushes a new history state multiple times, explicit [`waitForNavigation()`](api.md#pagewaitfornavigationoptions) to a specific url is the most reliable option.
112112
```js
113113
await Promise.all([
114114
page.waitForNavigation({ url: '**/invoice#processed' }),

utils/doclint/Source.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ class Source {
121121
* @return {!Promise<!Array<!Source>>}
122122
*/
123123
static async readdir(dirPath, extension = '') {
124-
const filePaths = (await recursiveReadDir(dirPath)).filter(fileName => fileName.endsWith(extension));
124+
extension = extension.toLowerCase();
125+
const filePaths = (await recursiveReadDir(dirPath)).filter(fileName => fileName.toLowerCase().endsWith(extension));
125126
return Promise.all(filePaths.map(filePath => Source.readFile(filePath)));
126127
}
127128
}

utils/doclint/cli.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const playwright = require('../../index.js');
1919
const path = require('path');
2020
const Source = require('./Source');
21+
const Message = require('./Message');
2122

2223
const {spawnSync} = require('child_process');
2324

@@ -44,8 +45,8 @@ async function run() {
4445
const readme = await Source.readFile(path.join(PROJECT_DIR, 'README.md'));
4546
const contributing = await Source.readFile(path.join(PROJECT_DIR, 'CONTRIBUTING.md'));
4647
const api = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'api.md'));
47-
const troubleshooting = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'troubleshooting.md'));
48-
const mdSources = [readme, api, contributing, troubleshooting];
48+
const docs = await Source.readdir(path.join(PROJECT_DIR, 'docs'), '.md');
49+
const mdSources = [readme, api, contributing, ...docs];
4950

5051
const preprocessor = require('./preprocessor');
5152
const browserVersions = await getBrowserVersions();
@@ -54,13 +55,15 @@ async function run() {
5455
chromiumVersion: browserVersions.chromium,
5556
firefoxVersion: browserVersions.firefox,
5657
})));
57-
messages.push(...preprocessor.ensureInternalLinksAreValid([api]));
58+
messages.push(...preprocessor.autocorrectInvalidLinks(PROJECT_DIR, mdSources, getRepositoryFiles()));
59+
for (const source of mdSources.filter(source => source.hasUpdatedText()))
60+
messages.push(Message.warning(`WARN: updated ${source.projectPath()}`));
5861

5962
const browser = await playwright.chromium.launch();
6063
const page = await browser.newPage();
6164
const checkPublicAPI = require('./check_public_api');
6265
const jsSources = await Source.readdir(path.join(PROJECT_DIR, 'src'));
63-
messages.push(...await checkPublicAPI(page, mdSources, jsSources));
66+
messages.push(...await checkPublicAPI(page, [api], jsSources));
6467
await browser.close();
6568

6669
for (const source of mdSources) {
@@ -126,6 +129,11 @@ async function getChromeVersion() {
126129
return version.trim().split(' ').pop();
127130
}
128131

132+
function getRepositoryFiles() {
133+
const out = spawnSync('git', ['ls-files'], {cwd: PROJECT_DIR});
134+
return out.stdout.toString().trim().split('\n').map(file => path.join(PROJECT_DIR, file));
135+
}
136+
129137
async function getFirefoxVersion() {
130138
const isWin = os.platform() === 'win32' || os.platform() === 'cygwin';
131139
const out = spawnSync(playwright.firefox.executablePath(), [isWin ? '/version' : '--version'], undefined);

0 commit comments

Comments
 (0)