Skip to content

Commit

Permalink
feat: introduce unit and integration test core (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
michelkaporin authored Jul 23, 2021
1 parent 467e33b commit 6b31f6e
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 77 deletions.
25 changes: 21 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,33 @@
}
},
{
"name": "Extension Tests",
"name": "Extension Integration Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
"--extensionTestsPath=${workspaceFolder}/out/test/integration/index"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
"outFiles": ["${workspaceFolder}/out/test/integration/**/*.js"],
"preLaunchTask": "${defaultBuildTask}",
"env": {
"SNYK_VSCE_DEVELOPMENT": "1"
}
},
{
// Ref: https://github.com/microsoft/vscode-recipes/tree/main/debugging-mocha-tests
"type": "node",
"request": "launch",
"name": "Extension Unit Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": ["--ui", "tdd", "--timeout", "999999", "--colors", "${workspaceFolder}/out/test/unit"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": ["<node_internals>/**/*.js"],
"env": {
"SNYK_VSCE_DEVELOPMENT": "1"
}
}
]
}
157 changes: 141 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@
"build": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "tsc -p ./",
"test": "node ./out/test/runTest.js",
"test:unit": "mocha --ui tdd -c out/test/unit/**/*.test.js",
"test:integration": "node ./out/test/integration/runTest.js",
"lint": "npx eslint 'src/**/*.ts'",
"lint:fix": "npx eslint --fix 'src/**/*.ts'",
"vscode:uninstall": "node ./out/uninstall"
Expand All @@ -230,6 +231,7 @@
"@types/lodash": "^4.14.161",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.2",
"@types/sinon": "^10.0.2",
"@types/uuid": "^8.3.0",
"@types/vscode": "^1.48.0",
"@typescript-eslint/eslint-plugin": "^4.0.1",
Expand All @@ -242,6 +244,7 @@
"glob": "^7.1.6",
"mocha": "^8.1.3",
"prettier": "^2.1.1",
"sinon": "^11.1.1",
"typescript": "^4.0.2",
"vscode-test": "^1.4.0",
"yalc": "^1.0.0-pre.44"
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/SnykInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from 'vscode';
import { DiagnosticCollection, ExtensionContext, StatusBarItem, TextDocument, TextEditor } from 'vscode';
import { IContextService } from '../snyk/services/contextService';
import { IOpenerService } from '../snyk/services/openerService';
import { Iteratively } from '../snyk/analytics/itly';

export interface StatusBarItemInterface {
snykStatusBarItem: StatusBarItem;
Expand All @@ -22,6 +23,7 @@ export interface BaseSnykModuleInterface {
openerService: IOpenerService;
shouldShowAnalysis: boolean;
emitViewInitialized(): void;
analytics: Iteratively;
loadAnalytics(): void;

// Abstract methods
Expand Down
5 changes: 5 additions & 0 deletions src/snyk/analytics/itly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export class Iteratively {
this.anonymousId = uuidv4();
}

public setShouldReportEvents(shouldReportEvents: boolean): void {
this.shouldReportEvents = shouldReportEvents;
this.load();
}

public load(): Iteratively | null {
if (!this.shouldReportEvents) {
return null;
Expand Down
6 changes: 6 additions & 0 deletions src/snyk/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export class Configuration implements IConfiguration {
.get<boolean>(this.getConfigName(YES_TELEMETRY_SETTING));
}

async setShouldReportEvents(yesTelemetry: boolean): Promise<void> {
await this.vscodeWorkspace
.getConfiguration(CONFIGURATION_IDENTIFIER)
.update(this.getConfigName(YES_TELEMETRY_SETTING), yesTelemetry, true);
}

get shouldShowWelcomeNotification(): boolean {
return !!this.vscodeWorkspace
.getConfiguration(CONFIGURATION_IDENTIFIER)
Expand Down
5 changes: 5 additions & 0 deletions src/snyk/lib/watchers/SnykSettingsWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
ADVANCED_ADVANCED_CODE_ENABLED_SETTING,
ADVANCED_ADVANCED_MODE_SETTING,
TOKEN_SETTING,
YES_TELEMETRY_SETTING,
} from '../../constants/settings';
import { configuration } from '../../configuration';
import { errorsLogs } from '../../messages/errorsServerLogMessages';

class SnykSettingsWatcher implements SnykWatcherInterface {
Expand All @@ -14,6 +16,8 @@ class SnykSettingsWatcher implements SnykWatcherInterface {
} else if (key === ADVANCED_ADVANCED_CODE_ENABLED_SETTING) {
void extension.checkCodeEnabled();
return;
} else if (key === YES_TELEMETRY_SETTING) {
return extension.analytics.setShouldReportEvents(configuration.shouldReportEvents);
}

const extensionConfig = vscode.workspace.getConfiguration('snyk');
Expand All @@ -34,6 +38,7 @@ class SnykSettingsWatcher implements SnykWatcherInterface {
TOKEN_SETTING,
ADVANCED_ADVANCED_CODE_ENABLED_SETTING,
ADVANCED_ADVANCED_MODE_SETTING,
YES_TELEMETRY_SETTING,
].find(config => event.affectsConfiguration(config));
if (change) {
try {
Expand Down
Loading

0 comments on commit 6b31f6e

Please sign in to comment.