Skip to content

fix #1315 unit tests need to wait for extension to activate #1316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

import * as vscode from 'vscode';
import { createDeferred } from './common/helpers';
import { PythonCompletionItemProvider } from './providers/completionProvider';
import { PythonHoverProvider } from './providers/hoverProvider';
import { PythonDefinitionProvider } from './providers/definitionProvider';
Expand Down Expand Up @@ -39,6 +40,8 @@ let unitTestOutChannel: vscode.OutputChannel;
let formatOutChannel: vscode.OutputChannel;
let lintingOutChannel: vscode.OutputChannel;
let jupMain: jup.Jupyter;
const activationDeferred = createDeferred<void>();
export const activated = activationDeferred.promise;
export async function activate(context: vscode.ExtensionContext) {
const pythonSettings = settings.PythonSettings.getInstance();
const pythonExt = new PythonExt();
Expand Down Expand Up @@ -153,6 +156,7 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(hepProvider);

context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('python', new SimpleConfigurationProvider()));
activationDeferred.resolve();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why it would be better to have activated set to false and then flip it to true here after the activation as resolved? I guess that loss of constness would be unfortunate (basically I'm just trying to learn better TS design 😃 ).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be a promise that can be used from within the unit test. Having a boolean doesn't allow me to await on the completion of the above code

}

class PythonExt implements vscode.Disposable {
Expand Down
18 changes: 11 additions & 7 deletions src/test/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@
process.env['PYTHON_DONJAYAMANNE_TEST'] = "1";

// The module 'assert' provides assertion methods from node
import * as assert from "assert";
import * as assert from 'assert';
import * as fs from 'fs';

// 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 path from "path";
import * as vscode from 'vscode';
import * as path from 'path';
let dummyPythonFile = path.join(__dirname, "..", "..", "src", "test", "pythonFiles", "dummy.py");

export function initialize(): Promise<any> {
let extensionActivated: boolean = false;
export async function initialize(): Promise<any> {
// Opening a python file activates the extension
return new Promise<any>((resolve, reject) => {
vscode.workspace.openTextDocument(dummyPythonFile).then(() => resolve(), reject);
});
await vscode.workspace.openTextDocument(dummyPythonFile);
if (!extensionActivated) {
const ext = require('../client/extension');
await ext.activated;
extensionActivated = true;
}
}

export async function wait(timeoutMilliseconds: number) {
Expand Down