简体   繁体   English

使用多个js文件运行Mocha测试并生成单独的JSON报告

[英]Run a mocha test with multiple js files and generate separate JSON reports

I have several mocha & chakram test case files, located on current directory: 我在当前目录中有几个mocha&chakram测试用例文件:

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. 我想按顺序运行Mocha测试并为每个测试用例生成JSON报告。

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. 这样只会生成一个文件“ Test3” .json。 or 要么

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

    This generates only one file. 这样只会生成一个文件。

  3. Using mocha --recursive 使用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. 我也尝试使用mochawesome,但是在这种情况下,我想要JSON文件作为结果/报告者。

How can I achieve this? 我该如何实现?

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. 您可以在./selenium-results/selenium-results.json文件中定义文件路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM