Skip to content

Commit

Permalink
Merge pull request #538 from gemini-testing/fix/kroman512/image_order
Browse files Browse the repository at this point in the history
fix: ensure right image states order html-reporter
  • Loading branch information
KuznetsovRoman authored Mar 27, 2024
2 parents 26a6408 + 8ffead1 commit 50c4074
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/images-info-saver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export class ImagesInfoSaver extends EventEmitter2 {
const testDebug = debug.extend(testResult.imageDir);
testDebug(`Saving images of ${testResult.id}`);

const newImagesInfos: ImageInfoFull[] = [];

await Promise.all(testResult.imagesInfo.map(async (imagesInfo, index) => {
const newImagesInfos = await Promise.all(testResult.imagesInfo.map(async (imagesInfo, index) => {
const imageDebug = testDebug.extend(index.toString());
imageDebug.enabled && imageDebug('Handling %j', removeBufferFromImagesInfo(imagesInfo));

Expand All @@ -79,7 +77,7 @@ export class ImagesInfoSaver extends EventEmitter2 {

await actions.onIdle();

newImagesInfos.push(_.omitBy(newImagesInfo, _.isNil) as ImageInfoFull);
return _.omitBy(newImagesInfo, _.isNil) as ImageInfoFull;
}));

await this.emitAsync(PluginEvents.TEST_SCREENSHOTS_SAVED, {
Expand Down
22 changes: 22 additions & 0 deletions test/unit/lib/images-info-saver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,27 @@ describe('images-info-saver', () => {
imagesInfo: updatedTestResult.imagesInfo
}));
});

it('should keep images order', async () => {
const imagesInfo = _.range(20).map(i => ({stateName: `state ${i + 1}`})) as ImageInfoNoRef[];
const testResult = {
imagesInfo,
fullName: 'some-name',
browserId: 'some-browser',
attempt: 0
} as ReporterTestResult;

const eventHandler = sinon.stub();
imagesInfoSaver.on(PluginEvents.TEST_SCREENSHOTS_SAVED, eventHandler);

const updatedTestResult = await imagesInfoSaver.save(testResult);

assert.deepStrictEqual(updatedTestResult.imagesInfo, imagesInfo);
assert.calledWith(eventHandler, sinon.match({
imagesInfo,
testId: 'some-name.some-browser',
attempt: 0
}));
});
});
});

0 comments on commit 50c4074

Please sign in to comment.