Skip to content

Chore/dbt-integration-tests #1718

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

Open
wants to merge 3 commits into
base: feat/extract-dbt-project
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
setupFilesAfterEnv: ["<rootDir>/src/test/setup.ts"],
reporters: ["default", ["summary", { summaryThreshold: 1 }]],
collectCoverageFrom: [
"src/**/*.{ts,tsx}",
"!src/test/**",
Expand Down
33 changes: 30 additions & 3 deletions src/test/mock/vscode.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { jest } from "@jest/globals";
import { Uri } from "vscode";

// Export VSCode types that were previously defined
export const ExtensionKind = {
UI: 1,
Workspace: 2,
};

export { Uri };
export const Uri = {
file: jest.fn((f: string) => ({ fsPath: f })),
parse: jest.fn(),
};

export class Position {
constructor(
Expand Down Expand Up @@ -110,6 +112,9 @@ export const window = {
hide: jest.fn(),
dispose: jest.fn(),
}),
withProgress: jest
.fn()
.mockImplementation((_options: any, task: any) => task()),
};

export const workspace = {
Expand All @@ -119,6 +124,12 @@ export const workspace = {
update: jest.fn(),
}),
workspaceFolders: [],
getWorkspaceFolder: jest.fn((uri: typeof Uri) => {
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
return workspace.workspaceFolders[0];
}
return undefined;
}),
onDidChangeConfiguration: jest.fn().mockReturnValue({ dispose: jest.fn() }),
onDidChangeWorkspaceFolders: jest
.fn()
Expand All @@ -129,11 +140,12 @@ export const workspace = {
onDidDelete: jest.fn().mockReturnValue({ dispose: jest.fn() }),
dispose: jest.fn(),
}),
};
} as any;

export const languages = {
createDiagnosticCollection: jest.fn().mockReturnValue({
set: jest.fn(),
get: jest.fn(),
delete: jest.fn(),
clear: jest.fn(),
dispose: jest.fn(),
Expand All @@ -152,6 +164,21 @@ export const languages = {
registerCodeLensProvider: jest.fn().mockReturnValue({ dispose: jest.fn() }),
};

export const EventEmitter = jest.fn().mockImplementation(() => ({
event: jest.fn().mockReturnValue({ dispose: jest.fn() }),
fire: jest.fn(),
dispose: jest.fn(),
}));

export const ProgressLocation = {
Notification: 15,
};

export const RelativePattern = jest.fn();
export const ViewColumn = {};
export const Disposable = jest.fn();
export const Event = jest.fn();

export const resetMocks = () => {
jest.clearAllMocks();
};
113 changes: 0 additions & 113 deletions src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,114 +1 @@
import "reflect-metadata";

// Set up the container before tests
import "../inversify.config";
import { MockEventEmitter } from "./common";

// Mock VS Code APIs before any imports
jest.mock("vscode", () => ({
EventEmitter: jest.fn().mockImplementation(() => new MockEventEmitter()),
workspace: {
getConfiguration: jest.fn().mockReturnValue({
get: jest.fn(),
update: jest.fn(),
}),
workspaceFolders: [],
onDidChangeConfiguration: jest.fn(),
onDidChangeWorkspaceFolders: jest.fn().mockImplementation((callback) => ({
dispose: jest.fn(),
})),
createFileSystemWatcher: jest.fn().mockReturnValue({
onDidChange: jest.fn(),
onDidCreate: jest.fn(),
onDidDelete: jest.fn(),
dispose: jest.fn(),
}),
},
commands: {
getCommands: jest.fn().mockResolvedValue([]),
registerCommand: jest.fn(),
executeCommand: jest.fn(),
},
window: {
showInformationMessage: jest.fn(),
showErrorMessage: jest.fn(),
createTerminal: jest.fn().mockReturnValue({
dispose: jest.fn(),
hide: jest.fn(),
show: jest.fn(),
sendText: jest.fn(),
}),
createOutputChannel: jest.fn().mockReturnValue({
appendLine: jest.fn(),
show: jest.fn(),
clear: jest.fn(),
dispose: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
}),
},
languages: {
createDiagnosticCollection: jest.fn().mockReturnValue({
set: jest.fn(),
delete: jest.fn(),
clear: jest.fn(),
dispose: jest.fn(),
}),
},
Uri: {
file: jest.fn((f: string) => ({ fsPath: f })),
parse: jest.fn(),
},
DiagnosticSeverity: {
Error: 0,
Warning: 1,
Information: 2,
Hint: 3,
},
Disposable: {
from: jest.fn(),
},
ExtensionKind: {
UI: 1,
Workspace: 2,
},
Diagnostic: jest.fn().mockImplementation((range, message, severity) => ({
range,
message,
severity,
})),
Range: jest
.fn()
.mockImplementation((startLine, startChar, endLine, endChar) => ({
start: { line: startLine, character: startChar },
end: { line: endLine, character: endChar },
})),
Position: jest.fn().mockImplementation((line, character) => ({
line,
character,
})),
TreeItemCollapsibleState: {
None: 0,
Collapsed: 1,
Expanded: 2,
},
TreeItem: jest.fn().mockImplementation((label, collapsibleState) => ({
label,
collapsibleState,
})),
CancellationTokenSource: jest.fn().mockImplementation(() => ({
token: {
onCancellationRequested: jest.fn(),
isCancellationRequested: false,
},
cancel: jest.fn(),
dispose: jest.fn(),
})),
CancellationToken: {
None: {
onCancellationRequested: jest.fn(),
isCancellationRequested: false,
},
},
}));
Loading