0

I have several mocha & chakram test case files, located on current directory:

test1.js
test2.js
test3.js
..and so on

I want to run a mocha test sequentially and generate a JSON reports for every test case.

What I want

Test1.json (result of test1.js)
Test2.json (result of test2.js)
Test3.json (result of test3.js)
..and so on

What I have tried

  1. Create a batch file which contains:

     mocha test1.js --reporter json > Test1.json
     mocha test2.js --reporter json > Test2.json
     mocha test3.js --reporter json > Test3.json
    

    When I run it, it runs only the first line

  2. Modified the batch file to be only one line

    mocha test1.js --reporter json > Test1.json test2.js --reporter json > Test2.json test3.js --reporter json > Test3.json

    This generates only one file 'Test3'.json. or

    mocha "./testfolder/*.js" --reporter json > Test.json

    This generates only one file.

  3. Using mocha --recursive

     mocha --recursive *.js --reporter > test1.json
    

    It goes to all subfolders. Even if this works, it will only generate one file. Reorganizing the folders is probably not an option.

  4. I have tried using mochawesome too.However, in this case, I want JSON file as the result / reporter.

How can I achieve this?

user2018
  • 310
  • 2
  • 7
  • 21

1 Answers1

1
mocha -R json test/main.js 2>&1 | tee ./selenium-results/selenium-results.json

This works for me. the ./selenium-results/selenium-results.json is where you would define your file path.

Amy Shin
  • 13
  • 6