Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit 2873ca1

Browse files
committed
feat: use eslint-config-checkly
1 parent 4ca54fb commit 2873ca1

27 files changed

+2893
-1232
lines changed

.eslintrc.js

-23
This file was deleted.

1. basics/download_upload.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ const { promisify } = require('util')
1313
const readFileAsync = promisify(fs.readFile)
1414
const writeFileAsync = promisify(fs.writeFile);
1515
(async () => {
16-
const browser = await puppeteer.launch({});
17-
const page = await browser.newPage();
18-
await page.setViewport({ width: 1200, height: 800 });
19-
20-
await page.goto("https://checklyhq.com/");
21-
const imageHref = await page.evaluate((sel) => {
22-
return document.querySelector(sel).getAttribute('src').replace('/', '');
23-
}, '.hero-image');
24-
25-
const viewSource = await page.goto("https://checklyhq.com/" + imageHref);
26-
const buffer = await viewSource.buffer()
27-
await writeFileAsync(path.join(__dirname, "checkly.png"), buffer)
28-
console.log("The file was saved!")
16+
const browser = await puppeteer.launch({})
17+
const page = await browser.newPage()
18+
await page.setViewport({ width: 1200, height: 800 })
2919

30-
await readFileAsync(path.join(__dirname, 'checkly.png'))
31-
console.log("The file was read!")
32-
browser.close()
20+
await page.goto('https://checklyhq.com/')
21+
const imageHref = await page.evaluate((sel) => {
22+
return document.querySelector(sel).getAttribute('src').replace('/', '')
23+
}, '.hero-image')
24+
25+
const viewSource = await page.goto('https://checklyhq.com/' + imageHref)
26+
const buffer = await viewSource.buffer()
27+
await writeFileAsync(path.join(__dirname, 'checkly.png'), buffer)
28+
console.log('The file was saved!')
29+
30+
await readFileAsync(path.join(__dirname, 'checkly.png'))
31+
console.log('The file was read!')
32+
browser.close()
3333
})()

1. basics/forms.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const puppeteer = require('puppeteer');
1717

1818
const radios = await page.$$eval('input[name="exampleRadios"]', inputs => { return inputs.map(input => input.value) })
1919
console.log('Radio values:', radios)
20-
20+
2121
await page.goto('https://getbootstrap.com/docs/4.3/components/forms/#select-menu')
2222

23-
const selectOptions = await page.$$eval('.bd-example > select.custom-select.custom-select-lg.mb-3 > option', options => { return options.map(option => option.value ) })
23+
const selectOptions = await page.$$eval('.bd-example > select.custom-select.custom-select-lg.mb-3 > option', options => { return options.map(option => option.value) })
2424
console.log(selectOptions)
2525

2626
await browser.close()

1. basics/get_list_of_links.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const puppeteer = require('puppeteer');
1111
await page.tracing.start({
1212
path: 'trace.json',
1313
categories: ['devtools.timeline']
14-
})
14+
})
1515
await page.goto('https://news.ycombinator.com/news')
1616

1717
// execute standard javascript in the context of the page.
1818
const stories = await page.$$eval('a.storylink', anchors => { return anchors.map(anchor => anchor.textContent).slice(0, 10) })
1919
console.log(stories)
20-
await page.tracing.stop();
20+
await page.tracing.stop()
2121
await browser.close()
2222
})()

1. basics/location_faker.js

+29-29
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,38 @@
77
const puppeteer = require('puppeteer');
88

99
(async () => {
10-
const browser = await puppeteer.launch();
11-
const screenshotPath = 'location.png';
12-
let url = 'https://developers.google.com/maps/documentation/javascript/examples/map-geolocation';
10+
const browser = await puppeteer.launch()
11+
const screenshotPath = 'location.png'
12+
const url = 'https://developers.google.com/maps/documentation/javascript/examples/map-geolocation'
1313

14-
//Firstly, we need to override the permissions
15-
//so we don't have to click "Allow Location Access"
16-
const context = browser.defaultBrowserContext();
17-
await context.overridePermissions(url, ['geolocation']);
14+
// Firstly, we need to override the permissions
15+
// so we don't have to click "Allow Location Access"
16+
const context = browser.defaultBrowserContext()
17+
await context.overridePermissions(url, ['geolocation'])
1818

19-
const page = await browser.newPage();
19+
const page = await browser.newPage()
2020

21-
//whenever the location is requested, it will be set to our given lattitude, longitude
22-
await page.evaluateOnNewDocument(function () {
23-
navigator.geolocation.getCurrentPosition = function (cb) {
24-
setTimeout(() => {
25-
cb({
26-
'coords': {
27-
accuracy: 21,
28-
altitude: null,
29-
altitudeAccuracy: null,
30-
heading: null,
31-
latitude: 0.62896,
32-
longitude: 77.3111303,
33-
speed: null
34-
}
35-
})
36-
}, 1000)
37-
}
38-
});
21+
// whenever the location is requested, it will be set to our given lattitude, longitude
22+
await page.evaluateOnNewDocument(function () {
23+
navigator.geolocation.getCurrentPosition = function (cb) {
24+
setTimeout(() => {
25+
cb({
26+
coords: {
27+
accuracy: 21,
28+
altitude: null,
29+
altitudeAccuracy: null,
30+
heading: null,
31+
latitude: 0.62896,
32+
longitude: 77.3111303,
33+
speed: null
34+
}
35+
})
36+
}, 1000)
37+
}
38+
})
3939

40-
await page.goto(url,{waitUntil:'networkidle2'});
41-
await page.screenshot({ path: screenshotPath });
40+
await page.goto(url, { waitUntil: 'networkidle2' })
41+
await page.screenshot({ path: screenshotPath })
4242

43-
await browser.close()
43+
await browser.close()
4444
})()

1. basics/pdf.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ const puppeteer = require('puppeteer');
1212
const browser = await puppeteer.launch()
1313
const page = await browser.newPage()
1414

15-
//1. Create PDF from URL
15+
// 1. Create PDF from URL
1616
await page.goto('https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pdf')
1717
await page.pdf({ path: 'api.pdf', format: 'A4' })
1818

19-
//2. Create PDF from static HTML
19+
// 2. Create PDF from static HTML
2020
const htmlContent = `<body>
2121
<h1>An example static HTML to PDF</h1>
22-
</body>`;
23-
await page.setContent(htmlContent);
22+
</body>`
23+
await page.setContent(htmlContent)
2424
await page.pdf({ path: 'html.pdf', format: 'A4' })
2525

2626
await browser.close()

1. basics/request_interception.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
/**
33
* @name request interception
44
*
@@ -13,18 +13,16 @@ const puppeteer = require('puppeteer');
1313
(async () => {
1414
const browser = await puppeteer.launch()
1515
const page = await browser.newPage()
16-
await page.setRequestInterception(true);
16+
await page.setRequestInterception(true)
1717
page.on('request', async (request) => {
18-
1918
if (request.resourceType() == 'image') {
20-
await request.abort();
19+
await request.abort()
2120
} else {
22-
await request.continue();
21+
await request.continue()
2322
}
24-
25-
});
23+
})
2624
await page.setViewport({ width: 1280, height: 800 })
2725
await page.goto('https://www.nytimes.com/')
2826
await page.screenshot({ path: 'nytimes.png', fullPage: true })
2927
await browser.close()
30-
})()
28+
})()

2. search/amazon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ try {
1414
await page.type('#twotabsearchtextbox', 'nyan cat pullover')
1515
await page.click('input.nav-input')
1616
await page.waitForSelector('#resultsCol')
17-
await page.screenshot({path: 'amazon_nyan_cat_pullovers_list.png'})
17+
await page.screenshot({ path: 'amazon_nyan_cat_pullovers_list.png' })
1818
await page.click('#pagnNextString')
1919
await page.waitForSelector('#resultsCol')
2020
const pullovers = await page.$$('a.a-link-normal.a-text-normal')
2121
await pullovers[2].click()
2222
await page.waitForSelector('#ppd')
23-
await page.screenshot({path: screenshot})
23+
await page.screenshot({ path: screenshot })
2424
await browser.close()
2525
console.log('See screenshot: ' + screenshot)
2626
})()

2. search/duck_duck_go.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const puppeteer = require('puppeteer')
77
(async () => {
88
const browser = await puppeteer.launch()
99
const page = await browser.newPage()
10-
await page.goto('https://duckduckgo.com/', { waitUntil: 'networkidle2' })
10+
await page.goto('https://duckduckgo.com/', { waitUntil: 'networkidle2' })
1111
await page.type('#search_form_input_homepage', 'Puppeteer')
1212
const searchValue = await page.$eval('#search_form_input_homepage', el => el.value)
1313
console.log(searchValue)

2. search/youtube.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ try {
1414
await page.type('#search', 'Fleetwood Mac Dreams')
1515
await page.click('button#search-icon-legacy')
1616
await page.waitForSelector('ytd-thumbnail.ytd-video-renderer')
17-
await page.screenshot({path: 'youtube_fm_dreams_list.png'})
17+
await page.screenshot({ path: 'youtube_fm_dreams_list.png' })
1818
const videos = await page.$$('ytd-thumbnail.ytd-video-renderer')
1919
await videos[2].click()
2020
await page.waitForSelector('.html5-video-container')

3. login/github.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const puppeteer = require('puppeteer')
99
const screenshot = 'github.png';
1010
(async () => {
11-
const browser = await puppeteer.launch({headless: true})
11+
const browser = await puppeteer.launch({ headless: true })
1212
const page = await browser.newPage()
1313
await page.goto('https://github.com/login')
1414
await page.type('#login_field', process.env.GITHUB_USER)

3. login/google_social.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66
*
77
*/
88
const puppeteer = require('puppeteer');
9-
(async () => {
10-
const browser = await puppeteer.launch({ headless: false })
11-
const page = await browser.newPage()
9+
(async () => {
10+
const browser = await puppeteer.launch({ headless: false })
11+
const page = await browser.newPage()
1212

13-
await page.setViewport({ width: 1280, height: 800 })
14-
await page.goto('https://app.checklyhq.com/login')
13+
await page.setViewport({ width: 1280, height: 800 })
14+
await page.goto('https://app.checklyhq.com/login')
1515

16-
const navigationPromise = page.waitForNavigation()
16+
const navigationPromise = page.waitForNavigation()
1717

18-
await page.waitForSelector('.google-button')
19-
await page.click('.google-button')
18+
await page.waitForSelector('.google-button')
19+
await page.click('.google-button')
2020

21-
await navigationPromise
22-
await page.waitForSelector('input[type="email"]')
23-
await page.type('input[type="email"]', process.env.GOOGLE_USER)
24-
await page.click('#identifierNext')
21+
await navigationPromise
22+
await page.waitForSelector('input[type="email"]')
23+
await page.type('input[type="email"]', process.env.GOOGLE_USER)
24+
await page.click('#identifierNext')
2525

26-
await page.waitForSelector('input[type="password"]', { visible: true })
27-
await page.type('input[type="password"]',process.env.GOOGLE_PWD)
26+
await page.waitForSelector('input[type="password"]', { visible: true })
27+
await page.type('input[type="password"]', process.env.GOOGLE_PWD)
2828

29-
await page.waitForSelector('#passwordNext', { visible: true })
30-
await page.click('#passwordNext')
29+
await page.waitForSelector('#passwordNext', { visible: true })
30+
await page.click('#passwordNext')
3131

32-
await navigationPromise
32+
await navigationPromise
3333

34-
await browser.close()
34+
await browser.close()
3535
})()

0 commit comments

Comments
 (0)