diff --git a/lib/images-info-saver.ts b/lib/images-info-saver.ts index 0ba8e7879..cec9fbd72 100644 --- a/lib/images-info-saver.ts +++ b/lib/images-info-saver.ts @@ -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)); @@ -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, { diff --git a/test/unit/lib/images-info-saver.ts b/test/unit/lib/images-info-saver.ts index 5d4bb3001..69708dda7 100644 --- a/test/unit/lib/images-info-saver.ts +++ b/test/unit/lib/images-info-saver.ts @@ -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 + })); + }); }); });