extend from global settings and modify cypress config

This commit is contained in:
Annie Huang committed 2024-02-27 11:41:37 +08:00
1 parent 004d232a84
commit 9e108e397b
3 files changed
+21 -17

No files matched your search

+16 -7
View File
@@ -1,7 +1,7 @@
const { defineConfig } = require('cypress') import { defineConfig } from 'cypress'
const process = require('process') import process from 'process'
const dotenv = require('dotenv') import dotenv from 'dotenv'
const fs = require('fs') import fs from 'fs' // Import fs module
dotenv.config({ path: '../.env.dev' }) dotenv.config({ path: '../.env.dev' })
dotenv.config({ path: '../.env' }) dotenv.config({ path: '../.env' })
@@ -9,17 +9,19 @@ dotenv.config({ path: '../.env' })
const getConfig = (key, defaultValue) => { const getConfig = (key, defaultValue) => {
return process.env[key] || defaultValue return process.env[key] || defaultValue
} }
const getOrFail = (key) => { const getOrFail = (key) => {
const value = getConfig(key, null) const value = getConfig(key, null)
if (value === null) { if (!value) {
throw new Error(`Missing required environment variable ${key}`) throw new Error(`Missing required environment variable ${key}`)
} }
return value return value
} }
// Check if the .env file exists
const EnableoAuth = fs.existsSync('../.env') const EnableoAuth = fs.existsSync('../.env')
module.exports = defineConfig({ export default defineConfig({
e2e: { e2e: {
baseUrl: getConfig('BASE_URL', 'http://localhost:5173'), baseUrl: getConfig('BASE_URL', 'http://localhost:5173'),
viewportWidth: 1920, viewportWidth: 1920,
@@ -33,6 +35,13 @@ module.exports = defineConfig({
defaultAccount: getOrFail('TESTING_USERNAME'), defaultAccount: getOrFail('TESTING_USERNAME'),
defaultPassword: getOrFail('TESTING_PASSWORD'), defaultPassword: getOrFail('TESTING_PASSWORD'),
isCHVersion: true, 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,
}, },
}) })
+2 -2
View File
@@ -11,7 +11,7 @@ declare global {
PrepareForGame(): Chainable<void> PrepareForGame(): Chainable<void>
InitTerminal(): Chainable<void> InitTerminal(): Chainable<void>
typeInCommand(command: string): Chainable<string> typeInCommand(command: string): Chainable<string>
getQuestInfo(id: string): Chainable<JQuery<HTMLElement>> getQuestInfo(id: string): Chainable<JQuery<HTMLParagraphElement>>
checkHint(index: number, total: number): Chainable<number> // 修改類型 checkHint(index: number, total: number): Chainable<number> // 修改類型
checkTaskInit(): Chainable<void> checkTaskInit(): Chainable<void>
waitUntilActive(last?: boolean): Chainable<void> // 注意小寫boolean,並且變量名應該是小寫 waitUntilActive(last?: boolean): Chainable<void> // 注意小寫boolean,並且變量名應該是小寫
@@ -41,7 +41,7 @@ Cypress.Commands.add('LoginWithPassword', (username, password) => {
Cypress.Commands.add('PrepareForGame', () => { Cypress.Commands.add('PrepareForGame', () => {
cy.visit('/') cy.visit('/')
// make sure the login page is loaded // make sure the login page is loaded
cy.url().should('satisfy', (elements) => { cy.url().should('satisfy', (elements: string) => {
const text = elements const text = elements
return text.includes('login') || text.includes('register') return text.includes('login') || text.includes('register')
}) })
+3 -8
View File
@@ -1,14 +1,9 @@
{ {
"extends": "../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"target": "es5", // "lib": ["es5", "dom"],
"lib": ["es5", "dom"],
"types": ["cypress", "@testing-library/cypress"] "types": ["cypress", "@testing-library/cypress"]
}, },
"include": ["node_modules/cypress", "cypress/**/*.ts"], "include": ["node_modules/cypress", "cypress/**/*.ts"],
"exclude": [ "exclude": ["node_modules/cypress", "cypress.config.ts", "../packages"]
"node_modules/cypress",
"cypress.config.ts",
"./cypress/support/e2e.js",
"../packages"
]
} }