Skip to content

Commit

Permalink
Setup unittests
Browse files Browse the repository at this point in the history
wip
  • Loading branch information
fey101 committed Oct 23, 2024
1 parent a774b49 commit fa3f77f
Show file tree
Hide file tree
Showing 8 changed files with 1,234 additions and 842 deletions.
3 changes: 2 additions & 1 deletion vscode/microsoft-kiota/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
out/
.kiotabin/
*.vsix
*.vsix
.vscode-test
5 changes: 5 additions & 0 deletions vscode/microsoft-kiota/.vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
});
1,977 changes: 1,166 additions & 811 deletions vscode/microsoft-kiota/package-lock.json

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions vscode/microsoft-kiota/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"type": "git"
},
"keywords": [
"openapi",
"api client",
"copilot",
"api plugins",
"api manifest"
"openapi",
"api client",
"copilot",
"api plugins",
"api manifest"
],
"activationEvents": [
"onStartupFinished"
Expand Down Expand Up @@ -463,22 +463,28 @@
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"lint": "eslint",
"test": "node ./out/test/runTest.js"
"test": "vscode-test"
},
"devDependencies": {
"@stylistic/eslint-plugin-ts": "^2.9.0",
"@types/adm-zip": "^0.5.5",
"@types/mocha": "^10.0.9",
"@types/chai": "^5.0.0",
"@types/node": "22.x",
"@types/sinon": "^17.0.3",
"@types/vscode": "^1.94.0",
"@typescript-eslint/eslint-plugin": "^8.11.0",
"@typescript-eslint/parser": "^8.11.0",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"eslint": "^9.13.0",
"chai": "^5.1.1",
"glob": "^11.0.0",
"mocha": "^10.7.3",
"sinon": "^19.0.2",
"ts-loader": "^9.5.1",
"typescript": "^5.6.3",
"typemoq": "^2.1.0",
"typescript": "^5.5.4",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4"
},
Expand Down
29 changes: 16 additions & 13 deletions vscode/microsoft-kiota/src/kiotaInterop/kiotaInstall.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as admZip from 'adm-zip';
import AdmZip from 'adm-zip';
import { createHash } from 'crypto';
import * as fs from 'fs';
import * as https from 'https';
import isOnline from 'is-online';
import * as path from 'path';
import * as vscode from "vscode";


const kiotaInstallStatusKey = "kiotaInstallStatus";
const installDelayInMs = 30000; // 30 seconds
async function runIfNotLocked(context: vscode.ExtensionContext, action: () => Promise<void>) {
Expand Down Expand Up @@ -34,15 +34,18 @@ export async function ensureKiotaIsPresent(context: vscode.ExtensionContext) {
title: vscode.l10n.t("Downloading kiota...")

}, async (progress, _) => {
const online = await isOnline();
if (!online) {
await vscode.window.showErrorMessage(
vscode.l10n.t("Downloading kiota requires an internet connection. Please check your connection and try again.")
);
return;
}
await runIfNotLocked(context, async () => {
try {
await (async () => {
const isOnline = (await import('is-online')).default;
const online = await isOnline();
if (!online) {
await vscode.window.showErrorMessage(
vscode.l10n.t("Downloading kiota requires an internet connection. Please check your connection and try again.")
);
return;
}
})();
await runIfNotLocked(context, async () => {
try {
const packageToInstall = runtimeDependencies.find((p) => p.platformId === currentPlatform);
if (!packageToInstall) {
throw new Error("Could not find package to install");
Expand Down Expand Up @@ -104,7 +107,7 @@ function getKiotaPathInternal(context: vscode.ExtensionContext, withFileName = t
}

function unzipFile(zipFilePath: string, destinationPath: string) {
const zip = new admZip(zipFilePath);
const zip = new AdmZip(zipFilePath);
zip.extractAllTo(destinationPath, true);
}

Expand Down Expand Up @@ -159,4 +162,4 @@ const linuxPlatform = 'linux';
export function getCurrentPlatform(): string {
const binPathSegmentOS = process.platform === 'win32' ? windowsPlatform : process.platform === 'darwin' ? osxPlatform : linuxPlatform;
return `${binPathSegmentOS}-${process.arch}`;
}
}
28 changes: 21 additions & 7 deletions vscode/microsoft-kiota/src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import * as assert from 'assert';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
// import { assert } from "chai";
import assert from "assert";
import * as sinon from "sinon";
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';
import * as filterModule from "../../commands/open-api-tree-view/filterDescriptionCommand";
import * as treeModule from "../../openApiTreeProvider";


suite('Extension Test Suite', () => {
void vscode.window.showInformationMessage('Start all tests.');
const sanbox = sinon.createSandbox();

teardown(async () => {
sanbox.restore();
});

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
test('test open-api-tree-view function filterDescriptionCommand', () => {
var treeProvider = sinon.createStubInstance(treeModule.OpenApiTreeProvider);
const filterDescriptionCommand = new filterModule.FilterDescriptionCommand(treeProvider);
assert.strictEqual("kiota.openApiExplorer.filterDescription", filterDescriptionCommand.getName());
});
});
4 changes: 2 additions & 2 deletions vscode/microsoft-kiota/src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import { glob } from 'glob';
import Mocha from 'mocha';
import * as path from 'path';

export async function run(): Promise<void> {
// Create the mocha test
Expand Down
10 changes: 9 additions & 1 deletion vscode/microsoft-kiota/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
},
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
"strict": true, /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */

// other options

"esModuleInterop": true,
"moduleResolution": "node",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,

}
}

0 comments on commit fa3f77f

Please sign in to comment.