-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
298 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ logs | |
.env | ||
.env.* | ||
!.env.example | ||
|
||
# Cypress specific | ||
cypress/screenshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'cypress'; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
baseUrl: 'http://localhost:3000', | ||
chromeWebSecurity: false, | ||
specPattern: 'cypress/e2e/**/*.spec.*', | ||
supportFile: false, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
context('首页', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
cy.contains('示例页').should('exist'); | ||
}); | ||
|
||
it('跳转测试', () => { | ||
cy.url() | ||
.should('eq', 'http://localhost:3000/'); | ||
|
||
cy.contains('基础项目模板').should('exist'); | ||
|
||
cy.get('#name-input') | ||
.type('mixte{enter}') | ||
.url() | ||
.should('eq', 'http://localhost:3000/hello/mixte'); | ||
|
||
cy.get('#back') | ||
.click() | ||
.url() | ||
.should('eq', 'http://localhost:3000/'); | ||
|
||
cy.get('#go') | ||
.should('be.disabled'); | ||
|
||
cy.get('#name-input') | ||
.type('Zw'); | ||
|
||
cy.get('#go') | ||
.should('not.be.disabled') | ||
.click() | ||
.url() | ||
.should('eq', 'http://localhost:3000/hello/Zw666'); | ||
}); | ||
|
||
it('底部按钮 - [首页]', () => { | ||
cy.url() | ||
.should('eq', 'http://localhost:3000/'); | ||
|
||
cy.get('button[title="首页"]') | ||
.click() | ||
.url() | ||
.should('eq', 'http://localhost:3000/'); | ||
|
||
cy.get('#name-input') | ||
.type('mixte{enter}'); | ||
|
||
cy.url() | ||
.should('eq', 'http://localhost:3000/hello/mixte'); | ||
|
||
cy.get('button[title="首页"]') | ||
.click() | ||
.url() | ||
.should('eq', 'http://localhost:3000/'); | ||
}); | ||
|
||
it('底部按钮 - [切换深色模式]', () => { | ||
const btnSelector = 'button[title="切换深色模式"]'; | ||
|
||
Cypress.$.each(['one', 'two'], (index) => { | ||
// light | ||
|
||
cy.get(`${btnSelector}[data-theme="light"]`) | ||
.should('exist'); | ||
|
||
cy.get('html') | ||
.should('have.class', 'light') | ||
.should('not.have.class', 'dark'); | ||
|
||
cy.get(btnSelector).click(); | ||
|
||
// dark | ||
|
||
cy.get(`${btnSelector}[data-theme="dark"]`) | ||
.should('exist'); | ||
|
||
cy.get('html') | ||
.should('have.class', 'dark') | ||
.should('not.have.class', 'light'); | ||
|
||
cy.get(btnSelector).click(); | ||
|
||
// system ( light ) | ||
|
||
cy.get(`${btnSelector}[data-theme="system"]`) | ||
.should('exist'); | ||
|
||
cy.get('html') | ||
.should('have.class', 'light') | ||
.should('not.have.class', 'dark'); | ||
|
||
// reset | ||
if (!index) { | ||
cy.get(btnSelector).click(); | ||
} | ||
}); | ||
}); | ||
|
||
it('底部按钮 - [跳转到 Github]', () => { | ||
cy.get('button[title="跳转到 Github"]') | ||
.children('a') | ||
.should('have.attr', 'target', '_blank') | ||
.should('have.attr', 'href', 'https://github.com/MoomFE-Starter-Template/Base'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { spawn } from 'node:child_process'; | ||
import process from 'node:process'; | ||
|
||
const argv = process.argv.slice(2); | ||
const command = argv.includes('--ci') ? 'run' : 'open'; | ||
|
||
// 启动预览 | ||
const preview = spawn('npm', ['run', 'preview'], { | ||
shell: true, | ||
stdio: 'inherit', | ||
}); | ||
|
||
// 等待预览启动 | ||
const wait = spawn('wait-on', ['http://localhost:3000'], { | ||
shell: true, | ||
}); | ||
|
||
// 等待预览启动完成后 | ||
wait.on('exit', () => { | ||
// 启动 Cypress 测试 | ||
const cypress = spawn('cypress', [command, '--config-file', 'cypress/cypress.config.ts'], { | ||
shell: true, | ||
stdio: 'inherit', | ||
}); | ||
|
||
// 当 Cypress 进程退出时,关闭预览进程 | ||
cypress.on('exit', () => { | ||
preview.kill(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.