diff --git a/tests/cypress.config.ts b/tests/cypress.config.ts index 83188db..ce86fe3 100644 --- a/tests/cypress.config.ts +++ b/tests/cypress.config.ts @@ -1,7 +1,7 @@ -const { defineConfig } = require('cypress') -const process = require('process') -const dotenv = require('dotenv') -const fs = require('fs') +import { defineConfig } from 'cypress' +import process from 'process' +import dotenv from 'dotenv' +import fs from 'fs' // Import fs module dotenv.config({ path: '../.env.dev' }) dotenv.config({ path: '../.env' }) @@ -9,17 +9,19 @@ dotenv.config({ path: '../.env' }) const getConfig = (key, defaultValue) => { return process.env[key] || defaultValue } + const getOrFail = (key) => { const value = getConfig(key, null) - if (value === null) { + if (!value) { throw new Error(`Missing required environment variable ${key}`) } return value } +// Check if the .env file exists const EnableoAuth = fs.existsSync('../.env') -module.exports = defineConfig({ +export default defineConfig({ e2e: { baseUrl: getConfig('BASE_URL', 'http://localhost:5173'), viewportWidth: 1920, @@ -33,6 +35,13 @@ module.exports = defineConfig({ defaultAccount: getOrFail('TESTING_USERNAME'), defaultPassword: getOrFail('TESTING_PASSWORD'), isCHVersion: true, - EnableoAuth, + EnableoAuth, // Add the EnableoAuth variable here + // google_username: process.env.GOOGLE_USERNAME, + // google_password: process.env.GOOGLE_PASSWORD, + // google_client_id: process.env.GOOGLE_CLIENT_ID, + + // github_username: process.env.GITHUB_USERNAME, + // github_password: process.env.GITHUB_PASSWORD, + // github_client_id: process.env.GITHUB_CLIENT_ID, }, }) diff --git a/tests/cypress/support/commands.ts b/tests/cypress/support/commands.ts index 8f9f4c5..b77cd88 100644 --- a/tests/cypress/support/commands.ts +++ b/tests/cypress/support/commands.ts @@ -11,7 +11,7 @@ declare global { PrepareForGame(): Chainable InitTerminal(): Chainable typeInCommand(command: string): Chainable - getQuestInfo(id: string): Chainable> + getQuestInfo(id: string): Chainable> checkHint(index: number, total: number): Chainable // 修改類型 checkTaskInit(): Chainable waitUntilActive(last?: boolean): Chainable // 注意小寫boolean,並且變量名應該是小寫 @@ -41,7 +41,7 @@ Cypress.Commands.add('LoginWithPassword', (username, password) => { Cypress.Commands.add('PrepareForGame', () => { cy.visit('/') // make sure the login page is loaded - cy.url().should('satisfy', (elements) => { + cy.url().should('satisfy', (elements: string) => { const text = elements return text.includes('login') || text.includes('register') }) diff --git a/tests/tsconfig.json b/tests/tsconfig.json index cf23123..dd1f480 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -1,14 +1,9 @@ { + "extends": "../tsconfig.json", "compilerOptions": { - "target": "es5", - "lib": ["es5", "dom"], + // "lib": ["es5", "dom"], "types": ["cypress", "@testing-library/cypress"] }, "include": ["node_modules/cypress", "cypress/**/*.ts"], - "exclude": [ - "node_modules/cypress", - "cypress.config.ts", - "./cypress/support/e2e.js", - "../packages" - ] + "exclude": ["node_modules/cypress", "cypress.config.ts", "../packages"] }