package-target.spec.ts 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { describe, expect, it } from 'vitest'
  2. import {
  3. desktopElectronBuilderArguments,
  4. parseDesktopPackageInvocation,
  5. resolveDesktopPackageTarget,
  6. withoutDesktopUploadCredentials,
  7. withoutWindowsSigningEnvironment,
  8. } from '../scripts/package-target.ts'
  9. describe('desktop package target', () => {
  10. it('selects matching runtime and electron-builder architectures', () => {
  11. expect(resolveDesktopPackageTarget('mac-arm64', 'darwin', 'arm64')).toMatchObject({
  12. platform: 'darwin', arch: 'arm64', builderPlatform: '--mac', builderArch: '--arm64',
  13. })
  14. expect(resolveDesktopPackageTarget('mac-x64', 'darwin', 'x64')).toMatchObject({
  15. platform: 'darwin', arch: 'x64', builderPlatform: '--mac', builderArch: '--x64',
  16. })
  17. expect(resolveDesktopPackageTarget('win-x64', 'win32', 'x64')).toMatchObject({
  18. platform: 'win32', arch: 'x64', builderPlatform: '--win', builderArch: '--x64',
  19. })
  20. })
  21. it('allows an Apple Silicon host to build the Intel target through Rosetta', () => {
  22. expect(resolveDesktopPackageTarget('mac-x64', 'darwin', 'arm64').arch).toBe('x64')
  23. })
  24. it('rejects unsupported targets and hosts before building', () => {
  25. expect(() => resolveDesktopPackageTarget('linux-x64', 'linux', 'x64')).toThrow(/unsupported target/u)
  26. expect(() => resolveDesktopPackageTarget('win-x64', 'darwin', 'arm64')).toThrow(/Windows x64/u)
  27. expect(() => resolveDesktopPackageTarget('mac-arm64', 'darwin', 'x64')).toThrow(/Apple Silicon/u)
  28. expect(() => resolveDesktopPackageTarget('mac-arm64', 'linux', 'arm64')).toThrow(/macOS/u)
  29. expect(() => resolveDesktopPackageTarget('mac-x64', 'darwin', 'ppc64')).toThrow(/Rosetta/u)
  30. })
  31. it('parses installer and unpacked-directory invocations', () => {
  32. expect(parseDesktopPackageInvocation(['mac-arm64'], 'darwin', 'arm64').directory).toBe(false)
  33. expect(parseDesktopPackageInvocation(['mac-arm64', '--dir'], 'darwin', 'arm64').directory).toBe(true)
  34. expect(parseDesktopPackageInvocation([], 'darwin', 'arm64').target.name).toBe('mac-arm64')
  35. expect(parseDesktopPackageInvocation(['--prepare-only'], 'darwin', 'arm64').prepareOnly).toBe(true)
  36. expect(() => parseDesktopPackageInvocation(['mac-arm64', 'mac-x64'], 'darwin', 'arm64'))
  37. .toThrow(/at most one target/u)
  38. })
  39. it('keeps electron-builder publishing disabled for the separate validated upload', () => {
  40. const target = resolveDesktopPackageTarget('mac-arm64', 'darwin', 'arm64')
  41. expect(desktopElectronBuilderArguments(target, false)).toEqual([
  42. 'exec',
  43. 'electron-builder',
  44. '--config',
  45. 'electron-builder.config.mjs',
  46. '--mac',
  47. '--arm64',
  48. '--publish',
  49. 'never',
  50. ])
  51. expect(desktopElectronBuilderArguments(target, true)).toContain('--dir')
  52. })
  53. it('keeps Windows signing fields out of build and seed preparation subprocesses', () => {
  54. expect(withoutWindowsSigningEnvironment({
  55. DSH_DESKTOP_WINDOWS_CER_FILE: 'C:\\release\\server.cer',
  56. DSH_DESKTOP_WINDOWS_TOKEN_PIN: 'token-secret',
  57. DSH_DESKTOP_WINDOWS_KEY_CONTAINER: 'container',
  58. DSH_DESKTOP_WINDOWS_SIGNTOOL: 'C:\\tools\\signtool.exe',
  59. DSH_DESKTOP_AUTO_UPDATE_ENV: 'production',
  60. })).toEqual({ DSH_DESKTOP_AUTO_UPDATE_ENV: 'production' })
  61. })
  62. it('keeps COS credentials out of every packaging subprocess', () => {
  63. expect(withoutDesktopUploadCredentials({
  64. DOWNLOAD_TEST_ORIGIN: 'https://desktop-updates.example.com',
  65. DOWNLOAD_TEST_COS_BUCKET: 'test-download-bucket',
  66. DOWNLOAD_TEST_COS_SECRET_ID: 'test-id',
  67. DOWNLOAD_TEST_COS_SECRET_KEY: 'test-key',
  68. DOWNLOAD_PROD_COS_BUCKET: 'production-download-bucket',
  69. DOWNLOAD_PROD_COS_SECRET_ID: 'production-id',
  70. DOWNLOAD_PROD_COS_SECRET_KEY: 'production-key',
  71. DSH_DESKTOP_AUTO_UPDATE_ENV: 'production',
  72. })).toEqual({
  73. DOWNLOAD_TEST_ORIGIN: 'https://desktop-updates.example.com',
  74. DOWNLOAD_TEST_COS_BUCKET: 'test-download-bucket',
  75. DOWNLOAD_PROD_COS_BUCKET: 'production-download-bucket',
  76. DSH_DESKTOP_AUTO_UPDATE_ENV: 'production',
  77. })
  78. })
  79. })