簡體   English   中英

使用多個js文件運行Mocha測試並生成單獨的JSON報告

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

我在當前目錄中有幾個mocha&chakram測試用例文件:

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

我想按順序運行Mocha測試並為每個測試用例生成JSON報告。

我想要的是

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

我嘗試過的

  1. 創建一個批處理文件,其中包含:

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

    當我運行它時,它僅運行第一行

  2. 將批處理文件修改為僅一行

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

    這樣只會生成一個文件“ Test3” .json。 要么

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

    這樣只會生成一個文件。

  3. 使用mocha --recursive

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

    它適用於所有子文件夾。 即使此方法有效,也只會生成一個文件。 重新組織文件夾可能不是一個選擇。

  4. 我也嘗試使用mochawesome,但是在這種情況下,我想要JSON文件作為結果/報告者。

我該如何實現?

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

這對我有用。 您可以在./selenium-results/selenium-results.json文件中定義文件路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM