source-entry.test.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { mkdtemp, rm } from 'node:fs/promises'
  4. import { tmpdir } from 'node:os'
  5. import { join, resolve } from 'node:path'
  6. import { _electron as electron } from '@playwright/test'
  7. const root = resolve(import.meta.dirname, '..')
  8. // Both staged variants coexist after packaging. The source entry must use the
  9. // requested variant's manifest and policy without moving either build marker.
  10. for (const clientOnly of [false, true]) {
  11. test(`source entry selects the ${clientOnly ? 'client' : 'full'} staged variant`, { timeout: 45000 }, async () => {
  12. const home = await mkdtemp(join(tmpdir(), 'yaoyao-source-entry-'))
  13. let app
  14. try {
  15. app = await electron.launch({ args: [root], cwd: root, env: { ...process.env,
  16. HERMES_YAOYAO_DESKTOP_TEST_HOME: home, HERMES_YAOYAO_DESKTOP_TEST_MODE: 'ask',
  17. HERMES_YAOYAO_DESKTOP_CLIENT_ONLY: clientOnly ? '1' : '0', HERMES_YAOYAO_DESKTOP_PORT: '1',
  18. HERMES_YAOYAO_DESKTOP_TEST_SYNC: '0' }, timeout: 30000 })
  19. const page = await app.firstWindow()
  20. await page.waitForURL(/boot\.html$/)
  21. assert.equal(await app.evaluate(({ app }) => app.getName()), clientOnly ? '夭夭' : '夭夭完整版')
  22. const state = await page.evaluate(() => window.yaoyaoDesktop.status())
  23. assert.deepEqual(state.supportedModes, !clientOnly && process.platform === 'darwin' ? ['client', 'server'] : ['client'])
  24. assert.equal(state.mode, !clientOnly && process.platform === 'darwin' ? null : 'remote')
  25. } finally {
  26. await app?.close().catch(() => {})
  27. await rm(home, { recursive: true, force: true })
  28. }
  29. })
  30. }