2021-04-30 17:40:22 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-05-11 23:21:01 +03:00
|
|
|
import { expect, contextTest as test, browserTest } from './config/browserTest';
|
2021-10-19 19:28:02 +03:00
|
|
|
import { ZipFileSystem } from '../packages/playwright-core/lib/utils/vfs';
|
2021-05-11 23:21:01 +03:00
|
|
|
import jpeg from 'jpeg-js';
|
2021-04-30 17:40:22 +03:00
|
|
|
|
2021-08-20 05:09:19 +03:00
|
|
|
test.skip(({ trace }) => !!trace);
|
|
|
|
|
2021-08-03 23:05:58 +03:00
|
|
|
test('should collect trace with resources, but no js', async ({ context, page, server }, testInfo) => {
|
2021-07-15 04:43:51 +03:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
2021-08-03 23:05:58 +03:00
|
|
|
await page.goto(server.PREFIX + '/frames/frame.html');
|
2021-04-30 17:40:22 +03:00
|
|
|
await page.setContent('<button>Click</button>');
|
|
|
|
await page.click('"Click"');
|
2021-09-07 23:48:30 +03:00
|
|
|
await page.mouse.move(20, 20);
|
|
|
|
await page.mouse.dblclick(30, 30);
|
|
|
|
await page.keyboard.insertText('abc');
|
2021-06-15 02:01:18 +03:00
|
|
|
await page.waitForTimeout(2000); // Give it some time to produce screenshots.
|
2021-04-30 17:40:22 +03:00
|
|
|
await page.close();
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
2021-04-30 17:40:22 +03:00
|
|
|
|
|
|
|
const { events } = await parseTrace(testInfo.outputPath('trace.zip'));
|
2021-05-14 08:36:34 +03:00
|
|
|
expect(events[0].type).toBe('context-options');
|
2021-04-30 17:40:22 +03:00
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.goto')).toBeTruthy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.setContent')).toBeTruthy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.click')).toBeTruthy();
|
2021-09-07 23:48:30 +03:00
|
|
|
expect(events.find(e => e.metadata?.apiName === 'mouse.move')).toBeTruthy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'mouse.dblclick')).toBeTruthy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'keyboard.insertText')).toBeTruthy();
|
2021-04-30 17:40:22 +03:00
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.close')).toBeTruthy();
|
|
|
|
|
|
|
|
expect(events.some(e => e.type === 'frame-snapshot')).toBeTruthy();
|
2021-05-08 21:35:36 +03:00
|
|
|
expect(events.some(e => e.type === 'screencast-frame')).toBeTruthy();
|
2021-09-08 01:23:13 +03:00
|
|
|
const style = events.find(e => e.type === 'resource-snapshot' && e.snapshot.request.url.endsWith('style.css'));
|
|
|
|
expect(style).toBeTruthy();
|
|
|
|
expect(style.snapshot.response.content._sha1).toBeTruthy();
|
|
|
|
const script = events.find(e => e.type === 'resource-snapshot' && e.snapshot.request.url.endsWith('script.js'));
|
|
|
|
expect(script).toBeTruthy();
|
|
|
|
expect(script.snapshot.response.content._sha1).toBe(undefined);
|
2021-04-30 17:40:22 +03:00
|
|
|
});
|
|
|
|
|
2021-06-05 00:52:16 +03:00
|
|
|
test('should not collect snapshots by default', async ({ context, page, server }, testInfo) => {
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.start();
|
2021-04-30 17:40:22 +03:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.setContent('<button>Click</button>');
|
|
|
|
await page.click('"Click"');
|
|
|
|
await page.close();
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
2021-04-30 17:40:22 +03:00
|
|
|
|
|
|
|
const { events } = await parseTrace(testInfo.outputPath('trace.zip'));
|
|
|
|
expect(events.some(e => e.type === 'frame-snapshot')).toBeFalsy();
|
|
|
|
expect(events.some(e => e.type === 'resource-snapshot')).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2021-05-29 04:20:49 +03:00
|
|
|
test('should exclude internal pages', async ({ browserName, context, page, server }, testInfo) => {
|
|
|
|
test.fixme(true, 'https://github.com/microsoft/playwright/issues/6743');
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.start();
|
2021-05-29 04:20:49 +03:00
|
|
|
await context.storageState();
|
|
|
|
await page.close();
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
2021-05-29 04:20:49 +03:00
|
|
|
|
|
|
|
const trace = await parseTrace(testInfo.outputPath('trace.zip'));
|
|
|
|
const pageIds = new Set();
|
|
|
|
trace.events.forEach(e => {
|
|
|
|
const pageId = e.metadata?.pageId;
|
|
|
|
if (pageId)
|
|
|
|
pageIds.add(pageId);
|
|
|
|
});
|
|
|
|
expect(pageIds.size).toBe(1);
|
|
|
|
});
|
|
|
|
|
2021-04-30 17:40:22 +03:00
|
|
|
test('should collect two traces', async ({ context, page, server }, testInfo) => {
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
2021-04-30 17:40:22 +03:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.setContent('<button>Click</button>');
|
|
|
|
await page.click('"Click"');
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.stop({ path: testInfo.outputPath('trace1.zip') });
|
2021-04-30 17:40:22 +03:00
|
|
|
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
2021-04-30 17:40:22 +03:00
|
|
|
await page.dblclick('"Click"');
|
|
|
|
await page.close();
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.stop({ path: testInfo.outputPath('trace2.zip') });
|
2021-04-30 17:40:22 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
const { events } = await parseTrace(testInfo.outputPath('trace1.zip'));
|
2021-05-14 08:36:34 +03:00
|
|
|
expect(events[0].type).toBe('context-options');
|
2021-04-30 17:40:22 +03:00
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.goto')).toBeTruthy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.setContent')).toBeTruthy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.click')).toBeTruthy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.dblclick')).toBeFalsy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.close')).toBeFalsy();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const { events } = await parseTrace(testInfo.outputPath('trace2.zip'));
|
2021-05-14 08:36:34 +03:00
|
|
|
expect(events[0].type).toBe('context-options');
|
2021-04-30 17:40:22 +03:00
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.goto')).toBeFalsy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.setContent')).toBeFalsy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.click')).toBeFalsy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.dblclick')).toBeTruthy();
|
|
|
|
expect(events.find(e => e.metadata?.apiName === 'page.close')).toBeTruthy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-11 08:24:04 +03:00
|
|
|
test('should not stall on dialogs', async ({ page, context, server }) => {
|
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
|
|
|
|
page.on('dialog', async dialog => {
|
|
|
|
await dialog.accept();
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.evaluate(() => {
|
|
|
|
confirm('are you sure');
|
|
|
|
});
|
|
|
|
await context.tracing.stop();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2021-05-11 23:21:01 +03:00
|
|
|
for (const params of [
|
|
|
|
{
|
|
|
|
id: 'fit',
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
2021-05-12 18:35:19 +03:00
|
|
|
},
|
|
|
|
{
|
2021-05-11 23:21:01 +03:00
|
|
|
id: 'crop',
|
|
|
|
width: 400, // Less than 450 to test firefox
|
|
|
|
height: 800,
|
2021-05-12 18:35:19 +03:00
|
|
|
},
|
|
|
|
{
|
2021-05-11 23:21:01 +03:00
|
|
|
id: 'scale',
|
|
|
|
width: 1024,
|
|
|
|
height: 768,
|
2021-05-12 18:35:19 +03:00
|
|
|
}
|
|
|
|
]) {
|
2021-06-04 00:33:33 +03:00
|
|
|
browserTest(`should produce screencast frames ${params.id}`, async ({ video, contextFactory, browserName, platform, headless }, testInfo) => {
|
2021-05-11 23:21:01 +03:00
|
|
|
browserTest.fixme(browserName === 'chromium' && video, 'Same screencast resolution conflicts');
|
2021-06-04 00:33:33 +03:00
|
|
|
browserTest.fixme(browserName === 'chromium' && !headless, 'Chromium screencast on headed has a min width issue');
|
2021-05-12 18:35:19 +03:00
|
|
|
browserTest.fixme(params.id === 'fit' && browserName === 'chromium' && platform === 'darwin', 'High DPI maxes image at 600x600');
|
2021-05-17 22:06:18 +03:00
|
|
|
browserTest.fixme(params.id === 'fit' && browserName === 'webkit' && platform === 'linux', 'Image size is flaky');
|
2021-05-12 18:35:19 +03:00
|
|
|
|
2021-05-11 23:21:01 +03:00
|
|
|
const scale = Math.min(800 / params.width, 600 / params.height, 1);
|
|
|
|
const previewWidth = params.width * scale;
|
|
|
|
const previewHeight = params.height * scale;
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
const context = await contextFactory({ viewport: { width: params.width, height: params.height } });
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
2021-05-11 23:21:01 +03:00
|
|
|
const page = await context.newPage();
|
|
|
|
// Make sure we have a chance to paint.
|
2021-05-12 18:35:19 +03:00
|
|
|
for (let i = 0; i < 10; ++i) {
|
|
|
|
await page.setContent('<body style="box-sizing: border-box; width: 100%; height: 100%; margin:0; background: red; border: 50px solid blue"></body>');
|
2021-05-11 23:21:01 +03:00
|
|
|
await page.evaluate(() => new Promise(requestAnimationFrame));
|
2021-05-12 18:35:19 +03:00
|
|
|
}
|
2021-06-02 20:04:25 +03:00
|
|
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
2021-05-11 23:21:01 +03:00
|
|
|
|
|
|
|
const { events, resources } = await parseTrace(testInfo.outputPath('trace.zip'));
|
|
|
|
const frames = events.filter(e => e.type === 'screencast-frame');
|
2021-05-12 18:35:19 +03:00
|
|
|
|
|
|
|
// Check all frame sizes.
|
2021-05-11 23:21:01 +03:00
|
|
|
for (const frame of frames) {
|
|
|
|
expect(frame.width).toBe(params.width);
|
|
|
|
expect(frame.height).toBe(params.height);
|
|
|
|
const buffer = resources.get('resources/' + frame.sha1);
|
|
|
|
const image = jpeg.decode(buffer);
|
|
|
|
expect(image.width).toBe(previewWidth);
|
|
|
|
expect(image.height).toBe(previewHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
const frame = frames[frames.length - 1]; // pick last frame.
|
|
|
|
const buffer = resources.get('resources/' + frame.sha1);
|
|
|
|
const image = jpeg.decode(buffer);
|
|
|
|
expect(image.data.byteLength).toBe(previewWidth * previewHeight * 4);
|
|
|
|
expectRed(image.data, previewWidth * previewHeight * 4 / 2 + previewWidth * 4 / 2); // center is red
|
|
|
|
expectBlue(image.data, previewWidth * 5 * 4 + previewWidth * 4 / 2); // top
|
|
|
|
expectBlue(image.data, previewWidth * (previewHeight - 5) * 4 + previewWidth * 4 / 2); // bottom
|
|
|
|
expectBlue(image.data, previewWidth * previewHeight * 4 / 2 + 5 * 4); // left
|
|
|
|
expectBlue(image.data, previewWidth * previewHeight * 4 / 2 + (previewWidth - 5) * 4); // right
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-26 03:14:19 +03:00
|
|
|
test('should include interrupted actions', async ({ context, page, server }, testInfo) => {
|
2021-07-15 04:43:51 +03:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
2021-06-26 03:14:19 +03:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.setContent('<button>Click</button>');
|
|
|
|
page.click('"ClickNoButton"').catch(() => {});
|
|
|
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
|
|
|
await context.close();
|
|
|
|
|
|
|
|
const { events } = await parseTrace(testInfo.outputPath('trace.zip'));
|
|
|
|
const clickEvent = events.find(e => e.metadata?.apiName === 'page.click');
|
|
|
|
expect(clickEvent).toBeTruthy();
|
2021-07-03 00:33:38 +03:00
|
|
|
expect(clickEvent.metadata.error.error.message).toBe('Action was interrupted');
|
2021-06-26 03:14:19 +03:00
|
|
|
});
|
|
|
|
|
2021-09-01 03:03:31 +03:00
|
|
|
test('should throw when starting with different options', async ({ context }) => {
|
2021-08-04 02:08:06 +03:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
2021-09-01 03:03:31 +03:00
|
|
|
const error = await context.tracing.start({ screenshots: false, snapshots: false }).catch(e => e);
|
|
|
|
expect(error.message).toContain('Tracing has been already started with different options');
|
|
|
|
});
|
2021-08-04 02:08:06 +03:00
|
|
|
|
2021-09-01 03:03:31 +03:00
|
|
|
test('should throw when stopping without start', async ({ context }, testInfo) => {
|
|
|
|
const error = await context.tracing.stop({ path: testInfo.outputPath('trace.zip') }).catch(e => e);
|
|
|
|
expect(error.message).toContain('Must start tracing before stopping');
|
|
|
|
});
|
2021-08-04 02:08:06 +03:00
|
|
|
|
2021-09-01 03:03:31 +03:00
|
|
|
test('should not throw when stopping without start but not exporting', async ({ context }, testInfo) => {
|
|
|
|
await context.tracing.stop();
|
2021-08-04 02:08:06 +03:00
|
|
|
});
|
|
|
|
|
2021-09-01 03:03:31 +03:00
|
|
|
test('should work with multiple chunks', async ({ context, page, server }, testInfo) => {
|
2021-08-05 07:11:35 +03:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
|
|
|
await page.goto(server.PREFIX + '/frames/frame.html');
|
|
|
|
|
2021-09-01 03:03:31 +03:00
|
|
|
await context.tracing.startChunk();
|
2021-08-05 07:11:35 +03:00
|
|
|
await page.setContent('<button>Click</button>');
|
|
|
|
await page.click('"Click"');
|
|
|
|
page.click('"ClickNoButton"').catch(() => {});
|
2021-09-01 03:03:31 +03:00
|
|
|
await context.tracing.stopChunk({ path: testInfo.outputPath('trace.zip') });
|
2021-08-05 07:11:35 +03:00
|
|
|
|
2021-09-01 03:03:31 +03:00
|
|
|
await context.tracing.startChunk();
|
2021-08-05 07:11:35 +03:00
|
|
|
await page.hover('"Click"');
|
2021-09-01 03:03:31 +03:00
|
|
|
await context.tracing.stopChunk({ path: testInfo.outputPath('trace2.zip') });
|
2021-08-05 07:11:35 +03:00
|
|
|
|
2021-10-19 07:05:59 +03:00
|
|
|
await context.tracing.startChunk();
|
|
|
|
await page.click('"Click"');
|
|
|
|
await context.tracing.stopChunk(); // Should stop without a path.
|
|
|
|
|
2021-08-05 07:11:35 +03:00
|
|
|
const trace1 = await parseTrace(testInfo.outputPath('trace.zip'));
|
|
|
|
expect(trace1.events[0].type).toBe('context-options');
|
|
|
|
expect(trace1.events.find(e => e.metadata?.apiName === 'page.goto')).toBeFalsy();
|
|
|
|
expect(trace1.events.find(e => e.metadata?.apiName === 'page.setContent')).toBeTruthy();
|
|
|
|
expect(trace1.events.find(e => e.metadata?.apiName === 'page.click' && !!e.metadata.error)).toBeTruthy();
|
|
|
|
expect(trace1.events.find(e => e.metadata?.apiName === 'page.hover')).toBeFalsy();
|
|
|
|
expect(trace1.events.find(e => e.metadata?.apiName === 'page.click' && e.metadata?.error?.error?.message === 'Action was interrupted')).toBeTruthy();
|
|
|
|
expect(trace1.events.some(e => e.type === 'frame-snapshot')).toBeTruthy();
|
2021-08-24 23:17:58 +03:00
|
|
|
expect(trace1.events.some(e => e.type === 'resource-snapshot' && e.snapshot.request.url.endsWith('style.css'))).toBeTruthy();
|
2021-08-05 07:11:35 +03:00
|
|
|
|
|
|
|
const trace2 = await parseTrace(testInfo.outputPath('trace2.zip'));
|
|
|
|
expect(trace2.events[0].type).toBe('context-options');
|
|
|
|
expect(trace2.events.find(e => e.metadata?.apiName === 'page.goto')).toBeFalsy();
|
|
|
|
expect(trace2.events.find(e => e.metadata?.apiName === 'page.setContent')).toBeFalsy();
|
|
|
|
expect(trace2.events.find(e => e.metadata?.apiName === 'page.click')).toBeFalsy();
|
|
|
|
expect(trace2.events.find(e => e.metadata?.apiName === 'page.hover')).toBeTruthy();
|
|
|
|
expect(trace2.events.some(e => e.type === 'frame-snapshot')).toBeTruthy();
|
2021-09-01 03:03:31 +03:00
|
|
|
expect(trace2.events.some(e => e.type === 'resource-snapshot' && e.snapshot.request.url.endsWith('style.css'))).toBeTruthy();
|
2021-08-05 07:11:35 +03:00
|
|
|
});
|
2021-06-26 03:14:19 +03:00
|
|
|
|
2021-08-19 17:26:24 +03:00
|
|
|
test('should export trace concurrently to second navigation', async ({ context, page, server }, testInfo) => {
|
|
|
|
for (let timeout = 0; timeout < 200; timeout += 20) {
|
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
|
|
|
|
// Navigate to the same page to produce the same trace resources
|
|
|
|
// that might be concurrently exported.
|
|
|
|
const promise = page.goto(server.PREFIX + '/grid.html');
|
|
|
|
await page.waitForTimeout(timeout);
|
|
|
|
await Promise.all([
|
|
|
|
promise,
|
|
|
|
context.tracing.stop({ path: testInfo.outputPath('trace.zip') }),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-20 04:20:15 +03:00
|
|
|
test('should not hang for clicks that open dialogs', async ({ context, page }) => {
|
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
|
|
|
const dialogPromise = page.waitForEvent('dialog');
|
|
|
|
await page.setContent(`<div onclick='window.alert(123)'>Click me</div>`);
|
|
|
|
await page.click('div', { timeout: 2000 }).catch(() => {});
|
|
|
|
const dialog = await dialogPromise;
|
|
|
|
await dialog.dismiss();
|
|
|
|
await context.tracing.stop();
|
|
|
|
});
|
|
|
|
|
2021-04-30 17:40:22 +03:00
|
|
|
async function parseTrace(file: string): Promise<{ events: any[], resources: Map<string, Buffer> }> {
|
2021-10-08 01:49:30 +03:00
|
|
|
const zipFS = new ZipFileSystem(file);
|
2021-04-30 17:40:22 +03:00
|
|
|
const resources = new Map<string, Buffer>();
|
2021-10-08 01:49:30 +03:00
|
|
|
for (const entry of await zipFS.entries())
|
|
|
|
resources.set(entry, await zipFS.read(entry));
|
|
|
|
zipFS.close();
|
|
|
|
|
2021-08-24 02:08:09 +03:00
|
|
|
const events = [];
|
|
|
|
for (const line of resources.get('trace.trace').toString().split('\n')) {
|
|
|
|
if (line)
|
|
|
|
events.push(JSON.parse(line));
|
|
|
|
}
|
|
|
|
for (const line of resources.get('trace.network').toString().split('\n')) {
|
|
|
|
if (line)
|
|
|
|
events.push(JSON.parse(line));
|
|
|
|
}
|
2021-04-30 17:40:22 +03:00
|
|
|
return {
|
|
|
|
events,
|
|
|
|
resources,
|
|
|
|
};
|
2021-05-11 23:21:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function expectRed(pixels: Buffer, offset: number) {
|
|
|
|
const r = pixels.readUInt8(offset);
|
|
|
|
const g = pixels.readUInt8(offset + 1);
|
|
|
|
const b = pixels.readUInt8(offset + 2);
|
|
|
|
const a = pixels.readUInt8(offset + 3);
|
|
|
|
expect(r).toBeGreaterThan(200);
|
|
|
|
expect(g).toBeLessThan(70);
|
|
|
|
expect(b).toBeLessThan(70);
|
|
|
|
expect(a).toBe(255);
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectBlue(pixels: Buffer, offset: number) {
|
|
|
|
const r = pixels.readUInt8(offset);
|
|
|
|
const g = pixels.readUInt8(offset + 1);
|
|
|
|
const b = pixels.readUInt8(offset + 2);
|
|
|
|
const a = pixels.readUInt8(offset + 3);
|
|
|
|
expect(r).toBeLessThan(70);
|
|
|
|
expect(g).toBeLessThan(70);
|
|
|
|
expect(b).toBeGreaterThan(200);
|
|
|
|
expect(a).toBe(255);
|
|
|
|
}
|