Skip to content

Commit 72ca644

Browse files
Merge pull request #726 from gemini-testing/INFRADUTY-29294.unused
fix: await for 'getTestsTreeFromDatabase' calls
2 parents 8c038bd + e85baca commit 72ca644

File tree

9 files changed

+30
-29
lines changed

9 files changed

+30
-29
lines changed

docs/en/html-reporter-api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Html-reporter adds an `htmlReporter` object to the `testplane` object with its o
1414
| [addExtraItem](#addextraitem) | Method | Adds an additional item to the burger menu of the report. |
1515
| [downloadDatabases](#downloaddatabases) | Method | Downloads all databases from the given files of the type _databaseUrls.json_. |
1616
| [mergeDatabases](#mergedatabases) | Method | Merges all given databases and saves the final report on the specified path. |
17-
| [getTestsTreeFromDatabase](#getteststreefromdatabase) | Method | Returns the test tree from the passed database. |
17+
| [getTestsTreeFromDatabase](#getteststreefromdatabase) | Method | Resolves the test tree from the passed database. |
1818

1919
## events
2020

@@ -192,12 +192,12 @@ await testplane.htmlReporter.mergeDatabases(srcDbPaths, path);
192192

193193
## getTestsTreeFromDatabase
194194

195-
Returns the test tree from the passed database.
195+
Resolves the test tree from the passed database.
196196

197197
### Example of a call
198198

199199
```javascript
200-
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
200+
const dbTree = await testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
201201
```
202202

203203
### Call parameters
@@ -207,8 +207,8 @@ The function takes one argument—the path to the database with the result o
207207
### Usage example
208208

209209
```javascript
210-
function getSuccessTestRunIds({ testplane, mergedDbPath }) {
211-
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
210+
async function getSuccessTestRunIds({ testplane, mergedDbPath }) {
211+
const dbTree = await testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
212212

213213
const successTestRunIds = [];
214214

docs/ru/html-reporter-api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ await testplane.htmlReporter.mergeDatabases(srcDbPaths, path);
197197
### Пример вызова
198198

199199
```javascript
200-
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
200+
const dbTree = await testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
201201
```
202202

203203
### Параметры вызова
@@ -207,8 +207,8 @@ const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
207207
### Пример использования
208208

209209
```javascript
210-
function getSuccessTestRunIds({ testplane, mergedDbPath }) {
211-
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
210+
async function getSuccessTestRunIds({ testplane, mergedDbPath }) {
211+
const dbTree = await testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
212212

213213
const successTestRunIds = [];
214214

lib/cli/commands/remove-unused-screens/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async function handleUnusedScreens(screenPaths, fsTests, opts = {}) {
140140
}
141141

142142
spinner.start(`Identifying unused reference images (tests passed successfully for them, but they were not used during execution)`);
143-
const unusedScreenPaths = identifyUnusedScreens(fsTests, {toolAdapter, mergedDbPath});
143+
const unusedScreenPaths = await identifyUnusedScreens(fsTests, {toolAdapter, mergedDbPath});
144144
spinner.succeed();
145145

146146
await handleScreens(screenPaths, {paths: unusedScreenPaths, type: 'unused'}, {spinner, cliOpts});

lib/cli/commands/remove-unused-screens/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ exports.identifyOutdatedScreens = (screenPaths, screenPatterns) => {
6868
return outdatedScreens;
6969
};
7070

71-
exports.identifyUnusedScreens = (fsTests, {toolAdapter, mergedDbPath} = {}) => {
72-
const dbTree = toolAdapter.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
71+
exports.identifyUnusedScreens = async (fsTests, {toolAdapter, mergedDbPath} = {}) => {
72+
const dbTree = await toolAdapter.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
7373
const screenPathsBySuccessTests = getScreenPathsBySuccessTests(dbTree);
7474
const unusedScreens = [];
7575

test/func/tests/common/tests-details.testplane.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe(process.env.TOOL || 'Default', () => {
2525
`//section[contains(@class, 'error__item') and .${getElementWithTextSelector('span', 'stack')}/..]`;
2626

2727
await browser.$(selector).waitForDisplayed();
28+
await browser.waitUntil(() => browser.execute(() => document.fonts.status === 'loaded'));
2829
await browser.assertView('details summary', selector);
2930
});
3031
});
106 Bytes
Loading

test/unit/lib/cli/commands/remove-unused-screens/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('lib/cli/commands/remove-unused-screens', () => {
6060
findScreens = sandbox.stub().resolves([]);
6161
askConfirm = sandbox.stub().resolves(true);
6262
identifyOutdatedScreens = sandbox.stub().returns([]);
63-
identifyUnusedScreens = sandbox.stub().returns([]);
63+
identifyUnusedScreens = sandbox.stub().resolves([]);
6464
removeScreens = sandbox.stub().resolves();
6565

6666
filesizeMock = sandbox.stub().returns('12345');
@@ -439,7 +439,7 @@ describe('lib/cli/commands/remove-unused-screens', () => {
439439

440440
it('should not throw if unused screen does not exist on fs', async () => {
441441
findScreens.resolves(['/root/broId/testId/1.png', '/root/broId/unusedTestId/2.png']);
442-
identifyUnusedScreens.returns(['/root/broId/unusedTestId/2.png']);
442+
identifyUnusedScreens.resolves(['/root/broId/unusedTestId/2.png']);
443443

444444
const accessError = new Error('file does not exist');
445445
accessError.code = 'ENOENT';
@@ -453,7 +453,7 @@ describe('lib/cli/commands/remove-unused-screens', () => {
453453

454454
it('should inform user about the number of unused screens', async () => {
455455
findScreens.resolves(['/root/usedTestId/img.png', '/root/unusedTestId/img.png']);
456-
identifyUnusedScreens.returns(['/root/unusedTestId/img.png']);
456+
identifyUnusedScreens.resolves(['/root/unusedTestId/img.png']);
457457

458458
await removeUnusedScreens_({toolAdapter, program});
459459

@@ -462,7 +462,7 @@ describe('lib/cli/commands/remove-unused-screens', () => {
462462

463463
describe('size calculation of unused images', () => {
464464
beforeEach(() => {
465-
identifyUnusedScreens.returns(['/root/unusedTestId/1.png', '/root/unusedTestId/2.png']);
465+
identifyUnusedScreens.resolves(['/root/unusedTestId/1.png', '/root/unusedTestId/2.png']);
466466

467467
fs.stat.withArgs('/root/unusedTestId/1.png').resolves({size: 10});
468468
fs.stat.withArgs('/root/unusedTestId/2.png').resolves({size: 20});
@@ -485,7 +485,7 @@ describe('lib/cli/commands/remove-unused-screens', () => {
485485

486486
describe('show list of unused images', () => {
487487
beforeEach(() => {
488-
identifyUnusedScreens.returns(['/root/unusedTestId/1.png', '/root/unusedTestId/2.png']);
488+
identifyUnusedScreens.resolves(['/root/unusedTestId/1.png', '/root/unusedTestId/2.png']);
489489
});
490490

491491
it('should ask user about it', async () => {
@@ -519,7 +519,7 @@ describe('lib/cli/commands/remove-unused-screens', () => {
519519

520520
describe('remove unused images', () => {
521521
it('should ask user about it', async () => {
522-
identifyUnusedScreens.returns(['/root/unusedTestId/1.png', '/root/unusedTestId/2.png']);
522+
identifyUnusedScreens.resolves(['/root/unusedTestId/1.png', '/root/unusedTestId/2.png']);
523523

524524
await removeUnusedScreens_({program});
525525

@@ -531,7 +531,7 @@ describe('lib/cli/commands/remove-unused-screens', () => {
531531

532532
it('should not remove if user say "no"', async () => {
533533
askConfirm.withArgs(sinon.match({message: 'Remove unused reference images?'}), program.options).resolves(false);
534-
identifyUnusedScreens.returns(['/root/unusedTestId/1.png', '/root/unusedTestId/2.png']);
534+
identifyUnusedScreens.resolves(['/root/unusedTestId/1.png', '/root/unusedTestId/2.png']);
535535

536536
await removeUnusedScreens_({program});
537537

@@ -540,7 +540,7 @@ describe('lib/cli/commands/remove-unused-screens', () => {
540540

541541
it('should remove if user say "yes"', async () => {
542542
const unusedScreens = ['/root/unusedTestId/1.png', '/root/unusedTestId/2.png'];
543-
identifyUnusedScreens.returns(unusedScreens);
543+
identifyUnusedScreens.resolves(unusedScreens);
544544
askConfirm.withArgs(sinon.match({message: 'Remove unused reference images?'}), program.options).resolves(true);
545545

546546
await removeUnusedScreens_({program});

test/unit/lib/cli/commands/remove-unused-screens/utils.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('lib/cli/commands/remove-unused-screens/utils', () => {
4343

4444
toolAdapter.readTests.resolves(testCollection);
4545
toolAdapter.htmlReporter = htmlReporter || {
46-
getTestsTreeFromDatabase: sandbox.stub().returns(mkTestsTreeFromDb_())
46+
getTestsTreeFromDatabase: sandbox.stub().resolves(mkTestsTreeFromDb_())
4747
};
4848

4949
return toolAdapter;
@@ -263,7 +263,7 @@ describe('lib/cli/commands/remove-unused-screens/utils', () => {
263263
return {[image.id]: image};
264264
};
265265

266-
it('should return unused screens for successful tests', () => {
266+
it('should return unused screens for successful tests', async () => {
267267
const browsersById = mkBrowser({id: 'test1 bro1', resultIds: ['res-1', 'res-2']});
268268
const resultsById = {
269269
...mkResult({id: 'res-1', status: ERROR, imageIds: []}),
@@ -273,38 +273,38 @@ describe('lib/cli/commands/remove-unused-screens/utils', () => {
273273
const dbTree = mkTestsTreeFromDb_({browsersById, resultsById, imagesById});
274274

275275
const toolAdapter = mkToolAdapter_();
276-
toolAdapter.htmlReporter.getTestsTreeFromDatabase.withArgs('/report/sqlite.db').returns(dbTree);
276+
toolAdapter.htmlReporter.getTestsTreeFromDatabase.withArgs('/report/sqlite.db').resolves(dbTree);
277277

278278
const fsTestsTree = mkTestsTreeFromFs_({
279279
byId: {
280280
'test1 bro1': {screenPaths: ['/test1/a.png', '/test1/b.png']}
281281
}
282282
});
283283

284-
const unusedScreens = utils.identifyUnusedScreens(
284+
const unusedScreens = await utils.identifyUnusedScreens(
285285
fsTestsTree,
286286
{toolAdapter, mergedDbPath: '/report/sqlite.db'}
287287
);
288288

289289
assert.deepEqual(unusedScreens, ['/test1/b.png']);
290290
});
291291

292-
it('should not return unused screens for not successful tests', () => {
292+
it('should not return unused screens for not successful tests', async () => {
293293
const browsersById = mkBrowser({id: 'test1 bro1', resultIds: ['res-1']});
294294
const resultsById = mkResult({id: 'res-1', status: ERROR, imageIds: ['img-1']});
295295
const imagesById = mkImage({id: 'img-1', stateName: 'a'});
296296
const dbTree = mkTestsTreeFromDb_({browsersById, resultsById, imagesById});
297297

298298
const toolAdapter = mkToolAdapter_();
299-
toolAdapter.htmlReporter.getTestsTreeFromDatabase.withArgs('/report/sqlite.db').returns(dbTree);
299+
toolAdapter.htmlReporter.getTestsTreeFromDatabase.withArgs('/report/sqlite.db').resolves(dbTree);
300300

301301
const fsTestsTree = mkTestsTreeFromFs_({
302302
byId: {
303303
'test1 bro1': {screenPaths: ['/test1/a.png', '/test1/b.png']}
304304
}
305305
});
306306

307-
const unusedScreens = utils.identifyUnusedScreens(
307+
const unusedScreens = await utils.identifyUnusedScreens(
308308
fsTestsTree,
309309
{toolAdapter, mergedDbPath: '/report/sqlite.db'}
310310
);

test/unit/lib/gui/tool-runner/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('lib/gui/tool-runner/index', () => {
7171
sandbox.stub(GuiReportBuilder, 'create').returns(reportBuilder);
7272
reportBuilder.getResult.returns({});
7373

74-
getTestsTreeFromDatabase = sandbox.stub().returns({});
74+
getTestsTreeFromDatabase = sandbox.stub().resolves({});
7575

7676
getReferencePath = sandbox.stub().returns('');
7777

@@ -599,7 +599,7 @@ describe('lib/gui/tool-runner/index', () => {
599599

600600
it('should not reuse tree if it is empty', async () => {
601601
fs.pathExists.withArgs(dbPath).resolves(true);
602-
getTestsTreeFromDatabase.returns({});
602+
getTestsTreeFromDatabase.resolves({});
603603

604604
await gui.initialize();
605605

@@ -608,7 +608,7 @@ describe('lib/gui/tool-runner/index', () => {
608608

609609
it('should reuse tests tree', async () => {
610610
fs.pathExists.withArgs(dbPath).resolves(true);
611-
getTestsTreeFromDatabase.returns('tests-tree');
611+
getTestsTreeFromDatabase.resolves('tests-tree');
612612

613613
await gui.initialize();
614614

0 commit comments

Comments
 (0)