jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.34k stars 6.47k forks source link

Add --json flag to programmatically consume the test output #513

Closed ide closed 9 years ago

ide commented 9 years ago

I want to use this with arcanist so making it easy to parse the output is helpful.

cpojer commented 9 years ago

yes! I'll look into what format we are using for arc unit and whether I can just open source that :)

mhagmajer commented 9 years ago

@cpojer, Any updates here?

cpojer commented 9 years ago

Yes this is planned but I wish I had 10 hours more per day to work on jest!

cpojer commented 9 years ago

This will be in 0.6.0.

ide commented 9 years ago

Thanks @cpojer!

cpojer commented 9 years ago

https://github.com/facebook/jest/commit/5413b7ba6dd4e0b34ce99e51b1691fbe8dc196f5

@ide care to try this out to see if it works for you? I wanna tag 0.6.0 tomorrow or so.

ide commented 9 years ago

It's going to take me awhile to hook this up to arcanist (need to write a bunch of PHP) so go ahead and publish it.

The --json flag works for a small project of mine though :)

$ npm test -- --json

> dash-button@1.0.0 test /Users/ide/Code/dash-button
> jest "--json"

Using Jest CLI v0.6.0-alpha
 PASS  src/__tests__/MacAddresses-test.js (0.56s)
 PASS  src/__tests__/NetworkInterfaces-test.js (0.594s)
 PASS  src/__tests__/ArpProbes-test.js (0.635s)
 PASS  src/__tests__/DashButton-test.js (2.197s)
4 tests passed (4 total)
Run time: 2.887s
{"success":true,"startTime":1445401855029,"numTotalTests":4,"numPassedTests":4,"numFailedTests":0,"testResults":[{"name":"/Users/ide/Code/dash-button/src/__tests__/MacAddresses-test.js","summary":"","message":"","status":"passed","startTime":1445401855747,"endTime":1445401856307,"coverage":{}},{"name":"/Users/ide/Code/dash-button/src/__tests__/NetworkInterfaces-test.js","summary":"","message":"","status":"passed","startTime":1445401855719,"endTime":1445401856313,"coverage":{}},{"name":"/Users/ide/Code/dash-button/src/__tests__/ArpProbes-test.js","summary":"","message":"","status":"passed","startTime":1445401855722,"endTime":1445401856357,"coverage":{}},{"name":"/Users/ide/Code/dash-button/src/__tests__/DashButton-test.js","summary":"","message":"","status":"passed","startTime":1445401855717,"endTime":1445401857914,"coverage":{}}],"postSuiteHeaders":[]}
cpojer commented 9 years ago

Right, the question is more like:

ide commented 9 years ago

Yeah it should, just trying to fill in the main fields here: https://secure.phabricator.com/diffusion/ARC/browse/master/src/unit/ArcanistUnitTestResult.php;e51e1c3d44640d60c9843c6f41ee06434cadf697$150. Name, result, and duration are the most important and looks like those are covered :)

    return array(
      'namespace' => $this->getNamespace(),
      'name' => $this->getName(),
      'link' => $this->getLink(),
      'result' => $this->getResult(),
      'duration' => $this->getDuration(),
      'extra' => $this->getExtraData(),
      'userData' => $this->getUserData(),
      'coverage' => $this->getCoverage(),
    );
cpojer commented 9 years ago

Cool. I mean this is the same code we use at FB for arc/phabricator so I guess this is fine.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.