@@ -2,6 +2,7 @@ import Q = require('q');
22import assert = require( 'assert' ) ;
33import path = require( 'path' ) ;
44const ff = require ( path . join ( __dirname , '..' , 'find-files-legacy.js' ) ) ;
5+ import { MockTestRunner } from 'azure-pipelines-task-lib/mock-test' ;
56
67describe ( 'PublishTestResultsV1 Find files legacy suite' , function ( ) {
78 this . timeout ( parseInt ( process . env . TASK_TEST_TIMEOUT ) || 20000 ) ;
@@ -100,29 +101,89 @@ describe('PublishTestResultsV1 Find files legacy suite', function () {
100101
101102 it ( 'Search simple pattern (relative path)' , ( done ) => {
102103 let relativePath = path . relative ( process . cwd ( ) , path . join ( __dirname , 'data' , '*.log' ) ) ;
103- let test = ff . findFiles ( path . join ( 'L0' , '..' , relativePath ) ) ;
104+ let test = ff . findFiles ( path . join ( 'L0' , '..' , relativePath ) ) ;
104105 assert ( test . length === 2 ) ;
105106 assert ( test [ 0 ] === posixFormat ( path . join ( data , 'a.log' ) ) ) ;
106107 assert ( test [ 1 ] === posixFormat ( path . join ( data , 'b.log' ) ) ) ;
107108 done ( ) ;
108109 } ) ;
109110
110111 it ( 'Search pattern seperated by semi-colon(delimiter)' , ( done ) => {
111- let test = ff . findFiles ( path . join ( data , '*.log' ) + ";" + path . join ( data , '*.txt' ) ) ;
112+ let test = ff . findFiles ( path . join ( data , '*.log' ) + ";" + path . join ( data , '*.txt' ) ) ;
112113 assert ( test . length === 4 ) ;
113114 assert ( test [ 0 ] === posixFormat ( path . join ( data , 'a.log' ) ) ) ;
114115 assert ( test [ 1 ] === posixFormat ( path . join ( data , 'b.log' ) ) ) ;
115116 assert ( test [ 2 ] === posixFormat ( path . join ( data , 'a.txt' ) ) ) ;
116117 assert ( test [ 3 ] === posixFormat ( path . join ( data , 'b.txt' ) ) ) ;
117118 done ( ) ;
118119 } ) ;
119-
120+
120121 it ( 'Search pattern seperated by semi-colon(delimiter)' , ( done ) => {
121122 let test = ff . findFiles ( path . join ( data , 'a*' ) + ";-:" + path . join ( data , 'a.txt' ) ) ;
122123 assert ( test . length === 1 ) ;
123124 assert ( test [ 0 ] === posixFormat ( path . join ( data , 'a.log' ) ) ) ;
124125 done ( ) ;
125126 } ) ;
127+
128+ it ( 'Publish test results with resultFiles filter that does not match with any files' , function ( done : Mocha . Done ) {
129+ const testPath = path . join ( __dirname , 'L0FilterDoesNotMatchAnyFile.js' )
130+ const tr : MockTestRunner = new MockTestRunner ( testPath ) ;
131+ tr . run ( ) ;
132+
133+ assert ( tr . stderr . length == 0 , 'should not have written to stderr. error: ' + tr . stderr ) ;
134+ assert ( tr . succeeded , 'task should have succeeded' ) ;
135+ assert ( tr . invokedToolCount == 0 , 'should exit before running PublishTestResults' ) ;
136+ done ( ) ;
137+ } ) ;
138+
139+ it ( 'Publish test results with resultFiles filter that matches with some files' , function ( done : Mocha . Done ) {
140+ const testPath = path . join ( __dirname , 'L0FilterMatchesSomeFile.js' )
141+ const tr : MockTestRunner = new MockTestRunner ( testPath ) ;
142+ tr . run ( ) ;
143+
144+ assert ( tr . stderr . length == 0 , 'should not have written to stderr. error: ' + tr . stderr ) ;
145+ assert ( tr . succeeded , 'task should have succeeded' ) ;
146+ assert ( tr . stdout . search ( / # # v s o \[ r e s u l t s .p u b l i s h t y p e = J U n i t ; m e r g e R e s u l t s = t r u e ; r e s u l t F i l e s = / ) >= 0 , 'should publish test results.' ) ;
147+ done ( ) ;
148+ } ) ;
149+
150+ it ( 'Publish test results with resultFiles as file path' , function ( done : Mocha . Done ) {
151+ const testPath = path . join ( __dirname , 'L0ResultFilesAsFilePath.js' )
152+ const tr : MockTestRunner = new MockTestRunner ( testPath ) ;
153+ tr . run ( ) ;
154+
155+ assert ( tr . stderr . length == 0 , 'should not have written to stderr. error: ' + tr . stderr ) ;
156+ assert ( tr . succeeded , 'task should have succeeded' ) ;
157+ assert ( tr . stdout . search ( / # # v s o \[ r e s u l t s .p u b l i s h t y p e = J U n i t ; r e s u l t F i l e s = / ) >= 0 , 'should publish test results.' ) ;
158+ done ( ) ;
159+ } ) ;
160+
161+ it ( 'Publish test results when test result files input is not provided' , function ( done : Mocha . Done ) {
162+ const testPath = path . join ( __dirname , 'L0InputIsNotProvided.js' )
163+ const tr : MockTestRunner = new MockTestRunner ( testPath ) ;
164+ tr . run ( ) ;
165+
166+ assert ( tr . stdout . length > 0 , 'should have written to stderr' ) ;
167+ assert ( tr . stdout . indexOf ( 'Input required: testResultsFiles' ) >= 0 , 'wrong error message: "' + tr . stdout + '"' ) ;
168+ assert ( tr . failed , 'task should have failed' ) ;
169+ assert ( tr . invokedToolCount == 0 , 'should exit before running PublishTestResults' ) ;
170+
171+ done ( ) ;
172+ } ) ;
173+
174+ it ( 'Publish test results when test runner type input is not provided' , function ( done : Mocha . Done ) {
175+ const testPath = path . join ( __dirname , 'L0TestRunnerTypeIsNotProvided.js' )
176+ const tr : MockTestRunner = new MockTestRunner ( testPath ) ;
177+ tr . run ( ) ;
178+
179+ assert ( tr . stdout . length > 0 , 'should have written to stdout' ) ;
180+ assert ( tr . stdout . indexOf ( 'Input required: testRunner' ) >= 0 , 'wrong error message: "' + tr . stdout + '"' ) ;
181+ assert ( tr . failed , 'task should have failed' ) ;
182+ assert ( tr . invokedToolCount == 0 , 'should exit before running PublishTestResults' ) ;
183+
184+ done ( ) ;
185+ } ) ;
186+
126187} ) ;
127188
128189function posixFormat ( p : string ) : string {
0 commit comments