A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.
TypeScript amazon-primeelectronepic-games-launcherepic-games-storeepic-storegaminggoggog-galaxyheroic-games-launcherlinuxplay-gamesprotonsteamwine
import { existsSync } from 'graceful-fs'
import { GameConfig } from 'backend/game_config'
import { runWineCommand } from 'backend/launcher'
import { runPresetInstaller } from 'backend/storeManagers/sideload/presets'
import type { GameSettings } from 'common/types'
jest.mock('graceful-fs', (): typeof import('graceful-fs') => ({
...jest.requireActual<typeof import('graceful-fs')>('graceful-fs'),
existsSync: jest.fn()
}))
jest.mock('backend/launcher', () => ({ runWineCommand: jest.fn() }))
jest.mock('backend/game_config', () => ({ GameConfig: { get: jest.fn() } }))
jest.mock('backend/logger', () => ({
createGameLogWriter: jest.fn(() =>
Promise.resolve({ writeString: jest.fn() })
),
logInfo: jest.fn(),
logWarning: jest.fn(),
LogPrefix: { Sideload: 'Sideload' }
}))
jest.mock('backend/ipc', () => ({ sendFrontendMessage: jest.fn() }))
jest.mock('backend/utils', () => ({
downloadFile: jest.fn(),
spawnAsync: jest.fn()
}))
jest.mock('backend/constants/environment', () => ({ isWindows: false }))
jest.mock('backend/constants/paths', () => ({
gamesConfigPath: '/tmp/heroic/gamesConfig',
publicDir: '/tmp/heroic/public',
toolsPath: '/tmp/heroic/tools',
userDataPath: '/tmp/heroic/userData'
}))
const runWineCommandMock = jest.mocked(runWineCommand)
// eslint-disable-next-line @typescript-eslint/unbound-method
const gameConfigMock = jest.mocked(GameConfig.get)
const existsSyncMock = jest.mocked(existsSync)
const gameSettings = {
winePrefix: '/prefixes/preset-battlenet',
wineVersion: { bin: '/wine/bin/wine' }
} as unknown as GameSettings
describe('runPresetInstaller', () => {
beforeEach(() => {
jest.clearAllMocks()
existsSyncMock.mockReturnValue(true)
gameConfigMock.mockReturnValue({
config: gameSettings
} as unknown as ReturnType<typeof GameConfig.get>)
})
it('reports a clean install when the installer exits with 0', async () => {
runWineCommandMock.mockResolvedValue({
stdout: '',
stderr: '',
code: 0
})
await expect(runPresetInstaller('battlenet')).resolves.toEqual({
status: 'done'
})
})
it('reports the installer exit code when it fails', async () => {
runWineCommandMock.mockResolvedValue({
stdout: '',
stderr: '',
code: 1
})
await expect(runPresetInstaller('battlenet')).resolves.toEqual({
status: 'error',
error: 'installer-exit-1'
})
})
})