@wdio/image-comparison-core 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @wdio/image-comparison-core
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 340fbe6: # 🐛 Bugfixes
8
+
9
+ ## #1098 Improve error message when baseline is missing and both flags are false
10
+
11
+ When `autoSaveBaseline = false` and `alwaysSaveActualImage = false` and a baseline image doesn't exist, the error message now provides clear guidance suggesting users set `alwaysSaveActualImage` to `true` if they need the actual image to create a baseline manually.
12
+
13
+ # Committers: 1
14
+
15
+ - Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
16
+
17
+ - e4e5b5c: # 🐛 Bugfixes
18
+
19
+ ## #1085 autoSaveBaseline collides with the new alwaysSaveActualImage flag
20
+
21
+ When `autoSaveBaseline` is `true` and `alwaysSaveActualImage` is `false`, actual images were still saved. This patch should fix that
22
+
23
+ # Committers: 1
24
+
25
+ - Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
26
+
3
27
  ## 1.1.0
4
28
 
5
29
  ### Minor Changes
@@ -94,7 +94,7 @@ vi.mock('./images.js', async () => {
94
94
  addBlockOuts: vi.fn(),
95
95
  };
96
96
  });
97
- import { executeImageCompare } from './images.js';
97
+ import { executeImageCompare, checkBaselineImageExists } from './images.js';
98
98
  import * as images from './images.js';
99
99
  describe('executeImageCompare', () => {
100
100
  const mockDeviceRectangles = {
@@ -597,6 +597,12 @@ describe('executeImageCompare', () => {
597
597
  autoSaveBaseline: true,
598
598
  }
599
599
  };
600
+ vi.mocked(fsPromises.access).mockImplementation(async (path) => {
601
+ if (path === '/mock/baseline/test.png') {
602
+ throw new Error('File not found');
603
+ }
604
+ return undefined;
605
+ });
600
606
  vi.mocked(compareImages.default).mockResolvedValue({
601
607
  rawMisMatchPercentage: 0,
602
608
  misMatchPercentage: 0,
@@ -908,4 +914,74 @@ describe('executeImageCompare', () => {
908
914
  expect(images.saveBase64Image).not.toHaveBeenCalled();
909
915
  expect(log.warn).not.toHaveBeenCalled();
910
916
  });
917
+ it('should not save actual image when autoSaveBaseline is true, alwaysSaveActualImage is false, baseline exists, and comparison passes', async () => {
918
+ // This test covers issue #1085: autoSaveBaseline collides with alwaysSaveActualImage
919
+ // When baseline exists and comparison passes, actual image should NOT be saved
920
+ const base64Image = Buffer.from('base64-image').toString('base64');
921
+ const optionsWithAutoSave = {
922
+ ...mockOptions,
923
+ folderOptions: {
924
+ ...mockOptions.folderOptions,
925
+ alwaysSaveActualImage: false,
926
+ autoSaveBaseline: true,
927
+ }
928
+ };
929
+ vi.mocked(fsPromises.access).mockResolvedValue(undefined);
930
+ vi.mocked(images.checkBaselineImageExists).mockImplementation(async () => {
931
+ return Promise.resolve();
932
+ });
933
+ vi.mocked(compareImages.default).mockResolvedValue({
934
+ rawMisMatchPercentage: 0,
935
+ misMatchPercentage: 0,
936
+ getBuffer: vi.fn().mockResolvedValue(Buffer.from('diff-image-data')),
937
+ diffBounds: { left: 0, top: 0, right: 0, bottom: 0 },
938
+ analysisTime: 10,
939
+ diffPixels: []
940
+ });
941
+ await executeImageCompare({
942
+ isViewPortScreenshot: true,
943
+ isNativeContext: false,
944
+ options: optionsWithAutoSave,
945
+ testContext: mockTestContext,
946
+ actualBase64Image: base64Image,
947
+ });
948
+ expect(images.saveBase64Image).not.toHaveBeenCalled();
949
+ expect(fsPromises.writeFile).not.toHaveBeenCalledWith('/mock/actual/test.png', expect.anything());
950
+ });
951
+ it('should not save actual image when baseline does not exist, alwaysSaveActualImage is false, and autoSaveBaseline is false', async () => {
952
+ // This test covers issue #1098: When both flags are false, we respect the user's choice
953
+ // and provide a helpful error message suggesting to adjust the arguments if needed
954
+ const base64Image = Buffer.from('base64-image').toString('base64');
955
+ const optionsWithoutAutoSave = {
956
+ ...mockOptions,
957
+ folderOptions: {
958
+ ...mockOptions.folderOptions,
959
+ alwaysSaveActualImage: false,
960
+ autoSaveBaseline: false,
961
+ }
962
+ };
963
+ vi.mocked(fsPromises.access).mockImplementation(async (path) => {
964
+ if (path === '/mock/baseline/test.png' || path === '/mock/actual/test.png') {
965
+ throw new Error('File not found');
966
+ }
967
+ return undefined;
968
+ });
969
+ vi.mocked(images.checkBaselineImageExists).mockImplementation(checkBaselineImageExists);
970
+ vi.mocked(compareImages.default).mockResolvedValue({
971
+ rawMisMatchPercentage: 0,
972
+ misMatchPercentage: 0,
973
+ getBuffer: vi.fn().mockResolvedValue(Buffer.from('diff-image-data')),
974
+ diffBounds: { left: 0, top: 0, right: 0, bottom: 0 },
975
+ analysisTime: 10,
976
+ diffPixels: []
977
+ });
978
+ await expect(executeImageCompare({
979
+ isViewPortScreenshot: true,
980
+ isNativeContext: false,
981
+ options: optionsWithoutAutoSave,
982
+ testContext: mockTestContext,
983
+ actualBase64Image: base64Image,
984
+ })).rejects.toThrow(/If you need the actual image to create a baseline, please set alwaysSaveActualImage to true/);
985
+ expect(images.saveBase64Image).not.toHaveBeenCalled();
986
+ });
911
987
  });
@@ -77,11 +77,11 @@ export async function checkBaselineImageExists({ actualFilePath, baselineFilePat
77
77
  const actualFileExists = await checkIfImageExists(actualFilePath);
78
78
  const filePathMessage = actualFileExists
79
79
  ? `The image can be found here:\n${actualFilePath}`
80
- : 'The actual image was not saved to disk (alwaysSaveActualImage is false).';
80
+ : 'The actual image was not saved to disk (alwaysSaveActualImage is false).\nIf you need the actual image to create a baseline, please set alwaysSaveActualImage to true.';
81
81
  throw new Error(`
82
82
  #####################################################################################
83
- Baseline image not found, save the actual image manually to the baseline.
84
- ${filePathMessage}
83
+ Baseline image not found, save the actual image manually to the baseline.
84
+ ${filePathMessage}
85
85
  #####################################################################################`);
86
86
  }
87
87
  }
@@ -262,8 +262,8 @@ export async function executeImageCompare({ isViewPortScreenshot, isNativeContex
262
262
  if (useBase64Image) {
263
263
  // Convert base64 to buffer for comparison
264
264
  actualImageBuffer = Buffer.from(actualBase64Image, 'base64');
265
- // Only save if autoSaveBaseline is true (needed to copy to baseline)
266
- if (autoSaveBaseline) {
265
+ // Only save actual image if baseline doesn't exist and autoSaveBaseline is true
266
+ if (autoSaveBaseline && !(await checkIfImageExists(baselineFilePath))) {
267
267
  await saveBase64Image(actualBase64Image, actualFilePath);
268
268
  }
269
269
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/image-comparison-core",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "author": "Wim Selles - wswebcreation",
5
5
  "description": "Image comparison core module for @wdio/visual-service - WebdriverIO visual testing framework",
6
6
  "keywords": [
@@ -31,7 +31,7 @@
31
31
  "@wdio/types": "^9.20.0"
32
32
  },
33
33
  "devDependencies": {
34
- "webdriverio": "^9.20.1"
34
+ "webdriverio": "^9.23.0"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"