Skip to content

Commit

Permalink
Test: Add tests for eSDK mode
Browse files Browse the repository at this point in the history
  • Loading branch information
deribaucourt committed Jan 5, 2024
1 parent 11b7015 commit 94d5c78
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions client/src/__tests__/unit-tests/driver/eSDKMode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2023 Savoir-faire Linux. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { BitBakeProjectScanner } from '../../../driver/BitBakeProjectScanner'
import { BitbakeDriver } from '../../../driver/BitbakeDriver'
import { type BitbakeSettings } from '../../../lib/src/BitbakeSettings'
import * as BitbakeTerminal from '../../../ui/BitbakeTerminal'
import * as ProcessUtils from '../../../lib/src/utils/ProcessUtils'
import { setBitbakeESDKMode } from '../../../driver/BitbakeESDK'
import fs, { type PathLike } from 'fs'

// Yocto's eSDKs contain devtool but not bitbake. These tests ensure we can still provide devtool functionalities without bitbake.
describe('Devtool eSDK Mode Test Suite', () => {
afterEach(() => {
jest.clearAllMocks()
setBitbakeESDKMode(false)
})

it('should pass sanity check without bitbake', async () => {
const bitbakeSettings: BitbakeSettings = {
pathToBitbakeFolder: 'nonexistent',
workingDirectory: '/path/to/workspace',
commandWrapper: '',
pathToEnvScript: 'fakeEnvScript',
pathToBuildFolder: 'nonexistent'
}
const bitbakeDriver = new BitbakeDriver()
bitbakeDriver.loadSettings(bitbakeSettings, '/path/to/workspace')

setBitbakeESDKMode(true)
const bitbakeTerminalSpy = jest.spyOn(BitbakeTerminal, 'runBitbakeTerminalCustomCommand').mockImplementation(async () => undefined as any)
const bitbakeExecutionSpy = jest.spyOn(ProcessUtils, 'finishProcessExecution').mockImplementation(async () => undefined as any)
const fsExistsSpy = jest.spyOn(fs, 'existsSync').mockImplementation((path: PathLike) => {
return path.toString().includes(bitbakeSettings.pathToEnvScript as string)
})

bitbakeExecutionSpy.mockReturnValueOnce(Promise.resolve({
status: 0
} as any))
const bitbakeSanity = await bitbakeDriver.checkBitbakeSettingsSanity()
expect(fsExistsSpy).toHaveBeenCalledWith(expect.stringContaining(bitbakeSettings.pathToEnvScript as string))
expect(bitbakeTerminalSpy).toHaveBeenCalledWith(expect.anything(), expect.stringContaining('which devtool'), expect.anything(), expect.anything())
expect(bitbakeSanity).toStrictEqual(true)
})

it('should scan devtool without bitbake', async () => {
const bitbakeDriver = new BitbakeDriver()
const bitBakeProjectScanner = new BitBakeProjectScanner(bitbakeDriver)
setBitbakeESDKMode(true)

const scanAvailableLayersSpy = jest.spyOn(bitBakeProjectScanner as any, 'scanAvailableLayers').mockImplementation(async () => {})
const scanForRecipesSpy = jest.spyOn(bitBakeProjectScanner as any, 'scanForRecipes').mockImplementation(async () => {})
const parseAllRecipesSpy = jest.spyOn(bitBakeProjectScanner as any, 'parseAllRecipes').mockImplementation(async () => {})
const scanDevtoolWorkspaces = jest.spyOn(bitBakeProjectScanner as any, 'scanDevtoolWorkspaces').mockImplementation(async () => {})

await bitBakeProjectScanner.rescanProject()

expect(scanDevtoolWorkspaces).toHaveBeenCalled()
expect(scanAvailableLayersSpy).not.toHaveBeenCalled()
expect(scanForRecipesSpy).not.toHaveBeenCalled()
expect(parseAllRecipesSpy).not.toHaveBeenCalled()
})
})

0 comments on commit 94d5c78

Please sign in to comment.