-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add client tests #29
Add client tests #29
Changes from all commits
6d4e01d
1afb29e
3ba2797
809523a
ed76165
a27c5fa
6a31a2b
4e3591e
e8c7a1c
4effef2
a2f0eaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Jtest Mock from https://github.com/jest-community/vscode-jest/blob/1867bde9ebf8c21d45409e7ad8a95a743ac4390d/__mocks__/vscode.ts | ||
// under MIT License | ||
|
||
const languages = { | ||
createDiagnosticCollection: jest.fn(), | ||
registerCodeLensProvider: jest.fn(), | ||
}; | ||
|
||
const StatusBarAlignment = { Left: 1, Right: 2 }; | ||
|
||
const window = { | ||
createStatusBarItem: jest.fn(() => ({ | ||
show: jest.fn(), | ||
hide: jest.fn(), | ||
tooltip: jest.fn(), | ||
})), | ||
showErrorMessage: jest.fn(), | ||
showWarningMessage: jest.fn(), | ||
createTextEditorDecorationType: jest.fn(), | ||
createOutputChannel: jest.fn(), | ||
showWorkspaceFolderPick: jest.fn(), | ||
showQuickPick: jest.fn(), | ||
onDidChangeActiveTextEditor: jest.fn(), | ||
showInformationMessage: jest.fn(), | ||
createWebviewPanel: jest.fn(), | ||
}; | ||
|
||
const workspace = { | ||
getConfiguration: jest.fn(), | ||
workspaceFolders: [], | ||
getWorkspaceFolder: jest.fn(), | ||
|
||
onDidChangeConfiguration: jest.fn(), | ||
onDidChangeTextDocument: jest.fn(), | ||
onDidChangeWorkspaceFolders: jest.fn(), | ||
onDidCreateFiles: jest.fn(), | ||
onDidDeleteFiles: jest.fn(), | ||
onDidRenameFiles: jest.fn(), | ||
onDidSaveTextDocument: jest.fn(), | ||
onWillSaveTextDocument: jest.fn(), | ||
}; | ||
|
||
const OverviewRulerLane = { | ||
Left: null, | ||
}; | ||
|
||
const Uri = { | ||
file: (f: any) => f, | ||
parse: jest.fn(), | ||
joinPath: jest.fn(), | ||
}; | ||
const Range = jest.fn(); | ||
const Location = jest.fn(); | ||
const Position = jest.fn(); | ||
const Diagnostic = jest.fn(); | ||
const ThemeIcon = jest.fn(); | ||
const DiagnosticSeverity = { Error: 0, Warning: 1, Information: 2, Hint: 3 }; | ||
const ConfigurationTarget = { Global: 1, Workspace: 2, WorkspaceFolder: 3 }; | ||
|
||
const debug = { | ||
onDidTerminateDebugSession: jest.fn(), | ||
startDebugging: jest.fn(), | ||
registerDebugConfigurationProvider: jest.fn(), | ||
}; | ||
|
||
const commands = { | ||
executeCommand: jest.fn(), | ||
registerCommand: jest.fn(), | ||
registerTextEditorCommand: jest.fn(), | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const CodeLens = function CodeLens() {}; | ||
|
||
const QuickInputButtons = { | ||
Back: {}, | ||
}; | ||
|
||
const tests = { | ||
createTestController: jest.fn(), | ||
}; | ||
|
||
const TestRunProfileKind = { | ||
Run: 1, | ||
Debug: 2, | ||
Coverage: 3, | ||
}; | ||
const ViewColumn = { | ||
One: 1, | ||
Tow: 2, | ||
}; | ||
|
||
const TestMessage = jest.fn(); | ||
const TestRunRequest = jest.fn(); | ||
const ThemeColor = jest.fn(); | ||
|
||
const EventEmitter = jest.fn().mockImplementation(() => { | ||
return { | ||
fire: jest.fn(), | ||
}; | ||
}); | ||
|
||
const QuickPickItemKind = { | ||
Separator: -1, | ||
Default: 0, | ||
}; | ||
|
||
export = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my side typescript complains it is using the CommonJS syntax, while the EcmaScript syntaxt should be used ( I am not sure where is exactly the problem, but I noticed .eslintrc.js is also using a commonjs export. I also noticed you put this file into "ignorePatterns". I am thinking this was an attempt to solve that problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file comes from another repo and works fine. As long as we don't change it, it makes no sense to me to test it's linting, which follows a different standard in another project. Also it makes it easy to update this file in the future when the vscode API changes/adds new features. I suggest to ignore linting this file and keep it as original. A comment at the top clearly indicates where it comes from. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. However I am surprised it works. Both syntaxes are not supposed to be interchangeable within a project. As a proof, this file does not compile if you use the ecmascript syntax. It makes me think the "root project" is not configured properly. |
||
ThemeColor, | ||
CodeLens, | ||
languages, | ||
StatusBarAlignment, | ||
window, | ||
workspace, | ||
OverviewRulerLane, | ||
Uri, | ||
Range, | ||
Location, | ||
Position, | ||
Diagnostic, | ||
ThemeIcon, | ||
DiagnosticSeverity, | ||
ConfigurationTarget, | ||
debug, | ||
commands, | ||
QuickInputButtons, | ||
tests, | ||
TestRunProfileKind, | ||
EventEmitter, | ||
TestMessage, | ||
TestRunRequest, | ||
ViewColumn, | ||
QuickPickItemKind, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2023 Savoir-faire Linux. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
test('two plus three is five', () => { | ||
expect(2 + 3).toBe(5) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* 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 { logger } from '../../ui/OutputLogger' | ||
|
||
jest.mock('vscode') | ||
|
||
const mockLoggerConfiguration = (loggingLevel: string): void => { | ||
vscode.workspace.getConfiguration = jest.fn().mockImplementation(() => ({ | ||
get: () => loggingLevel | ||
})) | ||
} | ||
|
||
const mockChannel = (): jest.Mocked<any> => { | ||
const mockOutputChannel = { | ||
appendLine: jest.fn(), | ||
show: jest.fn(), | ||
clear: jest.fn() | ||
} | ||
|
||
vscode.window.createOutputChannel = jest.fn().mockImplementation(() => mockOutputChannel) | ||
|
||
return mockOutputChannel | ||
} | ||
|
||
describe('OutputLogger Tests', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should define a singleton logger instance', () => { | ||
expect(logger).toBeDefined() | ||
}) | ||
|
||
it('should correctly log messages with appropriate log level', () => { | ||
const mockOutputChannel = mockChannel() | ||
mockLoggerConfiguration('warning') | ||
|
||
logger.setOutputChannel(vscode.window.createOutputChannel('Bitbake')) | ||
logger.loadSettings() | ||
|
||
const logSpy = jest.spyOn(mockOutputChannel, 'appendLine') | ||
|
||
logger.debug('Debug message') | ||
logger.info('Info message') | ||
logger.warning('Warning message') | ||
logger.error('Error message') | ||
|
||
expect(logSpy).toHaveBeenCalledTimes(2) | ||
expect(logSpy).toHaveBeenCalledWith('Warning message') | ||
expect(logSpy).toHaveBeenCalledWith('Error message') | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is weird here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in another comment, I suggest keeping the original file and not changing it's linting rules.