uiLauncher.test.mjs 1.56 KB
import assert from 'node:assert/strict'
import test from 'node:test'
import { openMiniProgram } from './uiLauncher.mjs'

test('IT-OL-UI-010: connection mode reuses an existing loopback endpoint', async () => {
  const calls = []
  const miniProgram = { id: 'connected' }
  const automator = {
    async connect(options) {
      calls.push({ method: 'connect', options })
      return miniProgram
    },
    async launch() {
      throw new Error('launch should not be called')
    }
  }

  const result = await openMiniProgram(automator, {
    launchDevTools: false,
    wsEndpoint: 'ws://127.0.0.1:9420'
  })

  assert.equal(result, miniProgram)
  assert.deepEqual(calls, [
    {
      method: 'connect',
      options: { wsEndpoint: 'ws://127.0.0.1:9420' }
    }
  ])
})

test('IT-OL-UI-011: launch mode starts the approved project with an explicit CLI', async () => {
  const calls = []
  const miniProgram = { id: 'launched' }
  const automator = {
    async connect() {
      throw new Error('connect should not be called')
    },
    async launch(options) {
      calls.push({ method: 'launch', options })
      return miniProgram
    }
  }

  const result = await openMiniProgram(automator, {
    launchDevTools: true,
    cliPath: 'C:/tools/wechat/cli.bat',
    projectPath: 'C:/workspace/project',
    port: 9420
  })

  assert.equal(result, miniProgram)
  assert.deepEqual(calls, [
    {
      method: 'launch',
      options: {
        cliPath: 'C:/tools/wechat/cli.bat',
        projectPath: 'C:/workspace/project',
        port: 9420,
        trustProject: true
      }
    }
  ])
})