Skip to content
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 tests for vscode extension #328

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
7 changes: 6 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: "16.x"
- run: |
- name: Install dependencies
run: |
cd vscode
npm install
npm install -g @vscode/vsce
- name: Test
run: |
cd vscode
npm test
- name: Lint
run: |
cd vscode
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ repos:
hooks:
- id: gitlint
- repo: https://github.com/crate-ci/typos
rev: v1.16.19
rev: v1.19.0
hooks:
- id: typos
exclude: "vscode/package-lock.json"
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.37.0
rev: v0.39.0
hooks:
- id: markdownlint-fix
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -29,7 +29,7 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
rev: v3.1.0
hooks:
- id: prettier
files: (^vscode|\.yml)
1 change: 1 addition & 0 deletions vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# VS Code extension build directories
node_modules
out
coverage
*.vsix
1 change: 0 additions & 1 deletion vscode/.prettierignore

This file was deleted.

87 changes: 87 additions & 0 deletions vscode/__mocks__/vscode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const languages = {
createDiagnosticCollection: jest.fn(),
};

const StatusBarAlignment = {};

const window = {
createStatusBarItem: jest.fn(() => ({
show: jest.fn(),
})),
showErrorMessage: jest.fn(),
showWarningMessage: jest.fn(),
createTextEditorDecorationType: jest.fn(),
createOutputChannel: jest.fn(),
showInformationMessage: jest.fn(),
};

const ConfigurationTarget = {
Global: 1,
};

const workspace = {
getConfiguration: jest.fn(),
workspaceFolders: [],
onDidSaveTextDocument: jest.fn(),
};

const env = {
openExternal: jest.fn(),
};

const OverviewRulerLane = {
Left: null,
};

const Uri = {
file: (f) => f,
parse: jest.fn(),
};
const Range = jest.fn();
const Diagnostic = jest.fn();
const DiagnosticSeverity = { Error: 0, Warning: 1, Information: 2, Hint: 3 };
const CompletionItem = jest.fn();
const CodeAction = jest.fn();
const CodeLens = jest.fn();
const DocumentLink = jest.fn();
const CallHierarchyItem = jest.fn();
const TypeHierarchyItem = jest.fn();
const SymbolInformation = jest.fn();
const InlayHint = jest.fn();
const CancellationError = jest.fn();

const debug = {
onDidTerminateDebugSession: jest.fn(),
startDebugging: jest.fn(),
};

const commands = {
executeCommand: jest.fn(),
};

const vscode = {
CallHierarchyItem,
CancellationError,
CodeAction,
CodeLens,
CompletionItem,
ConfigurationTarget,
Diagnostic,
DiagnosticSeverity,
DocumentLink,
InlayHint,
OverviewRulerLane,
Range,
StatusBarAlignment,
SymbolInformation,
TypeHierarchyItem,
Uri,
commands,
debug,
env,
languages,
window,
workspace,
};

module.exports = vscode;
9 changes: 9 additions & 0 deletions vscode/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
transform: {
"^.+\\.ts?$": "ts-jest",
},
transformIgnorePatterns: ["<rootDir>/node_modules/"],
collectCoverage: true,
};
Loading
Loading