@@ -4,66 +4,86 @@ var paths = require('../util/paths');
4
4
var fs = require ( 'fs' ) ;
5
5
var path = require ( 'path' ) ;
6
6
var _ = require ( 'underscore' ) ;
7
-
7
+ var junitWriter = new ( require ( 'junitwriter' ) ) ( ) ;
8
8
9
9
gulp . task ( 'compare' , function ( done ) {
10
- var compareConfig = JSON . parse ( fs . readFileSync ( paths . compareConfigFileName , 'utf8' ) ) . compareConfig ;
11
-
12
- function updateProgress ( ) {
13
- var results = { } ;
14
- _ . each ( compareConfig . testPairs , function ( pair ) {
15
- if ( ! results [ pair . testStatus ] ) {
16
- results [ pair . testStatus ] = 0 ;
17
- }
18
- ! results [ pair . testStatus ] ++ ;
19
- } ) ;
20
- if ( ! results . running ) {
21
- console . log ( '\nTest completed...' ) ;
22
- console . log ( '\x1b[32m' , ( results . pass || 0 ) + ' Passed' , '\x1b[0m' ) ;
23
- console . log ( '\x1b[31m' , ( results . fail || 0 ) + ' Failed\n' , '\x1b[0m' ) ;
10
+ var compareConfig = JSON . parse ( fs . readFileSync ( paths . compareConfigFileName , 'utf8' ) ) . compareConfig ,
11
+ testSuite = paths . report && paths . report . indexOf ( 'CI' ) > - 1 && paths . ciReport . format === 'junit' && junitWriter . addTestsuite ( paths . ci . testSuiteName ) ,
12
+ testPairsLength ;
24
13
25
- if ( results . fail ) {
26
- console . log ( '\x1b[31m' , '*** Mismatch errors found ***' , '\x1b[0m' ) ;
27
- console . log ( "For a detailed report run `npm run openReport`\n" ) ;
28
- done ( new Error ( 'Mismatch errors found.' ) ) ;
29
- } else {
30
- done ( ) ;
31
- }
14
+ function updateProgress ( ) {
15
+ var results = { } ;
16
+ _ . each ( compareConfig . testPairs , function ( pair ) {
17
+ if ( ! results [ pair . testStatus ] ) {
18
+ results [ pair . testStatus ] = 0 ;
19
+ }
20
+ ! results [ pair . testStatus ] ++ ;
21
+ } ) ;
22
+ if ( ! results . running ) {
23
+ console . log ( '\nTest completed...' ) ;
24
+ console . log ( '\x1b[32m' , ( results . pass || 0 ) + ' Passed' , '\x1b[0m' ) ;
25
+ console . log ( '\x1b[31m' , ( results . fail || 0 ) + ' Failed\n' , '\x1b[0m' ) ;
32
26
27
+ if ( results . fail ) {
28
+ console . log ( '\x1b[31m' , '*** Mismatch errors found ***' , '\x1b[0m' ) ;
29
+ console . log ( "For a detailed report run `npm run openReport`\n" ) ;
30
+ if ( paths . cliExitOnFail ) {
31
+ done ( new Error ( 'Mismatch errors found.' ) ) ;
32
+ }
33
+ }
34
+ }
33
35
}
34
- }
35
36
36
37
37
- _ . each ( compareConfig . testPairs , function ( pair ) {
38
- pair . testStatus = "running" ;
38
+ _ . each ( compareConfig . testPairs , function ( pair , key ) {
39
+ pair . testStatus = "running" ;
40
+ testPairsLength = ! testPairsLength && compareConfig . testPairs . length ;
41
+
42
+
43
+ var referencePath = path . join ( paths . backstop , pair . reference ) ;
44
+ var testPath = path . join ( paths . backstop , pair . test ) ;
39
45
40
- var referencePath = path . join ( paths . backstop , pair . reference ) ;
41
- var testPath = path . join ( paths . backstop , pair . test ) ;
46
+ resemble ( referencePath ) . compareTo ( testPath ) . onComplete ( function ( data ) {
47
+ var imageComparisonFailed = ! data . isSameDimensions || data . misMatchPercentage > pair . misMatchThreshold ,
48
+ error ,
49
+ testCase ;
42
50
43
- resemble ( referencePath ) . compareTo ( testPath ) . onComplete ( function ( data ) {
44
- var imageComparisonFailed = ! data . isSameDimensions || data . misMatchPercentage > pair . misMatchThreshold ;
51
+ if ( imageComparisonFailed ) {
52
+ pair . testStatus = "fail" ;
53
+ console . log ( '\x1b[31m' , 'ERROR:' , pair . label , pair . fileName , '\x1b[0m' ) ;
54
+ storeFailedDiffImage ( testPath , data ) ;
55
+ } else {
56
+ pair . testStatus = "pass" ;
57
+ console . log ( '\x1b[32m' , 'OK:' , pair . label , pair . fileName , '\x1b[0m' ) ;
58
+ }
45
59
46
- if ( imageComparisonFailed ) {
47
- pair . testStatus = "fail" ;
48
- console . log ( '\x1b[31m' , 'ERROR:' , pair . label , pair . fileName , '\x1b[0m' ) ;
49
- storeFailedDiffImage ( testPath , data ) ;
50
- } else {
51
- pair . testStatus = "pass" ;
52
- console . log ( '\x1b[32m' , 'OK:' , pair . label , pair . fileName , '\x1b[0m' ) ;
53
- }
54
- updateProgress ( ) ;
60
+ // add testcase only when there is a design deviation
61
+ if ( testSuite && imageComparisonFailed ) {
62
+ testCase = testSuite . addTestcase ( ' ›› ' + pair . label , pair . selector ) ;
63
+ error = 'Design deviation ›› ' + pair . label + ' (' + pair . selector + ') component' ;
64
+ testCase . addError ( error , 'CSS component' ) ;
65
+ testCase . addFailure ( error , 'CSS component' ) ;
66
+ }
67
+
68
+ if ( testSuite && testPairsLength === key + 1 ) {
69
+ junitWriter . save ( path . join ( paths . ci_report , 'xunit.xml' ) , function ( ) {
70
+ console . log ( '\x1b[32m' , 'Regression test report file (xunit.xml) is successfully created.' , '\x1b[0m' ) ;
71
+ } ) ;
72
+ }
73
+
74
+ updateProgress ( ) ;
75
+ } ) ;
55
76
} ) ;
56
- } ) ;
57
77
58
- function storeFailedDiffImage ( testPath , data ) {
59
- var failedDiffFilename = getFailedDiffFilename ( testPath ) ;
60
- console . log ( ' See:' , failedDiffFilename ) ;
61
- var failedDiffStream = fs . createWriteStream ( failedDiffFilename ) ;
62
- data . getDiffImage ( ) . pack ( ) . pipe ( failedDiffStream )
63
- }
78
+ function storeFailedDiffImage ( testPath , data ) {
79
+ var failedDiffFilename = getFailedDiffFilename ( testPath ) ;
80
+ console . log ( ' See:' , failedDiffFilename ) ;
81
+ var failedDiffStream = fs . createWriteStream ( failedDiffFilename ) ;
82
+ data . getDiffImage ( ) . pack ( ) . pipe ( failedDiffStream )
83
+ }
64
84
65
- function getFailedDiffFilename ( testPath ) {
66
- var lastSlash = testPath . lastIndexOf ( path . sep ) ;
67
- return testPath . slice ( 0 , lastSlash + 1 ) + 'failed_diff_' + testPath . slice ( lastSlash + 1 , testPath . length ) ;
68
- }
85
+ function getFailedDiffFilename ( testPath ) {
86
+ var lastSlash = testPath . lastIndexOf ( path . sep ) ;
87
+ return testPath . slice ( 0 , lastSlash + 1 ) + 'failed_diff_' + testPath . slice ( lastSlash + 1 , testPath . length ) ;
88
+ }
69
89
} ) ;
0 commit comments