Skip to content

Return zero recent failures for empty suites/reports

What does this MR do and why?

For #364226 (closed)

Makes countRecentlyFailedTests return 0 when the subject being passed to it is null or undefined so that if it is called before the test report widget has data, it doesn't throw an error.

Screenshots or screen recordings

before after
Screen_Recording_2022-06-22_at_16.18.56 Screen_Recording_2022-06-22_at_16.25.59

How to set up and validate locally

Reproduce the bug:

  1. git checkout master
  2. echo "Feature.enable(:refactor_mr_widget_test_summary)" | bundle exec rails console
  3. find/clone a project with test reports
  4. run a pipeline for the default branch in the project
  5. find/create a branch that modifies the results of the test report (feature-branch in the demo project)
  6. open a merge request for that branch, ensure a pipeline runs for it, watch the widget as it loads while the pipeline completes
  7. the widget should show a loading state and then an error state 🐛 (refreshing the page afterwards shows the data that should have appeared)
  8. (optional) to recreate the bug again after this, you can gdk restart or retry the pipeline's test job(s)

Validate the fix:

  1. git checkout 364226-return-zero-recent-failures-when-suites-is-null
  2. refresh the page to make sure the new version is running
  3. gdk restart or retry the pipeline's test job(s), watch the widget as it tries to load new data
  4. the widget should show a loading state and then show data (the same data that appeared after refreshing when the bug was there)

Run the new unit test on the old code to validate that it would catch a regression:

  1. git checkout master and apply this patch:
patch
diff --git a/app/assets/javascripts/vue_merge_request_widget/extensions/test_report/index.js b/app/assets/javascripts/vue_merge_request_widget/extensions/test_report/index.js
index 164bda33b95..0af84cf4dad 100644
--- a/app/assets/javascripts/vue_merge_request_widget/extensions/test_report/index.js
+++ b/app/assets/javascripts/vue_merge_request_widget/extensions/test_report/index.js
@@ -32,9 +32,6 @@ export default {
       };
     },
     statusIcon(data) {
-      if (data.parsingInProgress) {
-        return null;
-      }
       if (data.status === TESTS_FAILED_STATUS) {
         return EXTENSION_ICONS.warning;
       }
diff --git a/spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js b/spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js
index da4b990c078..6466d5d8486 100644
--- a/spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js
+++ b/spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js
@@ -79,6 +79,15 @@ describe('Test report extension', () => {
       expect(wrapper.text()).toContain(i18n.loading);
     });
 
+    it('with a 204 response, continues to display loading state', async () => {
+      mockApi(httpStatusCodes.NO_CONTENT, '');
+      createComponent();
+
+      await waitForPromises();
+
+      expect(wrapper.text()).toContain(i18n.loading);
+    });
+
     it('displays failed loading text', async () => {
       mockApi(httpStatusCodes.INTERNAL_SERVER_ERROR);
       createComponent();
  1. yarn jest spec/frontend/vue_mr_widget/extensions/test_report/index_spec.js
  2. the with a 204 response, continues to display loading state test case should fail

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Miranda Fluharty

Merge request reports