-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Add unit tests for devtool ide-sdk command
- Loading branch information
1 parent
5145443
commit c23aac7
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
client/src/__tests__/unit-tests/ui/bitbake-commands.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* 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 * as vscode from 'vscode' | ||
import { BitbakeWorkspace } from '../../../ui/BitbakeWorkspace' | ||
import { BitBakeProjectScanner } from '../../../driver/BitBakeProjectScanner' | ||
import { BitbakeDriver } from '../../../driver/BitbakeDriver' | ||
import { registerDevtoolCommands } from '../../../ui/BitbakeCommands' | ||
import { clientNotificationManager } from '../../../ui/ClientNotificationManager' | ||
import * as BitbakeTerminal from '../../../ui/BitbakeTerminal' | ||
import * as ProcessUtils from '../../../lib/src/utils/ProcessUtils' | ||
|
||
jest.mock('vscode') | ||
|
||
function mockExtensionContext (bitbakeWorkspace: BitbakeWorkspace, bitBakeProjectScanner: BitBakeProjectScanner): any { | ||
const contextMock: vscode.ExtensionContext = { | ||
subscriptions: { | ||
push: jest.fn() | ||
} | ||
} as any | ||
|
||
let ideSDKCommand: any | ||
vscode.commands.registerCommand = jest.fn().mockImplementation( | ||
(command: string, callback: (...args: any[]) => any, thisArg?: any): void => { | ||
if (command === 'bitbake.devtool-ide-sdk') { | ||
ideSDKCommand = callback | ||
} | ||
}) | ||
registerDevtoolCommands(contextMock, bitbakeWorkspace, bitBakeProjectScanner) | ||
expect(ideSDKCommand).toBeDefined() | ||
return ideSDKCommand | ||
} | ||
|
||
describe('Devtool ide-sdk command', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should detect missing settings', async () => { | ||
const bitbakeWorkspace = new BitbakeWorkspace() | ||
const bitBakeProjectScanner = new BitBakeProjectScanner(new BitbakeDriver()) | ||
const ideSDKCommand = mockExtensionContext(bitbakeWorkspace, bitBakeProjectScanner) | ||
|
||
clientNotificationManager.showSDKConfigurationError = jest.fn() | ||
await ideSDKCommand('busybox') | ||
expect(clientNotificationManager.showSDKConfigurationError).toHaveBeenCalled() | ||
}) | ||
|
||
it('should detect ide-sdk missing', async () => { | ||
const bitbakeWorkspace = new BitbakeWorkspace() | ||
const bitBakeProjectScanner = new BitBakeProjectScanner(new BitbakeDriver()) | ||
bitBakeProjectScanner.bitbakeDriver.bitbakeSettings = { | ||
pathToBitbakeFolder: '', | ||
sdkImage: 'core-image-minimal' | ||
} | ||
const ideSDKCommand = mockExtensionContext(bitbakeWorkspace, bitBakeProjectScanner) | ||
|
||
jest.spyOn(BitbakeTerminal, 'runBitbakeTerminalCustomCommand').mockReturnValue(undefined as any) | ||
jest.spyOn(ProcessUtils, 'finishProcessExecution').mockReturnValue({ status: 1 } as any) | ||
|
||
clientNotificationManager.showSDKUnavailableError = jest.fn() | ||
await ideSDKCommand('busybox') | ||
expect(clientNotificationManager.showSDKUnavailableError).toHaveBeenCalled() | ||
}) | ||
|
||
it('should properly format ide-sdk command', async () => { | ||
const bitbakeWorkspace = new BitbakeWorkspace() | ||
const bitBakeProjectScanner = new BitBakeProjectScanner(new BitbakeDriver()) | ||
bitBakeProjectScanner.bitbakeDriver.bitbakeSettings = { | ||
pathToBitbakeFolder: '', | ||
sdkImage: 'core-image-minimal', | ||
sshTarget: '[email protected]' | ||
} | ||
const ideSDKCommand = mockExtensionContext(bitbakeWorkspace, bitBakeProjectScanner) | ||
|
||
const commandSpy = jest.spyOn(BitbakeTerminal, 'runBitbakeTerminalCustomCommand').mockReturnValue(undefined as any) | ||
jest.spyOn(ProcessUtils, 'finishProcessExecution').mockReturnValue({ status: 0 } as any) | ||
|
||
await ideSDKCommand('busybox') | ||
expect(commandSpy).toHaveBeenCalledWith(expect.anything(), 'devtool ide-sdk -i code busybox core-image-minimal -t [email protected]', expect.anything()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters