Skip to content

Commit

Permalink
fix failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
triwav committed Sep 11, 2023
1 parent bd1e921 commit 6515fd8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
28 changes: 7 additions & 21 deletions src/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ describe('extension', () => {
beforeEach(() => {
sinon.stub(languageServerManager, 'init').returns(Promise.resolve());

context = {
extensionPath: '',
subscriptions: [],
asAbsolutePath: () => { },
globalState: {
get: () => {

},
update: () => {

}
}
};

originalWebviews = extensionInstance['webviews'];
extensionInstance['webviews'] = [];
});
Expand All @@ -54,48 +40,48 @@ describe('extension', () => {
it('registers configuration provider', async () => {
let spy = sinon.spy(vscode.debug, 'registerDebugConfigurationProvider');
expect(spy.calledOnce).to.be.false;
await extension.activate(context);
await extension.activate(vscode.context);
expect(spy.calledOnce).to.be.true;
});

it('registers formatter', async () => {
let spy = sinon.spy(vscode.languages, 'registerDocumentRangeFormattingEditProvider');
expect(spy.getCalls().length).to.equal(0);
await extension.activate(context);
await extension.activate(vscode.context);
expect(spy.getCalls().length).to.be.greaterThan(1);
});

it('registers definition provider', async () => {
let spy = sinon.spy(vscode.languages, 'registerDefinitionProvider');
expect(spy.calledOnce).to.be.false;
await extension.activate(context);
await extension.activate(vscode.context);
expect(spy.callCount).to.be.greaterThan(0);
});

it('registers all commands', async () => {
let stub = sinon.stub(BrightScriptCommands.prototype, 'registerCommands').callsFake(() => { });
await extension.activate(context);
await extension.activate(vscode.context);
expect(stub.callCount).to.equal(1);
});

it('registers onDidStartDebugSession', async () => {
let spy = sinon.spy(vscode.debug, 'onDidStartDebugSession');
expect(spy.calledOnce).to.be.false;
await extension.activate(context);
await extension.activate(vscode.context);
expect(spy.calledOnce).to.be.true;
});

it('registers onDidTerminateDebugSession', async () => {
let spy = sinon.spy(vscode.debug, 'onDidTerminateDebugSession');
expect(spy.calledOnce).to.be.false;
await extension.activate(context);
await extension.activate(vscode.context);
expect(spy.calledOnce).to.be.true;
});

it('registers onDidReceiveDebugSessionCustomEvent', async () => {
let spy = sinon.spy(vscode.debug, 'onDidReceiveDebugSessionCustomEvent');
expect(spy.calledOnce).to.be.false;
await extension.activate(context);
await extension.activate(vscode.context);
expect(spy.getCalls().length).to.be.greaterThan(0);
});
});
10 changes: 9 additions & 1 deletion src/mockVscode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ export let vscode = {
return this._data[key];
}
} as any,
workspaceState: {
_data: {},
update: function(key: string, value: any) {
this._data[key] = value;
},
get: function(key: string) {
return this._data[key];
}
} as any,
globalStorageUri: undefined as Uri,
workspaceState: {} as any,
environmentVariableCollection: {} as any,
logUri: undefined as Uri,
logPath: '',
Expand Down

0 comments on commit 6515fd8

Please sign in to comment.