Skip to content

Commit

Permalink
Test(web,web-react,web-twig): Introduce visual tests of all component…
Browse files Browse the repository at this point in the history
…s #DS-660
  • Loading branch information
crishpeen committed Jan 16, 2024
1 parent 8a8852e commit 18b2b92
Show file tree
Hide file tree
Showing 47 changed files with 88 additions and 10 deletions.
29 changes: 19 additions & 10 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,31 @@ export default defineConfig({
trace: 'on-first-retry',
},

/* Timeout configuration */
timeout: 120000,

/* Configure expect() to use in tests */
expect: {
/* Setting the timeout for each test */
timeout: 120000,
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
use: { ...devices['Desktop Chrome'], ignoreHTTPSErrors: true },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'], ignoreHTTPSErrors: true },
// },
//
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'], ignoreHTTPSErrors: true },
// },

/* Test against mobile viewports. */
// {
Expand Down
69 changes: 69 additions & 0 deletions tests/e2e/demo-components-compare.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { isTesting } from '@lmc-eu/spirit-common/constants/environments';
import { SERVERS, getDevelopmentEndpointUri } from '@lmc-eu/spirit-common/constants/servers';
import { readdirSync } from 'fs';
import { expect, test } from '@playwright/test';

// Tests that are intentionally broken, but will be fixed in the future
const IGNORED_TESTS = [
'Tooltip', // Should be fixed when DS-1087 and DS-1088 are merged
];

const runComponentCompareTests = (testConfig) => {
const { packageDir, componentsDir, srcDir = '', hiddenComponents = [], type } = testConfig;
const name = type
.split('-')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');

test.describe(`Demo ${name} Components`, () => {
const componentDirs = readdirSync(`${packageDir}${srcDir}${componentsDir}`, { withFileTypes: true })
.filter((item) => item.isDirectory())
.filter((item) => !hiddenComponents.includes(item.name))
.filter((item) => !IGNORED_TESTS.includes(item.name))
.map((item) => item.name.toLowerCase());

for (const component of componentDirs) {
test(`test demo ${name} component ${component}`, async ({ page }) => {
await page.goto(
`${
isTesting() ? SERVERS.TESTING[type] : getDevelopmentEndpointUri(type, { isDocker: type !== 'web-twig' })
}${componentsDir}/${component}/${type === 'web-twig' ? '?HIDE_TOOLBAR' : ''}`,
);
// wait for fonts to load
await page.evaluate(() => document.fonts.ready);
// wait for transitions to finish
await page.waitForLoadState();
// disable animations to avoid flaky screenshots
await page.addStyleTag({ content: '*, *::before, *::after { animation-iteration-count: 1 !important }' });
await expect(page).toHaveScreenshot(`${component}.png`, {
animations: 'disabled',
fullPage: true,
});
});
}
});
};

const testConfigs = [
{
componentsDir: '/src/scss/components',
packageDir: 'packages/web',
type: 'web',
},
{
componentsDir: '/src/components',
hiddenComponents: ['Field', 'Dialog', 'Icon', 'TextFieldBase', 'VisuallyHidden'],
packageDir: 'packages/web-react',
type: 'web-react',
},
// Disable web-twig tests for now on CI, because we don't have a way to run them in CI yet.
!isTesting() && {
componentsDir: '/components',
hiddenComponents: ['Field', 'Icon', 'TextFieldBase', 'VisuallyHidden'],
packageDir: 'packages/web-twig',
srcDir: '/src/Resources',
type: 'web-twig',
},
];

testConfigs.forEach(runComponentCompareTests);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Binary file modified tests/e2e/demo-homepages.spec.ts-snapshots/web-chromium-linux.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.

0 comments on commit 18b2b92

Please sign in to comment.