yeg
2026-09-05 03d8a2efcd7eec1a7afa18dcaf5c1e3dbc0f6531
tests/e2e/support/ticket04-stack.ts
@@ -87,7 +87,7 @@
  readonly backendUrl = `http://127.0.0.1:${apiPort}`
  async start() {
  async start(profiles = 'druid,dev-simulator') {
    await Promise.all([mysqlPort, redisPort, apiPort, simulatorPort].map(assertPortAvailable))
    this.docker = resolveDocker()
    mkdirSync(artifactDir, { recursive: true })
@@ -107,7 +107,7 @@
      ])
      await this.waitForContainers()
      this.buildBackend()
      await this.startBackend()
      await this.startBackend(profiles)
      this.disableCaptchaInIsolatedDatabase()
    } catch (error) {
      await this.stop()
@@ -115,9 +115,15 @@
    }
  }
  async restartBackend() {
  async restartBackend(profiles = 'druid,dev-simulator') {
    await this.stopBackend()
    await this.startBackend()
    await this.startBackend(profiles)
  }
  queryDatabase(sql: string) {
    if (!/^SELECT\s/i.test(sql)) throw new Error('验收查询只允许 SELECT')
    return this.dockerRun(['exec', this.mysqlContainer, 'mysql', '-uroot', `-p${mysqlPassword}`,
      '--database=battery_detection', '--batch', '--skip-column-names', '-e', sql]).stdout.trim()
  }
  redisCommand(...args: string[]) {
@@ -189,10 +195,10 @@
    if (!existsSync(backendJar)) throw new Error(`未生成后端可执行包: ${backendJar}`)
  }
  private async startBackend() {
  private async startBackend(profiles = 'druid,dev-simulator') {
    const logPath = resolve(artifactDir, 'backend.log')
    const log = createWriteStream(logPath, { flags: 'a' })
    const jdbcUrl = `jdbc:mysql://127.0.0.1:${mysqlPort}/battery_detection?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8`
    const jdbcUrl = `jdbc:mysql://127.0.0.1:${mysqlPort}/battery_detection?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&connectionTimeZone=UTC&forceConnectionTimeZoneToSession=true`
    this.backend = spawn('java', [
      '-jar', backendJar,
      `--server.port=${apiPort}`,
@@ -203,7 +209,7 @@
      `--spring.data.redis.port=${redisPort}`,
      `--spring.data.redis.password=${redisPassword}`,
      '--spring.data.redis.database=0',
      '--spring.profiles.active=druid,dev-simulator',
      `--spring.profiles.active=${profiles}`,
      '--spring.devtools.restart.enabled=false',
      `--battery.dev-simulator.port=${simulatorPort}`,
      `--ruoyi.profile=${artifactDir}`,
@@ -218,7 +224,7 @@
    await waitUntil(async () => {
      if (this.backend?.exitCode !== null) throw new Error(`后端提前退出,详见 ${logPath}`)
      try {
        return (await fetch(`${this.backendUrl}/dev/bts-simulator/state`)).ok
        return (await fetch(`${this.backendUrl}/captchaImage`)).ok
      } catch {
        return false
      }