mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 01:25:37 -05:00
Add main controller tests for a few extensions (#11307)
* add a few tests * fix errors * undo change * move registering commands to extension.ts for dacpac and schema compare * undo createController() addition * fix whitespace
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
"relativeSourcePath": "..",
|
||||
"relativeCoverageDir": "../../coverage",
|
||||
"ignorePatterns": [
|
||||
"**/node_modules/**"
|
||||
"**/node_modules/**",
|
||||
"extension.js"
|
||||
],
|
||||
"reports": [
|
||||
"cobertura"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
"activationEvents": [
|
||||
"onCommand:dacFx.start"
|
||||
],
|
||||
"main": "./out/main",
|
||||
"main": "./out/extension",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Microsoft/azuredatastudio.git"
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { DataTierApplicationWizard } from '../wizard/dataTierApplicationWizard';
|
||||
|
||||
/**
|
||||
* The main controller class that initializes the extension
|
||||
*/
|
||||
export default class MainController implements vscode.Disposable {
|
||||
|
||||
public constructor(private context: vscode.ExtensionContext) {
|
||||
}
|
||||
|
||||
public deactivate(): void {
|
||||
}
|
||||
|
||||
public activate(): Promise<boolean> {
|
||||
this.initializeDacFxWizard();
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
private initializeDacFxWizard() {
|
||||
azdata.tasks.registerTask('dacFx.start', (profile: azdata.IConnectionProfile, ...args: any[]) => new DataTierApplicationWizard().start(profile, args));
|
||||
}
|
||||
|
||||
public get extensionContext(): vscode.ExtensionContext {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.deactivate();
|
||||
}
|
||||
}
|
||||
@@ -3,23 +3,13 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import MainController from './controllers/mainController';
|
||||
import { ApiWrapper } from './common/apiWrapper';
|
||||
import { DataTierApplicationWizard } from './wizard/dataTierApplicationWizard';
|
||||
|
||||
let controllers: MainController[] = [];
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
||||
// Start the main controller
|
||||
let mainController = new MainController(context, new ApiWrapper());
|
||||
controllers.push(mainController);
|
||||
context.subscriptions.push(mainController);
|
||||
|
||||
await mainController.activate();
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
vscode.commands.registerCommand('dacFx.start', (profile: azdata.IConnectionProfile, ...args: any[]) => new DataTierApplicationWizard().start(profile, args));
|
||||
}
|
||||
|
||||
export function deactivate(): void {
|
||||
for (let controller of controllers) {
|
||||
controller.deactivate();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import MainController from './controllers/mainController';
|
||||
|
||||
let controllers: MainController[] = [];
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
let activations: Promise<boolean>[] = [];
|
||||
|
||||
// Start the main controller
|
||||
let mainController = new MainController(context);
|
||||
controllers.push(mainController);
|
||||
context.subscriptions.push(mainController);
|
||||
activations.push(mainController.activate());
|
||||
|
||||
return Promise.all(activations)
|
||||
.then((results: boolean[]) => {
|
||||
for (let result of results) {
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
for (let controller of controllers) {
|
||||
controller.deactivate();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as should from 'should';
|
||||
import MainController from '../controllers/mainController';
|
||||
import { TestContext, createContext } from './testContext';
|
||||
|
||||
let testContext: TestContext;
|
||||
|
||||
function createController(): MainController {
|
||||
let controller = new MainController(testContext.context);
|
||||
return controller;
|
||||
}
|
||||
|
||||
describe('MainController', function (): void {
|
||||
before(async function (): Promise<void> {
|
||||
testContext = createContext();
|
||||
});
|
||||
|
||||
it('Should create new instance successfully', async function (): Promise<void> {
|
||||
let controller: MainController;
|
||||
should.doesNotThrow(() => controller = createController());
|
||||
should.notEqual(controller.extensionContext, undefined);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -4,7 +4,8 @@
|
||||
"relativeCoverageDir": "../../coverage",
|
||||
"ignorePatterns": [
|
||||
"**/node_modules/**",
|
||||
"**/test/**"
|
||||
"**/test/**",
|
||||
"extension.js"
|
||||
],
|
||||
"reports": [
|
||||
"cobertura",
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
"activationEvents": [
|
||||
"onCommand:schemaCompare.start"
|
||||
],
|
||||
"main": "./out/main",
|
||||
"main": "./out/extension",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Microsoft/azuredatastudio.git"
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Disposable, ExtensionContext } from 'vscode';
|
||||
import { SchemaCompareMainWindow } from '../schemaCompareMainWindow';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
|
||||
/**
|
||||
* The main controller class that initializes the extension
|
||||
*/
|
||||
export default class MainController implements Disposable {
|
||||
protected schemaCompareMainWindow: SchemaCompareMainWindow;
|
||||
|
||||
public constructor(private context: ExtensionContext, private apiWrapper: ApiWrapper) {
|
||||
this.schemaCompareMainWindow = new SchemaCompareMainWindow(this.apiWrapper, null, this.extensionContext);
|
||||
}
|
||||
|
||||
public get extensionContext(): ExtensionContext {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
public deactivate(): void {
|
||||
}
|
||||
|
||||
public activate(): Promise<boolean> {
|
||||
this.initializeSchemaCompareDialog();
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
private initializeSchemaCompareDialog(): void {
|
||||
this.apiWrapper.registerCommand('schemaCompare.start', async (context: any) => { await this.schemaCompareMainWindow.start(context); });
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.deactivate();
|
||||
}
|
||||
}
|
||||
15
extensions/schema-compare/src/extension.ts
Normal file
15
extensions/schema-compare/src/extension.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { ApiWrapper } from './common/apiWrapper';
|
||||
import { SchemaCompareMainWindow } from './schemaCompareMainWindow';
|
||||
|
||||
export async function activate(extensionContext: vscode.ExtensionContext): Promise<void> {
|
||||
vscode.commands.registerCommand('schemaCompare.start', async (context: any) => { await new SchemaCompareMainWindow(new ApiWrapper(), undefined, extensionContext).start(context); });
|
||||
}
|
||||
|
||||
export function deactivate(): void {
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
"relativeCoverageDir": "../../coverage",
|
||||
"ignorePatterns": [
|
||||
"**/node_modules/**",
|
||||
"**/test/**"
|
||||
"**/test/**",
|
||||
"extension.js"
|
||||
],
|
||||
"reports": [
|
||||
"cobertura",
|
||||
|
||||
@@ -65,4 +65,16 @@ describe('MainController: main controller operations', function (): void {
|
||||
const controller = new MainController(testContext.context, testContext.apiWrapper.object);
|
||||
await shouldThrowSpecificError(async () => await controller.createNewProject(), constants.projectLocationRequired);
|
||||
});
|
||||
|
||||
it('Should create new instance without error', async function (): Promise<void> {
|
||||
should.doesNotThrow(() => new MainController(testContext.context, testContext.apiWrapper.object), 'Creating controller should not throw an error');
|
||||
});
|
||||
|
||||
it('Should activate and deactivate without error', async function (): Promise<void> {
|
||||
let controller = new MainController(testContext.context, testContext.apiWrapper.object);
|
||||
should.notEqual(controller.extensionContext, undefined);
|
||||
|
||||
should.doesNotThrow(() => controller.activate(), 'activate() should not throw an error');
|
||||
should.doesNotThrow(() => controller.dispose(), 'dispose() should not throw an error');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user