Files
mostlymatter/e2e-tests/playwright/support/visual/index.ts
Saturnino Abril b7b08dbc0f CLD-5948 Playwright/E2E: Update dependencies, server default config and its types, and remove Boards and mobile view tests (#24583)
* update dependencies

* update dependencies

* remove mobile view

* remove boards

* update default config  and its types

* update snapshots

* fix formatting

* check works and fix styling
2023-09-20 05:28:35 +08:00

39 строки
1.3 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import os from 'node:os';
import chalk from 'chalk';
import {expect, TestInfo} from '@playwright/test';
import {illegalRe} from '@e2e-support/util';
import testConfig, {TestArgs} from '@e2e-test.config';
import snapshotWithPercy from './percy';
export async function matchSnapshot(testInfo: TestInfo, testArgs: TestArgs) {
if (os.platform() !== 'linux') {
// eslint-disable-next-line no-console
console.log(
chalk.yellow(
`^ Warning: No visual test performed. Run in Linux or Playwright docker image to match snapshot.`,
),
);
return;
}
if (testConfig.snapshotEnabled) {
// Visual test with built-in snapshot
const filename = testInfo.title.replace(illegalRe, '').replace(/\s/g, '-').trim().toLowerCase();
expect(await testArgs.page.screenshot({fullPage: true})).toMatchSnapshot(`${filename}.png`);
}
if (testConfig.percyEnabled) {
// Used to easily identify the screenshot when viewing from third-party service provider.
const name = `[${testInfo.project.name}, ${testArgs?.viewport?.width}px] > ${testInfo.file} > ${testInfo.title}`;
// Visual test with Percy
await snapshotWithPercy(name, testArgs);
}
}