diff --git a/tests/cypress/e2e/UItests.cy.js b/tests/cypress/e2e/UItests.cy.ts
similarity index 99%
rename from tests/cypress/e2e/UItests.cy.js
rename to tests/cypress/e2e/UItests.cy.ts
index c2ecfd7..9d0050f 100644
--- a/tests/cypress/e2e/UItests.cy.js
+++ b/tests/cypress/e2e/UItests.cy.ts
@@ -1,4 +1,3 @@
-///
export default function checkLoginUI() {
cy.get('#title').should('contain', 'Linux Odyssey').and('be.visible')
cy.CheckPlaceholder('#password', '密碼', 'Password')
diff --git a/tests/cypress/e2e/completeQuests.cy.js b/tests/cypress/e2e/completeQuests.cy.ts
similarity index 96%
rename from tests/cypress/e2e/completeQuests.cy.js
rename to tests/cypress/e2e/completeQuests.cy.ts
index 3ef0aab..57ba8e2 100644
--- a/tests/cypress/e2e/completeQuests.cy.js
+++ b/tests/cypress/e2e/completeQuests.cy.ts
@@ -1,4 +1,3 @@
-///
describe('Complete quests with only commands', () => {
beforeEach(() => {
cy.PrepareForGame()
diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.ts
similarity index 70%
rename from tests/cypress/support/commands.js
rename to tests/cypress/support/commands.ts
index 9428779..eb62a5f 100644
--- a/tests/cypress/support/commands.js
+++ b/tests/cypress/support/commands.ts
@@ -1,12 +1,52 @@
-import '@testing-library/cypress/add-commands'
+// import '@testing-library/cypress/add-commands'
+declare global {
+ declare namespace Cypress {
+ interface Chainable {
+ // 確保你有正確的泛型參數
+ fillWith(
+ account: string,
+ password: string
+ ): Chainable>
+ LoginWithPassword(
+ username: string,
+ password: string
+ ): Chainable>
+ PrepareForGame(): Chainable>
+ InitTerminal(): Chainable>
+ typeInCommand(command: string): Chainable>
+ getQuestInfo(id: string): Chainable>
+ checkHint(index: number, total: number): Chainable> // 修改類型
+ checkTaskInit(): Chainable>
+ waitUntilActive(last: boolean): Chainable> // 注意小寫boolean,並且變量名應該是小寫
+ checkPending(): Chainable>
+ CompleteStageWithCommands(
+ stagename: string
+ ): Chainable>
+ CheckTextElement(
+ id: string,
+ chText: string,
+ enText: string
+ ): Chainable>
+ CheckPlaceholder(
+ id: string,
+ chText: string,
+ enText: string
+ ): Chainable>
+ CheckTreeElement(element: string): Chainable>
+ }
+ }
+}
-Cypress.Commands.add('LoginWithPassword', (username, password) => {
- cy.clearAllCookies({ domain: null })
- cy.visit('/login')
- cy.get('#username').type(username)
- cy.get('#password').type(password)
- cy.get('#LogInOrSignUp').click()
-})
+Cypress.Commands.add(
+ 'LoginWithPassword',
+ (username: string, password: string) => {
+ cy.clearAllCookies({ domain: null })
+ cy.visit('/login')
+ cy.get('#username').type(username)
+ cy.get('#password').type(password)
+ cy.get('#LogInOrSignUp').click()
+ }
+)
Cypress.Commands.add('PrepareForGame', () => {
cy.visit('/')
// make sure the login page is loaded
diff --git a/tests/package.json b/tests/package.json
index 46b0294..68157d1 100644
--- a/tests/package.json
+++ b/tests/package.json
@@ -13,5 +13,8 @@
"@testing-library/cypress": "^10.0.1",
"cypress": "^13.5.1",
"dotenv": "^16.3.1"
+ },
+ "devDependencies": {
+ "typescript": "^5.3.3"
}
}
diff --git a/tests/tsconfig.json b/tests/tsconfig.json
new file mode 100644
index 0000000..18edb19
--- /dev/null
+++ b/tests/tsconfig.json
@@ -0,0 +1,8 @@
+{
+ "compilerOptions": {
+ "target": "es5",
+ "lib": ["es5", "dom"],
+ "types": ["cypress", "node"]
+ },
+ "include": ["**/*.ts"]
+}
diff --git a/yarn.lock b/yarn.lock
index 81241b8..fe8624e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -9098,6 +9098,7 @@ __metadata:
"@testing-library/cypress": "npm:^10.0.1"
cypress: "npm:^13.5.1"
dotenv: "npm:^16.3.1"
+ typescript: "npm:^5.3.3"
languageName: unknown
linkType: soft