| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { tmpdir } from 'node:os'
- import { Arch, Platform } from 'electron-builder'
- import { Packager } from 'app-builder-lib'
- import { describe, expect, it, vi } from 'vitest'
- const { execute } = vi.hoisted(() => ({ execute: vi.fn(async () => undefined) }))
- vi.mock('node:child_process', async (importOriginal) => {
- const original = await importOriginal<typeof import('node:child_process')>()
- const { promisify } = await import('node:util')
- return { ...original, execFile: Object.assign(vi.fn(), { [promisify.custom]: execute }) }
- })
- describe('installer preparation preserves application dependencies', () => {
- it.each(['win32', 'darwin'] as const)('keeps electron-builder responsible for node_modules on %s', async (platform) => {
- execute.mockClear()
- const env = {
- DSH_DESKTOP_APP_ID: 'com.example.installer',
- DSH_DESKTOP_TARGET_PLATFORM: platform,
- DSH_DESKTOP_TARGET_ARCH: 'x64',
- DSH_DESKTOP_UNSIGNED: platform === 'win32' ? '1' : '0',
- DSH_DESKTOP_MACOS_SIGNING_IDENTITY: 'Example Company (TEAMID1234)',
- DSH_DESKTOP_MACOS_TEAM_ID: 'TEAMID1234',
- APPLE_KEYCHAIN_PROFILE: 'installer-test',
- DOWNLOAD_TEST_ORIGIN: 'https://desktop-updates.example.com',
- }
- for (const [name, value] of Object.entries(env)) vi.stubEnv(name, value)
- try {
- const { createElectronBuilderConfig } = await import('../electron-builder.config.mjs')
- const config = createElectronBuilderConfig(env, platform, 'x64')
- const packager = new Packager({ projectDir: tmpdir() })
- // A foreign source-build target avoids rebuilding modules; the real dependency ownership decision still runs.
- Object.defineProperties(packager, {
- config: { value: { beforeBuild: config.beforeBuild, buildDependenciesFromSource: true } },
- framework: { value: { isNpmRebuildRequired: true, version: '42.0.0' } },
- appInfo: { value: { type: 'module' } },
- })
- vi.spyOn(packager, 'getWorkspaceRoot').mockResolvedValue(tmpdir())
- await packager.installAppDependencies(process.platform === 'win32' ? Platform.LINUX : Platform.WINDOWS, Arch.x64)
- expect(packager.areNodeModulesHandledExternally).toBe(false)
- expect(execute).toHaveBeenCalledTimes(platform === 'win32' ? 1 : 0)
- } finally {
- vi.unstubAllEnvs()
- vi.restoreAllMocks()
- }
- })
- })
|