Skip to content

Commit

Permalink
[Fix] Duplicate kill listener (#1944)
Browse files Browse the repository at this point in the history
* rm duplicate kill

* rm yarn test pre push

* skip tests if os not compatible

* add sideload code to kill

* add logging to skipped tests
  • Loading branch information
BrettCleary committed Oct 27, 2022
1 parent 1e01cb2 commit 369ff67
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
yarn codecheck && yarn lint && yarn prettier-fix && yarn test && yarn i18n
yarn codecheck && yarn lint && yarn prettier-fix && yarn i18n
10 changes: 10 additions & 0 deletions src/backend/logger/__tests__/logfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { app } from 'electron'
import { configStore } from '../../constants'
import * as logfile from '../logfile'
import { logError } from '../logger'
import { platform } from 'os'

jest.mock('electron')
jest.mock('electron-store')
Expand All @@ -14,7 +15,16 @@ jest.unmock('../logfile')

let tmpDir = {} as DirResult

const shouldSkip = platform() === 'win32'
const skipMessage = 'on windows so skipping test'
const emptyTest = it('should do nothing', () => {})

describe('logger/logfile.ts', () => {
if (shouldSkip) {
console.log(skipMessage)
emptyTest
return
}
beforeEach(() => {
tmpDir = dirSync({ unsafeCleanup: true })
})
Expand Down
10 changes: 10 additions & 0 deletions src/backend/logger/__tests__/logger.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as logger from '../logger'
import { appendMessageToLogFile } from '../logfile'
import { showDialogBoxModalAuto } from '../../dialog/dialog'
import { platform } from 'os'

jest.mock('../logfile')
jest.mock('../../dialog/dialog')
Expand Down Expand Up @@ -39,7 +40,16 @@ function getStringPassedToLogFile(type: logLevel, skipMessagePrefix = false) {
].join('\n')
}

const shouldSkip = platform() === 'win32'
const skipMessage = 'on windows so skipping test'
const emptyTest = it('should do nothing', () => {})

describe('logger/logger.ts', () => {
if (shouldSkip) {
console.log(skipMessage)
emptyTest
return
}
afterEach(jest.restoreAllMocks)

test('log invokes console', () => {
Expand Down
9 changes: 3 additions & 6 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ import {
getAppSettings,
isNativeApp,
launchApp,
removeApp
removeApp,
stop
} from './sideload/games'
import { callAbortController } from './utils/aborthandler/aborthandler'

Expand Down Expand Up @@ -559,10 +560,6 @@ ipcMain.on('unlock', () => {
}
})

ipcMain.handle('kill', async (event, appName, runner) => {
return getGame(appName, runner).stop()
})

ipcMain.handle('checkDiskSpace', async (event, folder: string) => {
const parent = getFirstExistingParentPath(folder)
return new Promise((res) => {
Expand Down Expand Up @@ -1326,7 +1323,7 @@ ipcMain.handle(

ipcMain.handle('kill', async (event, appName, runner) => {
callAbortController(appName)
return getGame(appName, runner).stop()
return runner === 'sideload' ? stop(appName) : getGame(appName, runner).stop()
})

ipcMain.handle('updateGame', async (event, appName, runner) => {
Expand Down
20 changes: 20 additions & 0 deletions src/backend/wine/runtimes/__tests__/runtimes/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
// @ts-ignore: Don't know why ts complains about it.
import { test_data } from './test_data/github-api-heroic-test-data.json'
import { dirSync } from 'tmp'
import { platform } from 'os'

const testUrl =
'https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases/download/v2.3.9/Heroic-2.3.9.AppImage'
Expand All @@ -22,7 +23,16 @@ const testTarFileWithSubfolder = join(

afterEach(jest.restoreAllMocks)

const shouldSkip = platform() !== 'linux'
const skipMessage = 'not on linux so skipping test'
const emptyTest = it('should do nothing', () => {})

describe('getAssetDataFromDownload', () => {
if (shouldSkip) {
console.log(skipMessage)
emptyTest
return
}
it('Success', async () => {
// https://stackoverflow.com/a/43047378
jest.spyOn(axios, 'get').mockResolvedValue(test_data)
Expand Down Expand Up @@ -76,6 +86,11 @@ describe('getAssetDataFromDownload', () => {
})

describe('downloadFile', () => {
if (shouldSkip) {
console.log(skipMessage)
emptyTest
return
}
it('Success', async () => {
const expectedData = readFileSync(testTarFilePath)

Expand Down Expand Up @@ -151,6 +166,11 @@ describe('downloadFile', () => {
})

describe('extractTarFile', () => {
if (shouldSkip) {
console.log(skipMessage)
emptyTest
return
}
it('Success without strip', async () => {
const tmpDir = dirSync({ unsafeCleanup: true })
jest.spyOn(child_process, 'spawn')
Expand Down

0 comments on commit 369ff67

Please sign in to comment.