fix: throw if quality=0 is passed for png screenshot (#4812)
This commit is contained in:
parent
e7ee426202
commit
8d4c46ac19
|
|
@ -205,7 +205,7 @@ function validateScreenshotOptions(options: types.ScreenshotOptions): 'png' | 'j
|
||||||
if (!format)
|
if (!format)
|
||||||
format = 'png';
|
format = 'png';
|
||||||
|
|
||||||
if (options.quality) {
|
if (options.quality !== undefined) {
|
||||||
assert(format === 'jpeg', 'options.quality is unsupported for the ' + format + ' screenshots');
|
assert(format === 'jpeg', 'options.quality is unsupported for the ' + format + ' screenshots');
|
||||||
assert(typeof options.quality === 'number', 'Expected options.quality to be a number but found ' + (typeof options.quality));
|
assert(typeof options.quality === 'number', 'Expected options.quality to be a number but found ' + (typeof options.quality));
|
||||||
assert(Number.isInteger(options.quality), 'Expected options.quality to be an integer');
|
assert(Number.isInteger(options.quality), 'Expected options.quality to be an integer');
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,16 @@ describe('page screenshot', (suite, { browserName, headful }) => {
|
||||||
expect(error.message).toContain('path: unsupported mime type "text/plain"');
|
expect(error.message).toContain('path: unsupported mime type "text/plain"');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('quality option should throw for png', async ({page}) => {
|
||||||
|
const error = await page.screenshot({ quality: 10 }).catch(e => e);
|
||||||
|
expect(error.message).toContain('options.quality is unsupported for the png');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('zero quality option should throw for png', async ({page}) => {
|
||||||
|
const error = await page.screenshot({ quality: 0, type: 'png' }).catch(e => e);
|
||||||
|
expect(error.message).toContain('options.quality is unsupported for the png');
|
||||||
|
});
|
||||||
|
|
||||||
it('should prefer type over extension', async ({page, testInfo}) => {
|
it('should prefer type over extension', async ({page, testInfo}) => {
|
||||||
const outputPath = testInfo.outputPath('file.png');
|
const outputPath = testInfo.outputPath('file.png');
|
||||||
const buffer = await page.screenshot({ path: outputPath, type: 'jpeg' });
|
const buffer = await page.screenshot({ path: outputPath, type: 'jpeg' });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue