-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
51 lines (42 loc) · 1.56 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* eslint-env node, mocha */
const assert = require('assert');
const puppeteer = require('puppeteer-extra');
const pluginProxy = require('../src');
const config = require('./config');
const IP_API_SERVICE = 'https://api.myip.com/';
describe('PuppeteerExtraPluginProxy', () => {
// reset the plugins to a clean slate for each test
beforeEach(() => (puppeteer._plugins = []))
context('without credentials', () => {
it('works', async () => {
puppeteer.use(pluginProxy(config.withoutCredentials));
const browser = await puppeteer.launch();
const page = await browser.newPage();
try {
const response = await page.goto(IP_API_SERVICE, {waitUntil: 'domcontentloaded'});
const body = JSON.parse(await response.text());
assert.equal(body.ip, config.withoutCredentials._expectedAddress, `Unexpected IP ${body.ip}`);
} catch (e) {
browser.close();
throw e
}
browser.close();
}).timeout(10000);
});
context('with credentials', () => {
it('works', async () => {
puppeteer.use(pluginProxy(config.withCredentials));
const browser = await puppeteer.launch();
const page = await browser.newPage();
try {
const response = await page.goto(IP_API_SERVICE, {waitUntil: 'domcontentloaded'});
const body = JSON.parse(await response.text());
assert.equal(body.ip, config.withCredentials._expectedAddress, `Unexpected IP ${body.ip}`);
} catch (e) {
browser.close();
throw e
}
browser.close();
}).timeout(10000);
});
});