Calculate databasesUnderTest with a loop

Currently QLTestAdapter.run() calculates the databases affected by a set of
tests (those databases will be deleted and then reopened after test completion)
using a nested filter-find expression. Which does not work because the
predicate is an async function, so the expression is testing the truthiness of
a Promise instead of the async result.

This commit fixes the problem by implementing the same check with a loop so
that we can invoke the async predicate using await.
This commit is contained in:
Chuan-kai Lin
2021-07-12 14:50:42 -07:00
parent 7a58d360fd
commit 560f694f73

View File

@@ -190,8 +190,15 @@ export class QLTestAdapter extends DisposableObject implements TestAdapter {
this._testStates.fire({ type: 'started', tests: tests } as TestRunStartedEvent);
const currentDatabaseUri = this.databaseManager.currentDatabaseItem?.databaseUri;
const databasesUnderTest = this.databaseManager.databaseItems
.filter(database => tests.find(testPath => database.isAffectedByTest(testPath)));
const databasesUnderTest: DatabaseItem[] = [];
for (const database of this.databaseManager.databaseItems) {
for (const test of tests) {
if (await database.isAffectedByTest(test)) {
databasesUnderTest.push(database);
break;
}
}
}
await this.removeDatabasesBeforeTests(databasesUnderTest, token);
try {