-
Notifications
You must be signed in to change notification settings - Fork 263
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
chore: e2e test & ci integration #2740
base: feat_v3.x
Are you sure you want to change the base?
Changes from 4 commits
6a16d1f
99c005f
140b31e
8d3f08e
8beff5c
22cc2fe
7fe0719
2524793
75d817a
23661fa
69268e6
2b051dd
c89278d
d860276
efc90b7
e821c24
d71669d
eeefcbc
515a12b
16f267c
0cfaf5c
6207bf7
4218503
be2c6d5
d508760
051f657
72d467f
5667f45
7107a70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: E2E Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- V3.0 | ||
pull_request: | ||
branches: | ||
- V3.0 | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install pnpm | ||
run: corepack enable pnpm | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Run E2E Tests for H5 | ||
env: | ||
CI: true | ||
run: pnpm e2e:h5:run | ||
|
||
- name: Run E2E Tests for Taro | ||
env: | ||
CI: true | ||
run: pnpm e2e:taro:run | ||
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { componentTest } from './utils' | ||
|
||
describe('base components test', () => { | ||
componentTest('Button', () => {}) | ||
componentTest('Cell', () => {}) | ||
componentTest('ConfigProvider', () => {}) | ||
componentTest('Icon', () => {}) | ||
componentTest('Image', () => {}) | ||
componentTest('Overlay', () => {}) | ||
}) | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Cypress.on('uncaught:exception', (err, runnable) => { | ||
return false | ||
}) | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { componentTest } from './utils' | ||
|
||
describe('bussiness components test', () => { | ||
componentTest('Barrage', () => {}) | ||
componentTest('Card', () => {}) | ||
componentTest('TimeSelect', () => {}) | ||
componentTest('TrendArrow', () => {}) | ||
componentTest('WaterMark', () => {}) | ||
componentTest('AvatarCropper', () => {}) | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { componentTest } from './utils' | ||
|
||
describe('dentry components test', () => { | ||
componentTest('Address', () => {}) | ||
componentTest('Calendar', () => {}) | ||
componentTest('CalendarCard', () => {}) | ||
componentTest('Cascader', () => {}) | ||
componentTest('Checkbox', () => {}) | ||
componentTest('DatePicker', () => {}) | ||
componentTest('Form', () => {}) | ||
componentTest('Input', () => {}) | ||
componentTest('InputNumber', () => {}) | ||
componentTest('Menu', () => {}) | ||
componentTest('NumberKeyboard', () => {}) | ||
componentTest('Picker', () => {}) | ||
componentTest('Radio', () => {}) | ||
componentTest('Range', () => {}) | ||
componentTest('Rate', () => {}) | ||
componentTest('SearchBar', () => {}) | ||
componentTest('ShortPassword', () => {}) | ||
componentTest('Signature', () => {}) | ||
componentTest('Switch', () => {}) | ||
componentTest('TextArea', () => {}) | ||
componentTest('Uploader', () => {}) | ||
}) | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { componentTest } from './utils' | ||
|
||
describe('exhibition components test', () => { | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
componentTest('Animate', () => {}) | ||
componentTest('AnimatingNumbers', () => {}) | ||
componentTest('Audio', () => {}) | ||
componentTest('Avatar', () => {}) | ||
componentTest('CircleProgress', () => {}) | ||
componentTest('Collapse', () => {}) | ||
componentTest('CountDown', () => {}) | ||
componentTest('Ellipsis', () => {}) | ||
componentTest('ImagePreview', () => {}) | ||
componentTest('Indicator', () => {}) | ||
componentTest('Pagination', () => {}) | ||
componentTest('Price', () => {}) | ||
componentTest('Progress', () => {}) | ||
componentTest('Swiper', () => {}) | ||
componentTest('Table', () => {}) | ||
componentTest('Tag', () => {}) | ||
componentTest('Tour', () => {}) | ||
componentTest('Video', () => {}) | ||
componentTest('VirtualList', () => {}) | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { componentTest } from './utils' | ||
|
||
describe('feedback components test', () => { | ||
componentTest('ActionSheet', () => {}) | ||
componentTest('Badge', () => {}) | ||
componentTest('Dialog', () => {}) | ||
componentTest('Drag', () => {}) | ||
componentTest('Empty', () => {}) | ||
componentTest('ResultPage', () => {}) | ||
componentTest('InfiniteLoading', () => {}) | ||
componentTest('Loading', () => {}) | ||
componentTest('NoticeBar', () => {}) | ||
componentTest('Notify', () => {}) | ||
componentTest('Popover', () => {}) | ||
componentTest('Popup', () => {}) | ||
componentTest('PullToRefresh', () => {}) | ||
componentTest('Skeleton', () => {}) | ||
componentTest('Swipe', () => {}) | ||
componentTest('Toast', () => {}) | ||
}) | ||
Comment on lines
+3
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 测试用例缺少具体实现 当前所有组件的测试用例都是空实现,这可能会导致测试覆盖率不足。建议为每个组件添加以下测试项:
我可以协助您生成具体的测试用例实现。以下是一个示例实现: componentTest('Dialog', () => {
it('应该正确渲染对话框', () => {
cy.get('.nut-dialog').should('not.exist')
cy.get('.dialog-btn').click()
cy.get('.nut-dialog').should('be.visible')
})
it('应该响应确认和取消操作', () => {
cy.get('.dialog-btn').click()
cy.get('.nut-dialog__footer').contains('确定').click()
cy.get('.nut-dialog').should('not.exist')
})
}) 需要我为其他组件也生成类似的测试用例实现吗? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import './base.cy' | ||
import './layout.cy' | ||
import './nav.cy' | ||
import './dentry.cy' | ||
import './bussiness.cy' | ||
import './exhibition.cy' | ||
import './feedback.cy' | ||
|
||
Cypress.on('uncaught:exception', (err, runnable) => { | ||
return false | ||
}) | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { componentTest } from './utils' | ||
|
||
describe('layout components test', () => { | ||
componentTest('Divider', () => {}) | ||
componentTest('Grid', () => {}) | ||
componentTest('Layout', () => {}) | ||
componentTest('Space', () => {}) | ||
componentTest('Sticky', () => {}) | ||
componentTest('SafeArea', () => {}) | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { componentTest } from './utils' | ||
|
||
describe('nav components test', () => { | ||
componentTest('BackTop', () => {}) | ||
componentTest('Elevator', () => {}) | ||
componentTest('FixedNav', () => {}) | ||
componentTest('HoverButton', () => {}) | ||
componentTest('NavBar', () => {}) | ||
componentTest('SideNavBar', () => {}) | ||
componentTest('Tabbar', () => {}) | ||
componentTest('Tabs', () => {}) | ||
Comment on lines
+4
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 需要实现具体的测试用例 当前所有导航组件的测试用例都是空的,建议为每个组件添加以下测试内容:
以下是优先级较高的测试场景:
需要我为这些组件生成具体的测试用例代码吗? |
||
}) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
export const componentTest = (comName, fn, delay = 800) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
const getPath = (component) => `${Cypress.env('baseUrl')}${component}` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
it(`${comName} successfully passes`, () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
cy.visit(getPath(comName), { | ||||||||||||||||||||||||||||||||||||||||||||||||
onBeforeLoad: (win) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
Object.defineProperty(win.navigator, 'userAgent', { | ||||||||||||||||||||||||||||||||||||||||||||||||
value: | ||||||||||||||||||||||||||||||||||||||||||||||||
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1', | ||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+4
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议改进用户代理模拟方式 当前的实现存在以下问题:
建议实现一个可配置的设备模拟方案: +const DEVICE_AGENTS = {
+ iPhone: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',
+ iPad: 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
+ Android: 'Mozilla/5.0 (Linux; Android 8.0.0;) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Mobile Safari/537.36'
+};
+
+export const componentTest = (comName, fn, { delay = 800, device = 'iPhone' } = {}) => {
it(`${comName} successfully passes`, () => {
cy.visit(getPath(comName), {
onBeforeLoad: (win) => {
Object.defineProperty(win.navigator, 'userAgent', {
- value: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',
+ value: DEVICE_AGENTS[device]
})
},
})
|
||||||||||||||||||||||||||||||||||||||||||||||||
cy.get('#nav').contains(comName) | ||||||||||||||||||||||||||||||||||||||||||||||||
cy.wait(delay) | ||||||||||||||||||||||||||||||||||||||||||||||||
fn() | ||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议增强测试流程的稳定性 当前实现存在以下问题:
建议添加更多的错误处理和重试机制: - cy.get('#nav').contains(comName)
- cy.wait(delay)
- fn()
+ cy.get('#nav', { timeout: 10000 })
+ .should('exist')
+ .contains(comName)
+ .should('be.visible')
+
+ // 等待页面加载完成
+ cy.document().then((doc) => {
+ return new Cypress.Promise((resolve) => {
+ if (doc.readyState === 'complete') {
+ resolve()
+ } else {
+ doc.addEventListener('load', resolve)
+ }
+ })
+ })
+
+ // 执行测试函数
+ cy.wrap(null).then(() => fn()) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
建议增强测试执行和报告机制
当前的测试执行配置可以通过以下方式增强:
建议添加以下步骤:
📝 Committable suggestion