Skip to content

Commit

Permalink
Add tests for status bar functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan37 committed Mar 7, 2024
1 parent 7ef69d2 commit ecfd9c3
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 43 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.DS_Store
Thumbs.db
.vscode/
.vscode-test/
.idea/
.sass-cache
.eslintcache
lib-cov
*.log
*.log*
pids

.vscode-test/

# Node
.npm/
node_modules/
package-lock.json
Expand All @@ -20,9 +20,7 @@ dist/
out/
build/
*.tsbuildinfo

.history/
*.log*

# env
.env
Expand Down
3 changes: 2 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.js.map
**/*.ts
**/.vscode-test.*
**/.vscode-test.*
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "zenml-studio",
"publisher": "zenml",
"displayName": "ZenML Studio",
"description": "",
"version": "0.0.1",
Expand Down Expand Up @@ -33,17 +34,19 @@
"test": "vscode-test"
},
"devDependencies": {
"@types/vscode": "^1.86.0",
"@types/mocha": "^10.0.6",
"@types/node": "18.x",
"@types/vscode": "^1.86.0",
"@types/webpack": "^5.28.5",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@vscode/test-cli": "^0.0.4",
"@vscode/test-electron": "^2.3.9",
"eslint": "^8.56.0",
"typescript": "^5.3.3",
"resolve-ts-aliases": "^1.0.1",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "^5.90.0",
"webpack-cli": "^5.1.4",
"@vscode/test-cli": "^0.0.4",
"@vscode/test-electron": "^2.3.9"
"webpack-cli": "^5.1.4"
}
}
10 changes: 7 additions & 3 deletions src/commands/stackCommands.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { execCLICommand } from '../utils/shell';
import { Shell } from '../utils/shell';

/**
* Fetches the current active stack using the ZenML CLI.
*
* @param {Function} execCLICommand - Optional. Custom function to execute CLI commands, intended
* for testing with mocks or stubs.
* @returns {Promise<string>} Promise resolving with the name of the current active stack.
*/
export function getActiveStack(): Promise<string> {
return execCLICommand('zenml stack get');
export async function getActiveStack(execCLICommand: Function = Shell.execCLICommand): Promise<string> {
return await execCLICommand('zenml stack get');
}
19 changes: 11 additions & 8 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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 * as vscode from 'vscode';
// import * as myExtension from '../../extension';

suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
test('Extension should be present', () => {
assert.ok(vscode.extensions.getExtension('zenml.zenml-studio'));
});

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
test('Extension should activate', async () => {
const extension = vscode.extensions.getExtension('zenml.zenml-studio');
if (extension) {
await extension.activate();
assert.ok(extension.isActive, 'Extension did not activate as expected.');
} else {
assert.fail('Extension zenml-studio could not be found.');
}
});
});
27 changes: 14 additions & 13 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { exec } from 'child_process';

/**
* Executes a CLI command and returns a promise that resolves with the command's stdout.
*/
export function execCLICommand(command: string): Promise<string> {
return new Promise((resolve, reject) => {

exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
resolve(stdout.trim());
export class Shell {
/**
* Executes a CLI command and returns a promise that resolves with the command's stdout.
*/
static execCLICommand(command: string): Promise<string> {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
resolve(stdout.trim());
});
});
});
}
}
4 changes: 2 additions & 2 deletions src/views/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export class ZenMLStatusBar {
public updateStatusBar() {
console.log('Updating ZenML active stack...');

getActiveStack().then((fullActiveStackText) => {
getActiveStack().then((activeStackCliOutput) => {
/**
* The cli command `zenml stack get` outputs the line below:
* The global active stack is: 'default'
* 'default' is the actual string we want to display in the status bar.
*/
const match = fullActiveStackText.match(/'([^']+)'/); // matches text within single quotes
const match = activeStackCliOutput.match(/'([^']+)'/); // matches text within single quotes
const activeStack = match ? match[1] : 'Error parsing stack name';
this.statusBar.text = `Active Stack: ${activeStack}`;
this.statusBar.tooltip = 'Click to refresh the active ZenML stack';
Expand Down
11 changes: 5 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
],
"sourceMap": true,
"rootDir": "src",
"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. */
}
"strict": true,
"skipLibCheck": true,
},
"exclude": ["node_modules"],
"include": ["./src/**/*.ts"]
}

0 comments on commit ecfd9c3

Please sign in to comment.