marklogic-community / roxy

Deployment tool for MarkLogic applications. Also provides optional unit test and XQuery MVC structure
Other
87 stars 66 forks source link

Output of SJS Unit Tests not reported correctly in UI #854

Closed tternquist closed 6 years ago

tternquist commented 6 years ago

CC @dmcassel

The issue

Short description of the problem: When using SJS unit tests the outputs do not appear to be correctly reported. Instead of a count, the output for tests run, passed and failed are each "-"

What are the steps to reproduce the problem? Can reproduce with these contents as a test file under any test suite:

const test = require("/test/test-helper.xqy");

(function testOne() {
    var actual = 2;
    return [test.assertEqual(3, actual), test.assertEqual(3, actual)];
})();
(function testTwo() {
    var actual = 1;
    return [test.assertEqual(3, actual), test.assertEqual(3, actual)];
})();

When run i see the following:

image

Tech Specs

Which Operating System are you using? MacOS Sierra

Which version of MarkLogic are you using? 9.0-2

Which version of Roxy are you using (see version.txt)? v1.7.7

rjkennedy98 commented 6 years ago

Can we prioritize this being fixed as there is currently no alternative for unit testing with SJS.

dmcassel commented 6 years ago

@tternquist @rjkennedy98 I just submitted a PR to fix this. Would either of you be able to check out that version and confirm that it works the way you're looking for?

rjkennedy98 commented 6 years ago

@dmcassel Yes, I can do some verification. Thanks.

rjkennedy98 commented 6 years ago

Its working for me. Thanks @dmcassel

rjkennedy98 commented 6 years ago

Actually, looking more closely. There are a few weird things:

  1. suiteSetup.sjs and suiteTeardown.sjs appear.
  2. We only have 1 test with 1 assert. Not sure why the tests total is 2.
  3. SuiteSetup.sjs is appearing twice in this list.
<testsuite errors="0" failures="0" hostname="localhost" name="edl-ml-cash-pos" tests="2" time="0.049995" timestamp="">
  <testcase classname="suiteSetup.sjs" name="suiteSetup.sjs" time="0.0079992"/>
  <testcase classname="get.sjs" name="get.sjs" time="0.0319968"/>
  <testcase classname="suiteSetup.sjs" name="suiteSetup.sjs" time="0.0059994"/>
  <testcase classname="suiteTeardown.sjs" name="suiteTeardown.sjs" time="0.0019998"/>
</testsuite>

Here is our get.sjs:

var cashPos = require("/marklogic.rest.resource/edl-ml-cash-pos/assets/resource.sjs")
var test = require('/test/test-helper.xqy');

function testHappyPath() {
  var params = {
    "accountId": "0116928",
    "asOfDate": "2017-09-10",
    "positionSK": "74779212",
  }
  var context = {}
  var response = cashPos.GET(context, params);
  xdmp.log(response);
  return test.assertExists(response);
}

[ testHappyPath()];
dmcassel commented 6 years ago

@rjkennedy98 I just pushed a commit that should fix that. Please retest.

dmcassel commented 6 years ago

@tternquist @rjkennedy98 ping. I think the PR fixes this bug, but it would be helpful to have a quick independent test. Either of you have a little time to do so?

rjkennedy98 commented 6 years ago

@dmcassel It seems to be working now. 2 things to note: 1) the Unit Test Wiki has incorrect documentation on how to do the tests Unit Test Wiki

2) The secret sauce is doing flatten out all the assertions.

[].concat(testOne(), testTwo())
dmcassel commented 6 years ago

fixed in dev