Overview
You may encounter errors when trying to store your test results in CircleCI. This article discusses the case where the store_test_results step fail with the following error:
failed uploading test results: File: <path_to_file> had the following problems: * invalid top level element: <name_of_problematic_element>
How to address this issue
The error you're seeing means that the format of your test results file doesn't fully respect the expected JUnit XML format:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Mocha Tests" tests="3" failures="1">
<testsuite tests="3">
<testcase classname="foo1" name="ASuccessfulTest" time="10" file="src/__tests__/App.test.js" />
<testcase classname="foo2" name="AnotherSuccessfulTest" time="5" file="src/__tests__/App.test.js" />
<testcase classname="foo3" name="AFailingTest" time="1.1050" file="src/__tests__/App.test.js">
<failure type="NotEnoughFoo"> details about failure </failure>
</testcase>
</testsuite>
</testsuites>
In order to troubleshoot, we suggest storing the file as an artifact, and reviewing its contents. Doing so will allow you to identify if the formatting has outputted correctly.