Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure right image states order html-reporter #538

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}));
});
});
});
Loading