11import { VisualRegressionTracker } from "./visualRegressionTracker" ;
2- import { Config , Build , TestRun , TestRunResult , TestRunStatus } from "./types" ;
2+ import {
3+ Config ,
4+ BuildResponse ,
5+ TestRun ,
6+ TestRunResponse ,
7+ TestStatus ,
8+ } from "./types" ;
39import { mocked } from "ts-jest/utils" ;
10+ import TestRunResult from "./testRunResult" ;
411import axios , { AxiosError , AxiosResponse } from "axios" ;
512
613jest . mock ( "axios" ) ;
714const mockedAxios = mocked ( axios , true ) ;
815
16+ jest . mock ( "./testRunResult" ) ;
17+ const mockedTestRunResult = mocked ( TestRunResult , true ) ;
18+
919const axiosError404 : AxiosError = {
1020 isAxiosError : true ,
1121 config : { } ,
@@ -118,68 +128,39 @@ describe("VisualRegressionTracker", () => {
118128 } ;
119129
120130 it ( "should track success" , async ( ) => {
121- const testRunResult : TestRunResult = {
131+ const testRunResponse : TestRunResponse = {
122132 url : "url" ,
123- status : TestRunStatus . ok ,
133+ status : TestStatus . ok ,
124134 pixelMisMatchCount : 12 ,
125135 diffPercent : 0.12 ,
126136 diffTollerancePercent : 0 ,
137+ id : "some id" ,
138+ imageName : "imageName" ,
139+ diffName : "diffName" ,
140+ baselineName : "baselineName" ,
141+ merge : false ,
127142 } ;
128- vrt [ "submitTestResult" ] = jest . fn ( ) . mockResolvedValueOnce ( testRunResult ) ;
143+ vrt [ "submitTestResult" ] = jest
144+ . fn ( )
145+ . mockResolvedValueOnce ( testRunResponse ) ;
146+ vrt [ "processTestRun" ] = jest . fn ( ) ;
129147
130148 await vrt . track ( testRun ) ;
131149
132150 expect ( vrt [ "submitTestResult" ] ) . toHaveBeenCalledWith ( testRun ) ;
133- } ) ;
134-
135- describe . each < [ TestRunStatus . new | TestRunStatus . unresolved , string ] > ( [
136- [ TestRunStatus . new , "No baseline: " ] ,
137- [ TestRunStatus . unresolved , "Difference found: " ] ,
138- ] ) ( "should track error" , ( status , expectedMessage ) => {
139- const testRunResultMock : TestRunResult = {
140- url : "http://foo.bar" ,
141- status : TestRunStatus . ok ,
142- pixelMisMatchCount : 12 ,
143- diffPercent : 0.12 ,
144- diffTollerancePercent : 0 ,
145- } ;
146-
147- beforeEach ( ( ) => {
148- testRunResultMock . status = status ;
149- } ) ;
150-
151- it ( `disabled soft assert should throw exception if status ${ status } ` , async ( ) => {
152- vrt [ "config" ] . enableSoftAssert = false ;
153- vrt [ "submitTestResult" ] = jest
154- . fn ( )
155- . mockResolvedValueOnce ( testRunResultMock ) ;
156-
157- await expect ( vrt . track ( testRun ) ) . rejects . toThrowError (
158- new Error ( expectedMessage . concat ( testRunResultMock . url ) )
159- ) ;
160- } ) ;
161-
162- it ( `enabled soft assert should log error if status ${ status } ` , async ( ) => {
163- console . error = jest . fn ( ) ;
164- vrt [ "config" ] . enableSoftAssert = true ;
165- vrt [ "submitTestResult" ] = jest
166- . fn ( )
167- . mockResolvedValueOnce ( testRunResultMock ) ;
168-
169- await vrt . track ( testRun ) ;
170-
171- expect ( console . error ) . toHaveBeenCalledWith (
172- expectedMessage . concat ( testRunResultMock . url )
173- ) ;
174- } ) ;
151+ expect ( vrt [ "processTestRun" ] ) . toHaveBeenCalledWith ( testRunResponse ) ;
152+ expect ( mockedTestRunResult ) . toHaveBeenCalledWith (
153+ testRunResponse ,
154+ "http://localhost:4200"
155+ ) ;
175156 } ) ;
176157 } ) ;
177158
178159 describe ( "start" , ( ) => {
179160 test ( "should start build" , async ( ) => {
180161 const buildId = "1312" ;
181162 const projectId = "asd" ;
182- const build : Build = {
163+ const build : BuildResponse = {
183164 id : buildId ,
184165 projectId : projectId ,
185166 } ;
@@ -261,12 +242,15 @@ describe("VisualRegressionTracker", () => {
261242
262243 describe ( "submitTestResults" , ( ) => {
263244 it ( "should submit test run" , async ( ) => {
264- const testRunResult : TestRunResult = {
245+ const testRunResponse : TestRunResponse = {
265246 url : "url" ,
266- status : TestRunStatus . unresolved ,
247+ status : TestStatus . unresolved ,
267248 pixelMisMatchCount : 12 ,
268249 diffPercent : 0.12 ,
269250 diffTollerancePercent : 0 ,
251+ id : "some id" ,
252+ imageName : "imageName" ,
253+ merge : false ,
270254 } ;
271255 const testRun : TestRun = {
272256 name : "name" ,
@@ -280,11 +264,11 @@ describe("VisualRegressionTracker", () => {
280264 const projectId = "asd" ;
281265 vrt [ "buildId" ] = buildId ;
282266 vrt [ "projectId" ] = projectId ;
283- mockedAxios . post . mockResolvedValueOnce ( { data : testRunResult } ) ;
267+ mockedAxios . post . mockResolvedValueOnce ( { data : testRunResponse } ) ;
284268
285269 const result = await vrt [ "submitTestResult" ] ( testRun ) ;
286270
287- expect ( result ) . toBe ( testRunResult ) ;
271+ expect ( result ) . toBe ( testRunResponse ) ;
288272 expect ( mockedAxios . post ) . toHaveBeenCalledWith (
289273 `${ config . apiUrl } /test-runs` ,
290274 {
@@ -337,7 +321,7 @@ describe("VisualRegressionTracker", () => {
337321 } ) ;
338322
339323 test ( "handleResponse" , async ( ) => {
340- const build : Build = {
324+ const build : BuildResponse = {
341325 id : "id" ,
342326 projectId : "projectId" ,
343327 } ;
@@ -375,4 +359,43 @@ describe("VisualRegressionTracker", () => {
375359 ) ;
376360 } ) ;
377361 } ) ;
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+ } ) ;
378401} ) ;
0 commit comments