|
1 | 1 | import { VisualRegressionTracker } from "./visualRegressionTracker"; |
2 | | -import { Config, BuildResponse, TestRun, TestRunResponse, TestStatus } from "./types"; |
| 2 | +import { |
| 3 | + Config, |
| 4 | + BuildResponse, |
| 5 | + TestRun, |
| 6 | + TestRunResponse, |
| 7 | + TestStatus, |
| 8 | +} from "./types"; |
3 | 9 | import { mocked } from "ts-jest/utils"; |
4 | 10 | import TestRunResult from "./testRunResult"; |
5 | 11 | import axios, { AxiosError, AxiosResponse } from "axios"; |
@@ -137,60 +143,17 @@ describe("VisualRegressionTracker", () => { |
137 | 143 | vrt["submitTestResult"] = jest |
138 | 144 | .fn() |
139 | 145 | .mockResolvedValueOnce(testRunResponse); |
| 146 | + vrt["processTestRun"] = jest.fn(); |
140 | 147 |
|
141 | 148 | await vrt.track(testRun); |
142 | 149 |
|
143 | 150 | expect(vrt["submitTestResult"]).toHaveBeenCalledWith(testRun); |
| 151 | + expect(vrt["processTestRun"]).toHaveBeenCalledWith(testRunResponse); |
144 | 152 | expect(mockedTestRunResult).toHaveBeenCalledWith( |
145 | 153 | testRunResponse, |
146 | 154 | "http://localhost:4200" |
147 | 155 | ); |
148 | 156 | }); |
149 | | - |
150 | | - describe.each<[TestStatus.new | TestStatus.unresolved, string]>([ |
151 | | - [TestStatus.new, "No baseline: "], |
152 | | - [TestStatus.unresolved, "Difference found: "], |
153 | | - ])("should track error", (status, expectedMessage) => { |
154 | | - const testRunResponseMock: TestRunResponse = { |
155 | | - url: "http://foo.bar", |
156 | | - status: TestStatus.ok, |
157 | | - pixelMisMatchCount: 12, |
158 | | - diffPercent: 0.12, |
159 | | - diffTollerancePercent: 0, |
160 | | - id: "some id", |
161 | | - imageName: "imageName", |
162 | | - merge: false, |
163 | | - }; |
164 | | - |
165 | | - beforeEach(() => { |
166 | | - testRunResponseMock.status = status; |
167 | | - }); |
168 | | - |
169 | | - it(`disabled soft assert should throw exception if status ${status}`, async () => { |
170 | | - vrt["config"].enableSoftAssert = false; |
171 | | - vrt["submitTestResult"] = jest |
172 | | - .fn() |
173 | | - .mockResolvedValueOnce(testRunResponseMock); |
174 | | - |
175 | | - await expect(vrt.track(testRun)).rejects.toThrowError( |
176 | | - new Error(expectedMessage.concat(testRunResponseMock.url)) |
177 | | - ); |
178 | | - }); |
179 | | - |
180 | | - it(`enabled soft assert should log error if status ${status}`, async () => { |
181 | | - console.error = jest.fn(); |
182 | | - vrt["config"].enableSoftAssert = true; |
183 | | - vrt["submitTestResult"] = jest |
184 | | - .fn() |
185 | | - .mockResolvedValueOnce(testRunResponseMock); |
186 | | - |
187 | | - await vrt.track(testRun); |
188 | | - |
189 | | - expect(console.error).toHaveBeenCalledWith( |
190 | | - expectedMessage.concat(testRunResponseMock.url) |
191 | | - ); |
192 | | - }); |
193 | | - }); |
194 | 157 | }); |
195 | 158 |
|
196 | 159 | describe("start", () => { |
@@ -396,4 +359,43 @@ describe("VisualRegressionTracker", () => { |
396 | 359 | ); |
397 | 360 | }); |
398 | 361 | }); |
| 362 | + |
| 363 | + describe.each<[TestStatus.new | TestStatus.unresolved, string]>([ |
| 364 | + [TestStatus.new, "No baseline: "], |
| 365 | + [TestStatus.unresolved, "Difference found: "], |
| 366 | + ])("processTestRun", (status, expectedMessage) => { |
| 367 | + const testRunResponse: TestRunResponse = { |
| 368 | + url: "http://foo.bar", |
| 369 | + status: TestStatus.ok, |
| 370 | + pixelMisMatchCount: 12, |
| 371 | + diffPercent: 0.12, |
| 372 | + diffTollerancePercent: 0, |
| 373 | + id: "some id", |
| 374 | + imageName: "imageName", |
| 375 | + merge: false, |
| 376 | + }; |
| 377 | + |
| 378 | + beforeEach(() => { |
| 379 | + testRunResponse.status = status; |
| 380 | + }); |
| 381 | + |
| 382 | + it(`disabled soft assert should throw exception if status ${status}`, () => { |
| 383 | + vrt["config"].enableSoftAssert = false; |
| 384 | + |
| 385 | + expect(() => vrt["processTestRun"](testRunResponse)).toThrowError( |
| 386 | + new Error(expectedMessage.concat(testRunResponse.url)) |
| 387 | + ); |
| 388 | + }); |
| 389 | + |
| 390 | + it(`enabled soft assert should log error if status ${status}`, () => { |
| 391 | + console.error = jest.fn(); |
| 392 | + vrt["config"].enableSoftAssert = true; |
| 393 | + |
| 394 | + vrt["processTestRun"](testRunResponse); |
| 395 | + |
| 396 | + expect(console.error).toHaveBeenCalledWith( |
| 397 | + expectedMessage.concat(testRunResponse.url) |
| 398 | + ); |
| 399 | + }); |
| 400 | + }); |
399 | 401 | }); |
0 commit comments