mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
Merge pull request #209 from blockscout/playwright-setup
playwright setup and git lfs
This commit is contained in:
@@ -0,0 +1 @@
|
||||
__snapshots__/** filter=lfs diff=lfs merge=lfs -text
|
||||
@@ -0,0 +1,26 @@
|
||||
name: playwright
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: mcr.microsoft.com/playwright:v1.27.0-focal
|
||||
|
||||
steps:
|
||||
- run: apt-get update && apt-get install git-lfs
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
lfs: 'true'
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Install dependencies
|
||||
run: yarn
|
||||
- name: Run your tests
|
||||
run: HOME=/root yarn test-ct
|
||||
- name: Upload test results
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: playwright-report
|
||||
path: playwright-report
|
||||
@@ -39,3 +39,6 @@ yarn-error.log*
|
||||
|
||||
# Sentry
|
||||
.sentryclirc
|
||||
/test-results/
|
||||
/playwright-report/
|
||||
/playwright/.cache/
|
||||
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-checkout'.\n"; exit 2; }
|
||||
git lfs post-checkout "$@"
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-commit'.\n"; exit 2; }
|
||||
git lfs post-commit "$@"
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-merge'.\n"; exit 2; }
|
||||
git lfs post-merge "$@"
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.\n"; exit 2; }
|
||||
git lfs pre-push "$@"
|
||||
@@ -9,6 +9,7 @@ Core technologies what used in the project are
|
||||
- [Next.js](https://nextjs.org/) as application framework
|
||||
- [Chakra](https://chakra-ui.com/) as component library; our theme customization could be found in `/theme` folder
|
||||
- [css-modules](https://github.com/css-modules/css-modules) as lib for styling custom components
|
||||
- [playwright](https://playwright.dev/) as a tool for components visual testing
|
||||
|
||||
And of course our premier language is [Typescript](https://www.typescriptlang.org/)
|
||||
|
||||
@@ -21,6 +22,11 @@ For local development please follow next steps:
|
||||
- create local env file `.env.local` according to `.env.example` snapshot (see list of used environment variables [below](#environment-variables))
|
||||
- run `yarn dev` to spin up local dev server and navigate to the host from logs output
|
||||
|
||||
## Components visual testing
|
||||
|
||||
We use [playwright experimental components testing](https://playwright.dev/docs/test-components) for visual (screenshots) CI check. Test renders a single component in headless browser in docker, generates screenshots and then compares this screenshot with a reference one.
|
||||
To perform testing locally you need to install docker and run `yarn test-docker`
|
||||
|
||||
## Environment variables
|
||||
### Variables list
|
||||
The app instance could be customized by passing following variables to NodeJS environment.
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c828ad4724be091b412abdd7ea8265417d5df2ec64af108e3a0c4a7d114328f9
|
||||
size 1101
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:87fd989bcda6a9f5ec55203859cc55d6dcb93907479467e753e9519d73405ea8
|
||||
size 1218
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:11cfeb03fb63aeea7ebfd7935fad3944b59d0574b39759923323743024d4a6be
|
||||
size 1055
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:902cbe6d2a8d566b3c0ed3cebe69cfae5b92e57e4d3429dc237b5d7870e78460
|
||||
size 1140
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4969801b8a816a94338582ac85664c5bc23fd5b7d393942fe95405bc1b8e15dd
|
||||
size 1201
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:26e641105bbea743c935076bb8ac2646ce5f0a47c714e8617302bd5c79fbbd35
|
||||
size 1096
|
||||
+5
-1
@@ -13,7 +13,9 @@
|
||||
"start": "next start",
|
||||
"lint:eslint": "./node_modules/.bin/eslint . --ext .js,.jsx,.ts,.tsx",
|
||||
"prepare": "husky install",
|
||||
"format-svg": "./node_modules/.bin/svgo -r ./icons"
|
||||
"format-svg": "./node_modules/.bin/svgo -r ./icons",
|
||||
"test-ct": "playwright test -c playwright-ct.config.ts",
|
||||
"test-docker": "docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.27.0-focal ./run-tests.sh"
|
||||
},
|
||||
"dependencies": {
|
||||
"@chakra-ui/react": "2.3.1",
|
||||
@@ -42,6 +44,7 @@
|
||||
"use-font-face-observer": "^1.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/experimental-ct-react": "^1.26.1",
|
||||
"@types/node": "17.0.36",
|
||||
"@types/react": "18.0.9",
|
||||
"@types/react-dom": "18.0.5",
|
||||
@@ -53,6 +56,7 @@
|
||||
"eslint-plugin-regexp": "^1.7.0",
|
||||
"husky": "^8.0.0",
|
||||
"lint-staged": ">=10",
|
||||
"playwright": "^1.26.1",
|
||||
"svgo": "^2.8.0",
|
||||
"typescript": "4.7.2"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { PlaywrightTestConfig } from '@playwright/experimental-ct-react';
|
||||
import { devices } from '@playwright/experimental-ct-react';
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
*/
|
||||
const config: PlaywrightTestConfig = {
|
||||
testDir: './',
|
||||
|
||||
testMatch: /.*\.pw\.tsx/,
|
||||
|
||||
/* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
|
||||
snapshotDir: './__snapshots__',
|
||||
|
||||
/* Maximum time one test can run for. */
|
||||
timeout: 10 * 1000,
|
||||
|
||||
/* Run tests in files in parallel */
|
||||
fullyParallel: true,
|
||||
|
||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
forbidOnly: Boolean(process.env.CI),
|
||||
|
||||
/* Retry on CI only */
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
|
||||
/* Opt out of parallel tests on CI. */
|
||||
workers: process.env.CI ? 1 : undefined,
|
||||
|
||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||
reporter: 'html',
|
||||
|
||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||
use: {
|
||||
|
||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||
trace: 'on-first-retry',
|
||||
|
||||
/* Port to use for Playwright component endpoint. */
|
||||
ctPort: 3100,
|
||||
|
||||
headless: true,
|
||||
},
|
||||
|
||||
/* Configure projects for major browsers */
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
use: {
|
||||
...devices['Desktop Firefox'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'webkit',
|
||||
use: {
|
||||
...devices['Desktop Safari'],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
import type { ColorMode } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
|
||||
import theme from '../theme';
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode;
|
||||
colorMode?: ColorMode;
|
||||
}
|
||||
|
||||
const RenderWithChakra = ({ children, colorMode = 'light' }: Props) => {
|
||||
return (
|
||||
<ChakraProvider theme={{ ...theme, config: { ...theme.config, initialColorMode: colorMode } }}>
|
||||
{ children }
|
||||
</ChakraProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default RenderWithChakra;
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Testing Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/playwright/index.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,4 @@
|
||||
// Import styles, initialize component theme here.
|
||||
// import '../src/common.css';
|
||||
|
||||
export {};
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
yarn install
|
||||
yarn test-ct
|
||||
@@ -0,0 +1,25 @@
|
||||
import { test, expect } from '@playwright/experimental-ct-react';
|
||||
import React from 'react';
|
||||
|
||||
import RenderWithChakra from '../../playwright/RenderWithChakra';
|
||||
import Utilization from './Utilization';
|
||||
|
||||
test.use({ viewport: { width: 100, height: 50 } });
|
||||
|
||||
test('Utilization light', async({ mount }) => {
|
||||
const component = await mount(
|
||||
<RenderWithChakra>
|
||||
<Utilization value={ 0.1 }/>
|
||||
</RenderWithChakra>,
|
||||
);
|
||||
await expect(component).toHaveScreenshot();
|
||||
});
|
||||
|
||||
test('Utilization dark', async({ mount }) => {
|
||||
const component = await mount(
|
||||
<RenderWithChakra colorMode="dark">
|
||||
<Utilization value={ 0.1 }/>
|
||||
</RenderWithChakra>,
|
||||
);
|
||||
await expect(component).toHaveScreenshot();
|
||||
});
|
||||
Reference in New Issue
Block a user