feat(puppeteer): introduce puppeteer.errors and puppeteer.devices (#4312)

These getters are introduced as a more convenient substitute for
a `require('puppeteer/Errors')` and
`require('puppeteer/DeviceDescriptors')`.

This way we can make cross-browser story nicer - a single require
of `puppeteer` or `puppeteer-firefox` fully defines Puppeteer
environment.
This commit is contained in:
Andrey Lushnikov
2019-04-19 15:33:06 -07:00
committed by GitHub
parent dde55b0257
commit e3abb0aa32
20 changed files with 1836 additions and 1708 deletions

View File

@@ -24,7 +24,7 @@ const statAsync = helper.promisify(fs.stat);
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
const utils = require('./utils');
module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, puppeteer, CHROME}) {
module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, puppeteer, CHROME, puppeteerPath}) {
const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner;
const {it, fit, xit, it_fails_ffox} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
@@ -339,6 +339,17 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
});
});
describe('Top-level requires', function() {
it('should require top-level Errors', async() => {
const Errors = require(path.join(puppeteerPath, '/Errors'));
expect(Errors.TimeoutError).toBe(puppeteer.errors.TimeoutError);
});
it('should require top-level DeviceDescriptors', async() => {
const Devices = require(path.join(puppeteerPath, '/DeviceDescriptors'));
expect(Devices['iPhone 6']).toBe(puppeteer.devices['iPhone 6']);
});
});
describe('Browser target events', function() {
it('should work', async({server}) => {
const browser = await puppeteer.launch(defaultBrowserOptions);