Skip to content

Commit

Permalink
docs: Use Promises API of fs module in Puppeteer.md (#11541)
Browse files Browse the repository at this point in the history
  • Loading branch information
munierujp authored Jun 14, 2021
1 parent 384d793 commit 8695c93
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions docs/Puppeteer.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const fs = require('fs');
const { writeFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
Expand All @@ -71,15 +71,15 @@ module.exports = async function () {

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```

Then we need a custom Test Environment for puppeteer

```js
// puppeteer_environment.js
const fs = require('fs');
const { readFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const puppeteer = require('puppeteer');
Expand All @@ -95,7 +95,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
async setup() {
await super.setup();
// get the wsEndpoint
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
const wsEndpoint = await readFile(path.join(DIR, 'wsEndpoint'), 'utf8');
if (!wsEndpoint) {
throw new Error('wsEndpoint not found');
}
Expand Down
8 changes: 4 additions & 4 deletions website/versioned_docs/version-25.x/Puppeteer.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const fs = require('fs');
const { writeFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
Expand All @@ -71,15 +71,15 @@ module.exports = async function () {

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```

Then we need a custom Test Environment for puppeteer

```js
// puppeteer_environment.js
const fs = require('fs');
const { readFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const puppeteer = require('puppeteer');
Expand All @@ -95,7 +95,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
async setup() {
await super.setup();
// get the wsEndpoint
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
const wsEndpoint = await readFile(path.join(DIR, 'wsEndpoint'), 'utf8');
if (!wsEndpoint) {
throw new Error('wsEndpoint not found');
}
Expand Down
8 changes: 4 additions & 4 deletions website/versioned_docs/version-26.x/Puppeteer.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const fs = require('fs');
const { writeFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
Expand All @@ -71,15 +71,15 @@ module.exports = async function () {

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```

Then we need a custom Test Environment for puppeteer

```js
// puppeteer_environment.js
const fs = require('fs');
const { readFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const puppeteer = require('puppeteer');
Expand All @@ -95,7 +95,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
async setup() {
await super.setup();
// get the wsEndpoint
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
const wsEndpoint = await readFile(path.join(DIR, 'wsEndpoint'), 'utf8');
if (!wsEndpoint) {
throw new Error('wsEndpoint not found');
}
Expand Down
8 changes: 4 additions & 4 deletions website/versioned_docs/version-27.0/Puppeteer.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const fs = require('fs');
const { writeFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
Expand All @@ -71,15 +71,15 @@ module.exports = async function () {

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```

Then we need a custom Test Environment for puppeteer

```js
// puppeteer_environment.js
const fs = require('fs');
const { readFile } = require('fs').promises;
const os = require('os');
const path = require('path');
const puppeteer = require('puppeteer');
Expand All @@ -95,7 +95,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
async setup() {
await super.setup();
// get the wsEndpoint
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
const wsEndpoint = await readFile(path.join(DIR, 'wsEndpoint'), 'utf8');
if (!wsEndpoint) {
throw new Error('wsEndpoint not found');
}
Expand Down

0 comments on commit 8695c93

Please sign in to comment.