Skip to content

Commit

Permalink
fix: tests, address todo [ROAD-189] (#34)
Browse files Browse the repository at this point in the history
* fix: tests, address todo

* fix: remove redundant emitter
  • Loading branch information
michelkaporin authored Aug 2, 2021
1 parent c911070 commit 27ba2d2
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 39 deletions.
22 changes: 13 additions & 9 deletions src/snyk/lib/analyzer/SnykAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,27 @@ class SnykAnalyzer implements AnalyzerInterface {
updatedFile: openedTextEditorType,
): Promise<void> {
try {
const isSecurityReviewFile = this.codeSecurityReview && this.codeSecurityReview.has(updatedFile.document.uri);
const isQualityReviewFile = this.codeQualityReview && this.codeQualityReview.has(updatedFile.document.uri);

if (
!this.codeSecurityReview ||
!this.codeSecurityReview.has(updatedFile.document.uri) ||
(!isSecurityReviewFile && !isQualityReviewFile) ||
!updatedFile.contentChanges.length ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
!updatedFile.contentChanges[0].range
) {
return;
}
const fileIssuesList: IFilePath = updateFileReviewResultsPositions(this.analysisResults, updatedFile);
if (this.codeSecurityReview) {
const [securityIssues, qualityIssues] = this.createIssuesList({
fileIssuesList,
suggestions: this.analysisResults.suggestions,
fileUri: vscode.Uri.file(updatedFile.fullPath),
});
this.codeSecurityReview.set(vscode.Uri.file(updatedFile.fullPath), [...securityIssues]); // todo
const [securityIssues, qualityIssues] = this.createIssuesList({
fileIssuesList,
suggestions: this.analysisResults.suggestions,
fileUri: vscode.Uri.file(updatedFile.fullPath),
});
if (isSecurityReviewFile) {
this.codeSecurityReview?.set(vscode.Uri.file(updatedFile.fullPath), [...securityIssues]);
} else if (isQualityReviewFile) {
this.codeQualityReview?.set(vscode.Uri.file(updatedFile.fullPath), [...qualityIssues]);
}
} catch (err) {
await extension.processError(err, {
Expand Down
2 changes: 1 addition & 1 deletion src/snyk/lib/modules/ReportModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class ReportModule extends BaseSnykModule implements ReportModuleInterf

constructor() {
super();
this.loadingBadge = new LoadingBadge(this.viewManagerService);
this.loadingBadge = new LoadingBadge();
}

private static get shouldReport(): boolean {
Expand Down
13 changes: 2 additions & 11 deletions src/snyk/services/viewManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { EventEmitter, TreeView } from 'vscode';
import { configuration, FeaturesConfiguration } from '../configuration';
import { REFRESH_VIEW_DEBOUNCE_INTERVAL } from '../constants/general';
import { PendingTask, PendingTaskInterface } from '../utils/pendingTask';
import { TreeNode } from '../view/treeNode';
import { FeaturesViewProvider } from '../view/welcome/welcomeViewProvider';
import { Node } from './../view/node';

export type ViewType = FeaturesViewProvider | TreeView<Node>;
export type ViewType = FeaturesViewProvider | TreeView<TreeNode>;

export class ViewContainer {
private container = new Map<string, ViewType>();
Expand All @@ -23,9 +23,6 @@ export class ViewContainer {
export interface IViewManagerService {
viewContainer: ViewContainer;

initializedView: PendingTaskInterface;
emitViewInitialized(): void;

readonly refreshCodeSecurityViewEmitter: EventEmitter<void>;
readonly refreshCodeQualityViewEmitter: EventEmitter<void>;
refreshCodeSecurityView(): void;
Expand All @@ -37,21 +34,15 @@ export interface IViewManagerService {
export class ViewManagerService implements IViewManagerService {
readonly viewContainer: ViewContainer;

readonly initializedView: PendingTaskInterface;
readonly refreshCodeSecurityViewEmitter: EventEmitter<void>;
readonly refreshCodeQualityViewEmitter: EventEmitter<void>;

constructor() {
this.initializedView = new PendingTask();
this.refreshCodeSecurityViewEmitter = new EventEmitter<void>();
this.refreshCodeQualityViewEmitter = new EventEmitter<void>();
this.viewContainer = new ViewContainer();
}

emitViewInitialized(): void {
if (!this.initializedView.isCompleted) this.initializedView.complete();
}

refreshAllAnalysisViews(): void {
this.refreshCodeSecurityView();
this.refreshCodeQualityView();
Expand Down
2 changes: 0 additions & 2 deletions src/snyk/view/code/qualityIssueProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export class CodeQualityIssueProvider extends IssueProvider {
}

getRootChildren(): TreeNode[] {
this.viewManagerService.emitViewInitialized();

if (!configuration.getFeaturesConfiguration()?.codeQualityEnabled) {
return [
new TreeNode({
Expand Down
2 changes: 0 additions & 2 deletions src/snyk/view/code/securityIssueProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export class CodeSecurityIssueProvider extends IssueProvider {
}

getRootChildren(): TreeNode[] {
this.viewManagerService.emitViewInitialized();

if (!configuration.getFeaturesConfiguration()?.codeSecurityEnabled) {
return [
new TreeNode({
Expand Down
12 changes: 2 additions & 10 deletions src/snyk/view/loadingBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as vscode from 'vscode';
import { BaseSnykModuleInterface } from '../../interfaces/SnykInterfaces';
import { SNYK_VIEW_WELCOME } from '../constants/views';
import { errorsLogs } from '../messages/errorsServerLogMessages';
import { IViewManagerService } from '../services/viewManagerService';
import { PendingTask, PendingTaskInterface } from '../utils/pendingTask';

export interface ILoadingBadge {
Expand All @@ -13,8 +12,6 @@ export class LoadingBadge implements ILoadingBadge {
private progressBadge: PendingTaskInterface | undefined;
private shouldShowProgressBadge = false;

constructor(private viewManagerService: IViewManagerService) {}

private getProgressBadgePromise(): Promise<void> {
if (!this.shouldShowProgressBadge) return Promise.resolve();
if (!this.progressBadge || this.progressBadge.isCompleted) {
Expand All @@ -30,13 +27,8 @@ export class LoadingBadge implements ILoadingBadge {
// Using closure on this to allow partial binding in arbitrary positions
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this.viewManagerService.initializedView.waiter
.then(
() =>
vscode.window.withProgress({ location: { viewId: SNYK_VIEW_WELCOME } }, () =>
self.getProgressBadgePromise(),
), // todo check if correct with respect to security/quality split
)
vscode.window
.withProgress({ location: { viewId: SNYK_VIEW_WELCOME } }, () => self.getProgressBadgePromise())
.then(
() => undefined,
error =>
Expand Down
4 changes: 2 additions & 2 deletions src/test/integration/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strictEqual } from 'assert';
import { deepStrictEqual, strictEqual } from 'assert';
import { configuration } from '../../snyk/configuration';

suite('Configuration', () => {
Expand All @@ -24,7 +24,7 @@ suite('Configuration', () => {
await configuration.setShouldReportEvents(false);

strictEqual(configuration.token, token);
strictEqual(configuration.getFeaturesConfiguration(), featuresConfig);
deepStrictEqual(configuration.getFeaturesConfiguration(), featuresConfig);
strictEqual(configuration.shouldReportEvents, false);
await configuration.setToken('');
});
Expand Down
4 changes: 2 additions & 2 deletions src/test/integration/viewNavigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { configuration } from '../../snyk/configuration';
import { getExtension } from '../../extension';
import { SNYK_VIEW_FEATURES, SNYK_VIEW_WELCOME } from '../../snyk/constants/views';
import { TreeView } from 'vscode';
import { Node } from '../../snyk/view/node';
import { FeaturesViewProvider } from '../../snyk/view/welcome/welcomeViewProvider';
import { TreeNode } from '../../snyk/view/treeNode';

suite('View Navigation', () => {
setup(async () => {
Expand All @@ -19,7 +19,7 @@ suite('View Navigation', () => {
test('"Feature view is seen after user authenticates within welcome view', async () => {
const extension = getExtension();
const viewContainer = extension.viewManagerService.viewContainer;
const welcomeTree = viewContainer.get<TreeView<Node>>(SNYK_VIEW_WELCOME);
const welcomeTree = viewContainer.get<TreeView<TreeNode>>(SNYK_VIEW_WELCOME);

// 1. Check welcome view is visible
strictEqual(welcomeTree?.visible, true);
Expand Down

0 comments on commit 27ba2d2

Please sign in to comment.