Skip to content

Commit 2a87864

Browse files
authored
Merge pull request #971
* chore(30540): fix cypress-each * chore(30540): add declaration for the custom commands * chore(30540): refactor component to simple TS and external command * chore(30540): add comments for debugging * chore(30540): add duplicate for testing * chore(30540): add types * chore(30540): fix paths * chore(30540): update dependencies * chore(30540): update eslint configuration * chore(30540): clean comments * chore(30540): linting
1 parent 44aa387 commit 2a87864

34 files changed

+1664
-395
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { ContextObject } from 'axe-core'
2+
import type { Options } from 'cypress-axe'
3+
4+
declare global {
5+
namespace Cypress {
6+
interface Chainable {
7+
getByTestId(value: string): Chainable<JQuery<HTMLElement>>
8+
getByAriaLabel(value: string): Chainable<JQuery<HTMLElement>>
9+
checkAccessibility(
10+
context?: string | Node | ContextObject | undefined,
11+
options?: Options | undefined,
12+
skipFailures?: boolean
13+
): Chainable<JQuery<HTMLElement>>
14+
clearInterceptList(interceptAlias: string): Chainable<JQuery<HTMLElement>>
15+
mount(jsx: React__default.ReactNode, options?: MountOptions, rerenderKey?: string): Cypress.Chainable<MountReturn>
16+
mountWithProviders(
17+
component: React.ReactNode,
18+
options?: MountOptions & { routerProps?: MemoryRouterProps } & {
19+
wrapper?: React.JSXElementConstructor<{ children: React.ReactNode }>
20+
}
21+
): Cypress.Chainable<MountReturn>
22+
}
23+
}
24+
}
25+
26+
export {}

hivemq-edge-frontend/cypress/support/commands.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,8 @@
1-
/// <reference types="cypress" />
2-
// ***********************************************
3-
// This example commands.ts shows you how to
4-
// create various custom commands and overwrite
5-
// existing commands.
6-
//
7-
// For more comprehensive examples of custom
8-
// commands please read more here:
9-
// https://on.cypress.io/custom-commands
10-
// ***********************************************
11-
//
12-
//
13-
// -- This is a parent command --
14-
// Cypress.Commands.add('login', (email, password) => { ... })
15-
//
16-
//
17-
// -- This is a child command --
18-
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19-
//
20-
//
21-
// -- This is a dual command --
22-
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23-
//
24-
//
25-
// -- This will overwrite an existing command --
26-
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27-
//
281
import { getByTestId } from './commands/getByTestId.ts'
292
import { getByAriaLabel } from './commands/getByAriaLabel.ts'
303
import { checkAccessibility } from './commands/checkAccessibility.ts'
314
import { clearInterceptList } from './commands/clearInterceptList.ts'
325

33-
declare global {
34-
// eslint-disable-next-line @typescript-eslint/no-namespace
35-
namespace Cypress {
36-
interface Chainable {
37-
checkAccessibility: typeof checkAccessibility
38-
getByTestId: typeof getByTestId
39-
getByAriaLabel: typeof getByAriaLabel
40-
clearInterceptList: typeof clearInterceptList
41-
}
42-
}
43-
}
44-
456
Cypress.Commands.add('getByTestId', getByTestId)
467
Cypress.Commands.add('getByAriaLabel', getByAriaLabel)
478
Cypress.Commands.add('checkAccessibility', checkAccessibility)
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import 'cypress-axe'
2-
import 'cypress-each'
3-
import '@percy/cypress'
4-
import 'cypress-real-events'
5-
import '@cypress/code-coverage/support'
6-
7-
import './commands'
8-
9-
import type { MountOptions, MountReturn } from 'cypress/react'
1+
import type { MountOptions } from 'cypress/react'
102
import { mount } from 'cypress/react'
113
import type { MemoryRouterProps } from 'react-router-dom'
124
import { MemoryRouter } from 'react-router-dom'
@@ -22,29 +14,18 @@ import '@/config/i18n.config.ts'
2214
import '@fontsource/roboto/400.css'
2315
import '@fontsource/roboto/700.css'
2416

25-
// Augment the Cypress namespace to include type definitions for
26-
// your custom command.
27-
// Alternatively, can be defined in cypress/support/component.d.ts
28-
// with a <reference path="./component" /> at the top of your spec.
29-
declare global {
30-
// eslint-disable-next-line @typescript-eslint/no-namespace
31-
namespace Cypress {
32-
interface Chainable {
33-
mount: typeof mount
34-
35-
mountWithProviders(
36-
component: React.ReactNode,
37-
options?: MountOptions & { routerProps?: MemoryRouterProps } & {
38-
wrapper?: React.JSXElementConstructor<{ children: React.ReactNode }>
39-
}
40-
): Cypress.Chainable<MountReturn>
41-
}
17+
/**
18+
* * Attempts to find an element with a test id attribute of the given param value
19+
* @example
20+
* cy.getByTestId('btn')
21+
* */
22+
export const mountWithProviders = (
23+
component: React.ReactNode,
24+
options?: MountOptions & { routerProps?: MemoryRouterProps } & {
25+
wrapper?: React.JSXElementConstructor<{ children: React.ReactNode }>
4226
}
43-
}
44-
45-
Cypress.Commands.add('mount', mount)
46-
Cypress.Commands.add('mountWithProviders', (component, options = {}) => {
47-
const { routerProps = { initialEntries: ['/'] }, wrapper: Test, ...mountOptions } = options
27+
) => {
28+
const { routerProps = { initialEntries: ['/'] }, wrapper: Test, ...mountOptions } = options || {}
4829

4930
const wrapped = (
5031
<QueryClientProvider
@@ -74,4 +55,4 @@ Cypress.Commands.add('mountWithProviders', (component, options = {}) => {
7455
)
7556

7657
return mount(wrapped, mountOptions)
77-
})
58+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'cypress-axe'
2+
import 'cypress-each'
3+
import '@percy/cypress'
4+
import 'cypress-real-events'
5+
import '@cypress/code-coverage/support'
6+
7+
import './commands'
8+
import { mount } from 'cypress/react'
9+
import { mountWithProviders } from './commands/mountWithProviders.tsx'
10+
11+
Cypress.Commands.add('mount', mount)
12+
Cypress.Commands.add('mountWithProviders', mountWithProviders)

hivemq-edge-frontend/eslint.config.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import js from '@eslint/js'
22
import globals from 'globals'
3+
import reactPlugin from 'eslint-plugin-react'
34
import reactHooks from 'eslint-plugin-react-hooks'
45
import reactRefresh from 'eslint-plugin-react-refresh'
56
import tsEslint from 'typescript-eslint'
@@ -9,16 +10,21 @@ import pluginQuery from '@tanstack/eslint-plugin-query'
910

1011
export default tsEslint.config(
1112
{ ignores: ['dist', '**/__generated__/*'] },
12-
eslintConfigPrettier,
13+
reactPlugin.configs.flat.recommended,
14+
reactPlugin.configs.flat['jsx-runtime'],
1315
pluginCypress.configs.recommended,
1416
...pluginQuery.configs['flat/recommended'],
17+
eslintConfigPrettier,
1518
{
1619
extends: [js.configs.recommended, ...tsEslint.configs.recommended],
1720
files: ['**/*.{ts,tsx}'],
1821
languageOptions: {
1922
ecmaVersion: 2020,
2023
globals: globals.browser,
2124
},
25+
settings: {
26+
react: { version: 'detect' },
27+
},
2228
plugins: {
2329
'react-hooks': reactHooks,
2430
'react-refresh': reactRefresh,
@@ -37,10 +43,14 @@ export default tsEslint.config(
3743
},
3844
],
3945

46+
'react/prop-types': 0,
47+
'react/display-name': 0,
48+
4049
'unused-expressions': 'off',
4150
'@typescript-eslint/no-unused-expressions': 'off',
4251
'cypress/no-unnecessary-waiting': 'error',
4352
'@typescript-eslint/consistent-type-imports': 'error',
53+
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }],
4454
},
4555
}
4656
)

hivemq-edge-frontend/package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dev": "vite",
88
"build": "tsc && vite build",
99
"lint:eslint": "eslint src --report-unused-disable-directives --max-warnings 0",
10+
"lint:eslint:fix": "eslint src --report-unused-disable-directives --max-warnings 0 --fix",
1011
"lint:prettier": "prettier --check .",
1112
"lint:prettier:write": "prettier --write .",
1213
"lint:stylelint": "stylelint './src/**/*.css'",
@@ -22,7 +23,7 @@
2223
"cypress:run:matrix:e2e": "cypress run -q --e2e --spec ./cypress/e2e/Login/**/* && copyfiles --flat ./coverage-cypress/lcov.info ./coverage-cypress/coverage-final.json ./coverage-combined/e2e",
2324
"cypress:run:matrix:components": "cypress run -q --component --spec ./src/components/ConnectionStatusBadge/**/* && copyfiles --flat ./coverage-cypress/lcov.info ./coverage-combined/components",
2425
"cypress:run:matrix:extensions": "cypress run -q --component --spec ./src/extensions/datahub/components/controls/CanvasControls.spec.cy.tsx && copyfiles --flat ./coverage-cypress/lcov.info ./coverage-combined/extensions",
25-
"cypress:run:matrix:modules": "cypress run -q --component --spec ./src/modules/**/*",
26+
"cypress:run:matrix:modules": "cypress run -q --component --spec './src/modules/**/*'",
2627
"cypress:percy": "LOCAL_NONCE=$(date '+%s') && PERCY_PARALLEL_NONCE=$LOCAL_NONCE percy exec --parallel -- cypress run --e2e && PERCY_PARALLEL_NONCE=$LOCAL_NONCE percy exec --parallel -- cypress run --component && PERCY_PARALLEL_NONCE=$LOCAL_NONCE percy build:finalize ",
2728
"test": "vitest",
2829
"test:coverage": "vitest run --coverage",
@@ -119,12 +120,12 @@
119120
"@4tw/cypress-drag-drop": "^2.3.0",
120121
"@chakra-ui/cli": "^2.4.1",
121122
"@cypress/code-coverage": "^3.13.11",
122-
"@eslint/js": "^9.17.0",
123+
"@eslint/js": "^9.26.0",
123124
"@istanbuljs/nyc-config-typescript": "^1.0.2",
124125
"@mswjs/data": "^0.16.2",
125126
"@percy/cli": "^1.28.5",
126127
"@percy/cypress": "^3.1.3",
127-
"@tanstack/eslint-plugin-query": "^5.66.0",
128+
"@tanstack/eslint-plugin-query": "^5.74.7",
128129
"@testing-library/jest-dom": "^6.6.3",
129130
"@testing-library/react": "^16.2.0",
130131
"@types/debug": "^4.1.12",
@@ -144,24 +145,25 @@
144145
"cypress-each": "^1.14.0",
145146
"cypress-terminal-report": "^7.1.0",
146147
"d3-scale-cluster": "^2.0.1",
147-
"eslint": "^9.19.0",
148-
"eslint-config-prettier": "^10.0.1",
149-
"eslint-plugin-cypress": "^4.1.0",
150-
"eslint-plugin-react-hooks": "^5.1.0",
151-
"eslint-plugin-react-refresh": "^0.4.18",
148+
"eslint": "^9.26.0",
149+
"eslint-config-prettier": "^10.1.5",
150+
"eslint-plugin-cypress": "^4.3.0",
151+
"eslint-plugin-react": "^7.37.5",
152+
"eslint-plugin-react-hooks": "^5.2.0",
153+
"eslint-plugin-react-refresh": "^0.4.20",
152154
"fs-extra": "^11.3.0",
153-
"globals": "^15.14.0",
155+
"globals": "^16.1.0",
154156
"i18next-pseudo": "^2.2.1",
155157
"jsdom": "^24.0.0",
156158
"msw": "^2.7.0",
157159
"openapi-typescript-codegen": "^0.25.0",
158-
"prettier": "^3.4.2",
160+
"prettier": "^3.5.3",
159161
"sass": "^1.70.0",
160162
"stylelint": "^16.14.1",
161163
"stylelint-config-standard": "^37.0.0",
162164
"stylelint-config-standard-scss": "^14.0.0",
163165
"typescript": "^5.7.3",
164-
"typescript-eslint": "^8.18.2",
166+
"typescript-eslint": "^8.32.1",
165167
"vite": "^6.2.5",
166168
"vite-plugin-istanbul": "^6.0.2",
167169
"vitest": "^3.1.1"

0 commit comments

Comments
 (0)