Skip to content

Commit

Permalink
possible test error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Nov 25, 2018
1 parent 33755a2 commit f1ca84c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
30 changes: 15 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ export async function activate(context: vscode.ExtensionContext) {
testExplorerExtension.exports.registerTestAdapter(adapter);
}
}
context.subscriptions.push(
vscode.workspace.onDidChangeWorkspaceFolders(event => {
for (const workspaceFolder of event.removed) {
const adapter = registeredAdapters.get(workspaceFolder);
if (adapter) {
testExplorerExtension.exports.unregisterTestAdapter(adapter);
registeredAdapters.delete(workspaceFolder);
}
}

vscode.workspace.onDidChangeWorkspaceFolders(event => {
for (const workspaceFolder of event.removed) {
const adapter = registeredAdapters.get(workspaceFolder);
if (adapter) {
testExplorerExtension.exports.unregisterTestAdapter(adapter);
registeredAdapters.delete(workspaceFolder);
}
}

for (const workspaceFolder of event.added) {
const adapter = new C2TestAdapter(workspaceFolder);
registeredAdapters.set(workspaceFolder, adapter);
testExplorerExtension.exports.registerTestAdapter(adapter);
}
});
for (const workspaceFolder of event.added) {
const adapter = new C2TestAdapter(workspaceFolder);
registeredAdapters.set(workspaceFolder, adapter);
testExplorerExtension.exports.registerTestAdapter(adapter);
}
}));
}
}
19 changes: 13 additions & 6 deletions src/test/C2TestAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ describe('C2TestAdapter', function() {
}

async function waitFor(
test: Mocha.Context, condition: Function,
context: Mocha.Context, condition: Function,
timeout: number = 1000): Promise<void> {
const start = Date.now();
let c = await condition();
while (!(c = await condition()) &&
(Date.now() - start < timeout || !test.enableTimeouts()))
(Date.now() - start < timeout || !context.enableTimeouts()))
await promisify(setTimeout)(32);
assert.ok(c);
}
Expand All @@ -137,8 +137,14 @@ describe('C2TestAdapter', function() {
return e.suite!;
}

function disposeAdapterAndSubscribers(check: boolean = true) {
adapter && adapter.dispose();
async function disposeAdapterAndSubscribers(
context: Mocha.Context, check: boolean = true) {
if (adapter) {
adapter.dispose();
await waitFor(context, () => {
return (<any>adapter)._allTasks._count == 0;
});
}
testsEventsConnection && testsEventsConnection.dispose();
testStatesEventsConnection && testStatesEventsConnection.dispose();
testStatesEvents = [];
Expand Down Expand Up @@ -206,9 +212,9 @@ describe('C2TestAdapter', function() {
await resetConfig();
})

afterEach(function() {
afterEach(async function() {
this.timeout(8000);
disposeAdapterAndSubscribers();
await disposeAdapterAndSubscribers(this);
})

describe('detect config change', function() {
Expand Down Expand Up @@ -1783,6 +1789,7 @@ describe('C2TestAdapter', function() {
})

specify('variable substitution with executables={...}', async function() {
this.timeout(8000);
this.slow(500);
const wsPath = workspaceFolderUri.fsPath;
const execPath2CopyRelPath = path.normalize('foo/bar/base.second.first');
Expand Down

0 comments on commit f1ca84c

Please sign in to comment.