Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: playwright initial setup and basic test, also updating dependencies #327

Merged
merged 7 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
jest: true,
},
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:react/recommended',
],
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'prettier',
],
overrides: [
{
env: {
node: true,
},
files: ['commitlint.config.js', '.eslintrc.js'],
parserOptions: {
sourceType: 'script',
},
},
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
},
Expand All @@ -20,7 +39,5 @@ module.exports = {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
env: {
jest: true,
},
ignorePatterns: ['dist'],
};
2 changes: 1 addition & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
- name: Cache node modules
uses: actions/cache@v3
with:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: npm install -g yarn && yarn
- name: Install Playwright Browsers
run: yarn playwright install --with-deps
- name: Run Playwright tests
run: yarn playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
- name: Cache node modules
uses: actions/cache@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
- name: Cache node modules
uses: actions/cache@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ coverage
dist
demo/examples
.parcel-cache
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
16 changes: 16 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from 'jest';

const config: Config = {
roots: ['src'],
verbose: false,
collectCoverage: true,
preset: 'ts-jest',
testEnvironment: 'jsdom',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
};

export default config;
63 changes: 26 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"scripts": {
"build": "rm -rf dist && tsc && rollup -c",
"start": "parcel src/examples/index.html",
"test": "LANG=en_GB jest --coverage --roots ./src",
"test-ci": "LANG=en_GB.UTF-8 cross-env NODE_ICU_DATA=node_modules/full-icu jest --coverage",
"test": "LANG=en_GB jest",
"test-ci": "LANG=en_GB.UTF-8 cross-env NODE_ICU_DATA=node_modules/full-icu jest",
"typecheck": "tsc && tsc --project tsconfig.test.json",
"lint": "eslint src --max-warnings=0",
"lint": "eslint ./ --max-warnings=0",
"gh-predeploy": "parcel build src/examples/index.html --dist-dir demo/examples --public-url ./",
"gh-deploy": "yarn gh-predeploy && gh-pages -d demo/examples",
"ci": "yarn && yarn build",
Expand Down Expand Up @@ -45,64 +45,53 @@
"author": "cchanxzy",
"license": "MIT",
"devDependencies": {
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@playwright/test": "^1.40.1",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@testing-library/dom": "^7.31.0",
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
"@testing-library/dom": "^9.3.3",
"@testing-library/jest-dom": "^6.1.6",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^13.1.9",
"@types/jest": "^29.5.7",
"@types/react": "^17.0.6",
"@types/react-dom": "^17.0.5",
"@typescript-eslint/eslint-plugin": "^4.24.0",
"@typescript-eslint/parser": "^4.24.0",
"@types/node": "^20.10.5",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"codecov": "^3.8.3",
"cross-env": "^7.0.3",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.23.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"full-icu": "^1.3.4",
"gh-pages": "^3.1.0",
"husky": "^6.0.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^11.0.0",
"parcel": "^2.0.0-rc.0",
"prettier": "^2.3.0",
"react": "^17.0.2",
"react-dom": "17.0.2",
"prettier": "^3.1.1",
"process": "^0.11.10",
"react": "^18.2.0",
"react-dom": "18.2.0",
"rollup": "^2.52.7",
"semantic-release": "^17.4.3",
"source-map-loader": "^3.0.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"tslib": "^2.3.0",
"typescript": "^4.2.4"
"typescript": "^5.3.3"
},
"peerDependencies": {
"react": "^16.9.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {},
"jest": {
"verbose": false,
"collectCoverage": true,
"testEnvironment": "jsdom",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx"
]
},
"targets": {
"main": false,
"module": false,
Expand Down
77 changes: 77 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!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: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:1234/',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

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

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

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'yarn start',
url: 'http://localhost:1234/',
reuseExistingServer: !process.env.CI,
},
});
4 changes: 2 additions & 2 deletions src/components/CurrencyInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ export const CurrencyInput: FC<CurrencyInputProps> = forwardRef<
) || 0;
const newValue = key === 'ArrowUp' ? currentValue + step : currentValue - step;

if (min !== undefined && newValue < min) {
if (min !== undefined && newValue < Number(min)) {
return;
}

if (max !== undefined && newValue > max) {
if (max !== undefined && newValue > Number(max)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/utils/escapeRegExp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* See: https://stackoverflow.com/questions/17885855/use-dynamic-variable-string-as-regex-pattern-in-javascript
*/
export const escapeRegExp = (stringToGoIntoTheRegex: string): string => {
return stringToGoIntoTheRegex.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
return stringToGoIntoTheRegex.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
};
22 changes: 2 additions & 20 deletions src/examples/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down Expand Up @@ -41,25 +41,7 @@ <h1>React Currency Input Field</h1>
</div>
</div>
<hr />
<div id="example-1"></div>

<hr />

<div id="example-2"></div>

<hr />

<div id="example-3"></div>

<hr />

<div id="example-4"></div>

<hr />

<div id="format-values-example"></div>

<hr />
<div id="app"></div>

<footer class="mb-5"></footer>
</div>
Expand Down
Loading