Repository navigation
ValueError: Descending test id on line ... #50
Description
Trying to use this to convert the tap output from the built-in test runner to junit for CI/CD use.
# ~/.local/bin/tap2junit -i tests/report.txt -o tests/report.xml
Traceback (most recent call last):
File "~/.local/bin/tap2junit", line 8, in <module>
sys.exit(main())
File "~/.local/pipx/venvs/tap2junit/lib/python3.8/site-packages/tap2junit/__main__.py", line 94, in main
convert(
File "~/.local/pipx/venvs/tap2junit/lib/python3.8/site-packages/tap2junit/__main__.py", line 68, in convert
result = parse(name or input_file, data, package)
File "~/.local/pipx/venvs/tap2junit/lib/python3.8/site-packages/tap2junit/__main__.py", line 58, in parse
tap_parser.parse(data)
File "~/.local/pipx/venvs/tap2junit/lib/python3.8/site-packages/tap2junit/tap13.py", line 238, in parse
self._parse(io.StringIO(source))
File "~/.local/pipx/venvs/tap2junit/lib/python3.8/site-packages/tap2junit/tap13.py", line 193, in _parse
raise ValueError("Descending test id on line: %r" % line)
ValueError: Descending test id on line: 'ok 1 - fileSize checks'report.txt (as outputted from node --test-reporter=tap --test-reporter-destination=report.txt tests/run-tests.js)
TAP version 13
# Subtest: System Configuration Required Tests
ok 1 - System Configuration Required Tests # TODO System Configuration Required Tests
---
duration_ms: 3.723
...
# Subtest: System Configuration Optional Tests
# Subtest: System Configuration Optional Tests
ok 1 - System Configuration Optional Tests
---
duration_ms: 3.2683
...
1..1
ok 2 - System Configuration Optional Tests
---
duration_ms: 4.5664
...
# Subtest: Main Validation Tests
# Subtest: fileSize checks
# Subtest: fileSize is too small
ok 1 - fileSize is too small
---
duration_ms: 20.9785
...
# Subtest: fileSize is too large
ok 2 - fileSize is too large
---
duration_ms: 27.1384
...
1..2
ok 1 - fileSize checks
---
duration_ms: 51.8895
...
1..1
ok 3 - Main Validation Tests
---
duration_ms: 53.4117
...
1..3
# tests 3
# pass 2
# fail 0
# cancelled 0
# skipped 0
# todo 1
# duration_ms 81.1599Not entirely sure why this is happening but if I had to guess it's nesting depth/recursion related..?
If I take out the fileSize checks wrapping around those tests, it seems to work..
There's no issues anywhere else, even with the built-in experimental node test runner (a previous version of node gave bad output when nesting hit the third level, but on latest [v19.8.1] the TAP output looks correct to me and is parsed and handled fine by other tools such as tap itself) so I'd rather not lose the 'nice' grouping of the tests just to get a junit XML file.
Activity
cclauss commentedon Mar 30, 2023
@MoLow Any ideas?
@ForbiddenEra We made a new release this morning. Can you please try
pip install tap2junit==0.1.5vs.pip install tap2junit==0.1.6and see if you get the same or different results?MoLow commentedon Mar 30, 2023
this seems to reproduce on
0.1.6.validation of test numbering seems to ignore nesting.
@ForbiddenEra you can take a look at https://www.npmjs.com/package/@reporters/junit
ForbiddenEra commentedon Apr 2, 2023
Oo, will take a peek - nice to see an alternative, I was tempted to whip up my own since the XML doesn't look too complex but no sense in re-inventing any wheels, I'll take a peek at that; fortunately I can have my tests still run properly and specify a reporter on the command line without using
--testor usingrun()(nodejs/node#47314 describes in more detail what/why etc and it seems like commits are coming to improve this for my case)I should also mention that the XML that I did get out of it when removing nesting wasn't the greatest either; it didn't pick up any 'filenames' and split any of my test comments/descriptions up that had a
/character in them:Which results in
mehoutput on Gitlab, which is ultimately my goal:Any comments on this? None of my tests are actually named with a
-at the beginning, it's simply picking that up fromnode:test's output.I never tried
0.1.5as I had only started testing with it that same day, I can give that a shot too if it might be worth it, though I worry that even if it handles nesting appropriately that this "secondary" issue may still be present.I'll definitely try the mentioned reporter and if I find time I may also try
0.1.5but ultimately if the reporter works for me than I'm happy and might not have time otherwise.@MoLow As I see you're the maintainer for the linked reporter, I figure it may be easier to leave my comments here, especially considering
tap2junitbeing maintained undernodejsand me attempting to make use of the experimentalnode:teststuff that maybe it wouldn't hurt visibility to those who might care?; let me know though if you want me to create an issue in that repo regarding this.ForbiddenEra commentedon Apr 2, 2023
I tried installing
0.1.5but can't (easily) 100% confirm that it overrode0.1.6as it doesn't provide a--versionor similar option, though it installed fine and got the same result for descending values.Tried the
@reporters/junitquickly and the result seems maybe better in some ways, worse in others?So, all the other tests are wrapped in the first testcase..
I have a
run_tests.jsthat imports 4 test scripts and runs them.. eg.Each of these scripts exports a default function, eg:
testSuite1.js:testSuite2.js:The
TAPoutput looks fine, I think?If I wrap the calls in
run_tests.jsin it's own test, then it seems to be OK, of course I have to pass the test handle to each sub-test and await everything but then I get better looking XML?Might be a workaround, though I don't really want everything wrapped into one test suite like that, what I'm after should look like this:
I did have a reason previously for using a separate script to initiate the tests (eg. the
run_tests.js) but the reasons around that have commits coming tonodethat should negate the reasons I had.Ditching that (and, of course, moving all the tests outside of the exported function) and using
node --testwith the@reporters/junithowever still doesn't give me the result I was looking for, everything gets wrapped in one of the suites for no real reason?Here's the
TAPoutput from that atttempt:It seems like whichever test shows up first is considered the
rootof all tests, even if the subsequent tests are siblings; while some of what I might be doing may not be the exact proper way/slightly weird, I don't think that runningnode --testin a directory withtest/*.jsfiles is in any way weird or wrong, from the documentation I've read, this seems like, if anything, the most official/proper way to do it besides usingrun()..?Also..for some reason gitlab seems to use the
classname="test"as the test suite name - I'm not super familiar with thejunitformat so I'm not sure if this is more of an issue on that side, but in the XML generated it shows every testcase as havingclassname="test"- I'm not sure where this is coming from or how that's generated (haven't peeked at the code yet for the reporter) - assuming it's just responding to the events on aTestsStreamand outputting the XML based on what it gets fromnodeon theTestsStreambut I wonder if perhaps theclassnameshould actually be the suite name?Here for test suite 3 where it shows 'Test Suite #3/Test#1' is because that's the actual name of the test eg:
I had taken out the
Test Suite #x/prefix for all the other ones and had missed that; I had only put it like that in the first place because it seemed liketap2junitwas using the/to parse sub-test names ..I did briefly look into what gets fired on a
TestsStreambut as presently there's no way to use the internal reporters when usingrun()which is the only way to get a handle on theTestsStream, it's a bit awkward - this has been fixed already in a commit I found however I don't know when it's planned to land on a release..MoLow commentedon Apr 2, 2023
@ForbiddenEra can you please open an issue at https://github.com/MoLow/reporters/tree/main describing what the desired output would be and what node version you are using?
ForbiddenEra commentedon Apr 2, 2023
No problem; I did ask if you would prefer that and will do..
Edit: done - MoLow/reporters#42
thanks again for your time/help/reporter and other work :)