Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): remove emulateMedia method #6084

Merged
merged 1 commit into from Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions docs/api.md
Expand Up @@ -115,7 +115,6 @@
* [page.coverage](#pagecoverage)
* [page.deleteCookie(...cookies)](#pagedeletecookiecookies)
* [page.emulate(options)](#pageemulateoptions)
* [page.emulateMedia(type)](#pageemulatemediatype)
* [page.emulateMediaFeatures(features)](#pageemulatemediafeaturesfeatures)
* [page.emulateMediaType(type)](#pageemulatemediatypetype)
* [page.emulateTimezone(timezoneId)](#pageemulatetimezonetimezoneid)
Expand Down Expand Up @@ -1334,12 +1333,6 @@ const iPhone = puppeteer.devices['iPhone 6'];

List of all available devices is available in the source code: [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts).

#### page.emulateMedia(type)
- `type` <?[string]> Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables CSS media emulation.
- returns: <[Promise]>

**Note:** This method is deprecated, and only kept around as an alias for backwards compatibility. Use [`page.emulateMediaType(type)`](#pageemulatemediatypetype) instead.

#### page.emulateMediaFeatures(features)
- `features` <?[Array]<[Object]>> Given an array of media feature objects, emulates CSS media features on the page. Each media feature object must have the following properties:
- `name` <[string]> The CSS media feature name. Supported names are `'prefers-colors-scheme'` and `'prefers-reduced-motion'`.
Expand Down
5 changes: 0 additions & 5 deletions src/initialize.ts
Expand Up @@ -20,7 +20,6 @@
const api = require('./api');

import { helper } from './common/helper';
import { Page } from './common/Page';
import { Puppeteer } from './common/Puppeteer';

interface InitOptions {
Expand All @@ -42,10 +41,6 @@ export const initializePuppeteer = (options: InitOptions): Puppeteer => {
helper.installAsyncStackHooks(api[className]);
}

// Expose alias for deprecated method.
// @ts-expect-error emulateMedia does not exist error
Page.prototype.emulateMedia = Page.prototype.emulateMediaType;

let preferredRevision = packageJson.puppeteer.chromium_revision;
const isPuppeteerCore = packageJson.name === 'puppeteer-core';
// puppeteer-core ignores environment variables
Expand Down
48 changes: 0 additions & 48 deletions test/emulation.spec.ts
Expand Up @@ -146,55 +146,7 @@ describe('Emulation', () => {
});
});

describe('Page.emulateMedia [deprecated]', function () {
/* emulateMedia is deprecated in favour of emulateMediaType but we
* don't want to remove it from Puppeteer just yet. We can't check
* that emulateMedia === emulateMediaType because when running tests
* with COVERAGE=1 the methods get rewritten. So instead we
* duplicate the tests for emulateMediaType and ensure they pass
* when calling the deprecated emulateMedia method.
*
* If you update these tests, you should update emulateMediaType's
* tests, and vice-versa.
*/
itFailsFirefox('should work', async () => {
const { page } = getTestState();

expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(
true
);
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(
false
);
// @ts-expect-error this method is deprecated so we don't declare it
await page.emulateMedia('print');
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(
false
);
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(true);
// @ts-expect-error this method is deprecated so we don't declare it
await page.emulateMedia(null);
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(
true
);
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(
false
);
});
it('should throw in case of bad argument', async () => {
const { page } = getTestState();

let error = null;
// @ts-expect-error this method is deprecated so we don't declare it
await page.emulateMedia('bad').catch((error_) => (error = error_));
expect(error.message).toBe('Unsupported media type: bad');
});
});

describe('Page.emulateMediaType', function () {
/* NOTE! Updating these tests? Update the emulateMedia tests above
* too (and see the big comment for why we have these duplicated).
*/
itFailsFirefox('should work', async () => {
const { page } = getTestState();

Expand Down
17 changes: 0 additions & 17 deletions utils/doclint/check_public_api/index.js
Expand Up @@ -172,14 +172,6 @@ function checkDuplicates(doc) {
return errors;
}

const expectedNonExistingMethods = new Map([
/* Expected to be missing as the method is deprecated
* and we alias it to Page.prototype.emulateMediaType in index.js
* which is not checked by DocLint
*/
['Page', new Set(['emulateMedia'])],
]);

// All the methods from our EventEmitter that we don't document for each subclass.
const EVENT_LISTENER_METHODS = new Set([
'emit',
Expand Down Expand Up @@ -226,15 +218,6 @@ function compareDocumentations(actual, expected) {
const methodDiff = diff(actualMethods, expectedMethods);

for (const methodName of methodDiff.extra) {
const nonExistingMethodsForClass = expectedNonExistingMethods.get(
className
);
if (
nonExistingMethodsForClass &&
nonExistingMethodsForClass.has(methodName)
)
continue;

errors.push(`Non-existing method found: ${className}.${methodName}()`);
}

Expand Down