@@ -70,11 +70,11 @@ program
7070 )
7171 . option (
7272 '--output-directory [directory]' ,
73- 'Write test results to files, results written in JSON '
73+ 'Write test results to files, format is defined by --output-format '
7474 )
7575 . option (
76- '--junit' ,
77- 'Write test results to files, results written in JUnit XML format '
76+ '--output-format [jest | junit] ' ,
77+ 'Format for the output. (default: jest) '
7878 )
7979 . option (
8080 '--force' ,
@@ -184,6 +184,51 @@ configuration.baseUrl = program.baseUrl
184184 ? program . baseUrl
185185 : configuration . baseUrl
186186
187+ configuration . outputFormat = ( ) => ( {
188+ jestArguments : [ ] ,
189+ jestConfiguration : { } ,
190+ packageJsonConfiguration : { } ,
191+ } )
192+ if ( program . outputDirectory ) {
193+ const outputDirectory = path . isAbsolute ( program . outputDirectory )
194+ ? program . outputDirectory
195+ : path . join ( '..' , program . outputDirectory )
196+ const outputFormatConfigurations = {
197+ jest ( project ) {
198+ return {
199+ jestArguments : [
200+ '--json' ,
201+ '--outputFile' ,
202+ path . join ( outputDirectory , `${ project . name } .json` ) ,
203+ ] ,
204+ jestConfiguration : { } ,
205+ packageJsonConfiguration : { } ,
206+ }
207+ } ,
208+ junit ( project ) {
209+ return {
210+ jestArguments : [ ] ,
211+ jestConfiguration : { reporters : [ 'default' , 'jest-junit' ] } ,
212+ packageJsonConfiguration : {
213+ 'jest-junit' : {
214+ outputDirectory : outputDirectory ,
215+ outputName : `${ project . name } .xml` ,
216+ } ,
217+ } ,
218+ }
219+ } ,
220+ }
221+ const format = program . outputFormat ? program . outputFormat : 'jest'
222+ configuration . outputFormat = outputFormatConfigurations [ format ]
223+ if ( ! configuration . outputFormat ) {
224+ const allowedFormats = Object . keys ( outputFormatConfigurations ) . join ( ', ' )
225+ winston . error (
226+ `'${ format } 'is not an output format, allowed values: ${ allowedFormats } `
227+ )
228+ process . exit ( 1 )
229+ }
230+ }
231+
187232winston . debug ( util . inspect ( configuration ) )
188233
189234let projectPath
@@ -207,7 +252,7 @@ function runProject(project) {
207252 return Promise . reject (
208253 new Error (
209254 `The project ${
210- project . name
255+ project . name
211256 } has no test suites defined, create a suite using the IDE.`
212257 )
213258 )
@@ -232,18 +277,9 @@ function runProject(project) {
232277 ] ,
233278 testEnvironment : 'jest-environment-selenium' ,
234279 testEnvironmentOptions : configuration ,
235- ...( program . junit ? { reporters : [ 'default' , 'jest-junit' ] } : { } ) ,
280+ ...configuration . outputFormat ( project ) . jestConfiguration ,
236281 } ,
237- ...( program . junit && program . outputDirectory
238- ? {
239- 'jest-junit' : {
240- outputDirectory : path . isAbsolute ( program . outputDirectory )
241- ? program . outputDirectory
242- : '../' + program . outputDirectory ,
243- outputName : `${ project . name } .xml` ,
244- } ,
245- }
246- : { } ) ,
282+ ...configuration . outputFormat ( project ) . packageJsonConfiguration ,
247283 dependencies : project . dependencies || { } ,
248284 } ,
249285 null ,
@@ -269,7 +305,7 @@ function runProject(project) {
269305 writeJSFile (
270306 path . join ( projectPath , sanitizeFileName ( suite . name ) ) ,
271307 `// This file was generated using Selenium IDE\nconst tests = require("./commons.js");${
272- code . globalConfig
308+ code . globalConfig
273309 } ${ suite . code } ${ cleanup } `
274310 )
275311 } else if ( suite . tests . length ) {
@@ -283,7 +319,7 @@ function runProject(project) {
283319 sanitizeFileName ( test . name )
284320 ) ,
285321 `// This file was generated using Selenium IDE\nconst tests = require("../commons.js");${
286- code . globalConfig
322+ code . globalConfig
287323 } ${ test . code } `
288324 )
289325 } )
@@ -333,18 +369,7 @@ function runJest(project) {
333369 `{**/*${ program . filter } */*.test.js,**/*${ program . filter } *.test.js}` ,
334370 ]
335371 . concat ( program . maxWorkers ? [ '-w' , program . maxWorkers ] : [ ] )
336- . concat (
337- program . outputDirectory && ! program . junit
338- ? [
339- '--json' ,
340- '--outputFile' ,
341- path . isAbsolute ( program . outputDirectory )
342- ? path . join ( program . outputDirectory , `${ project . name } .json` )
343- : '../' +
344- path . join ( program . outputDirectory , `${ project . name } .json` ) ,
345- ]
346- : [ ]
347- )
372+ . concat ( configuration . outputFormat ( project ) . jestArguments )
348373 const opts = {
349374 cwd : path . join ( process . cwd ( ) , projectPath ) ,
350375 stdio : 'inherit' ,
0 commit comments