Uploaded image for project: 'GPII - Global Public Inclusive Infrastructure'
  1. GPII - Global Public Inclusive Infrastructure
  2. GPII-2927

Code coverage statistics differ running unit tests in a browser vs. using node

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      Starting from the top with "how-things-work-now", and specifically using the processes bridge component of the process reporter module:

      1. The processes bridge unit tests are included via the "all-tests.html" file within universal's web-based tests folder, i.e.:
      https://github.com/GPII/universal/blob/master/tests/web/html/all-tests.html#L28

      2. The web page for the processes bridge unit tests referenced in "all-tests.html" is "ProcessesBridgeTest.html" and is found inside the "processReporter" web test directory:
      https://github.com/GPII/universal/blob/master/gpii/node_modules/processReporter/test/web/html/ProcessesBridgeTest.html

      3. "ProcessesBridgeTest.html" loads the actual unit tests from the script file "ProcessesBridgeTests.js":
      https://github.com/GPII/universal/blob/master/gpii/node_modules/processReporter/test/web/html/ProcessesBridgeTest.html#L21

      4. In addition to defining unit tests for each of the functions in the "processesBridge.js" source file, "ProcessesBridgeTests.js" defines a function gpii.tests.processes.runTests().  This is called from "ProcessesBridgeTest.html":
      https://github.com/GPII/universal/blob/master/gpii/node_modules/processReporter/test/web/html/ProcessesBridgeTest.html#L32

      When the above configuration is run as part of npm run test, the code coverage for "processesBridge.js" is 25-30% as shown in the second row of the report:
      http://clown.idrc.ocad.ca/GPII/gpii-master/reports/universal/gpii/node_modules/processReporter/src/index.html

      The above setup was modified such that processes bridge unit tests were run using node.  This is shown in the "ProcessReporterMoreCoverage" branch. The steps to make the change were are as follows.

      1. Remove the reference to "ProcessesBridgeTest.html" from "all-tests.html":
      https://github.com/klown/universal/blob/ProcessReporterMoreCoverage/tests/web/html/all-tests.html

      2. Delete the "ProcessesBridgeTest.html" file from the "ProcessReporter" web test directory:
      https://github.com/klown/universal/tree/ProcessReporterMoreCoverage/gpii/node_modules/processReporter/test/web/html

      3. Move the unit tests in "ProcessesBridgeTests.js" out of the "web" test directory up to the "test" directory, and add necessary require(...) statements such that it can be run using node.  Also, a call to the gpii.tests.processes.runTests() function was added to the end of the script.  Except for these changes, the unit test definitions themselves remain the same:
      https://github.com/klown/universal/tree/ProcessReporterMoreCoverage/gpii/node_modules/processReporter/test/ProcessesBridgeTests.js

      4. Modify the "all-tests.js" file within universal's "tests" directory to reference the "ProcessesBridgeTests.js" unit tests:
      https://github.com/klown/universal/blob/ProcessReporterMoreCoverage/tests/all-tests.js#L92

      When the above configuration is run as part of npm run test, the coverage report shows approximately 90% coverage (second row):
      http://clown.idrc.ocad.ca/GPII/ProcessReporterMoreCoverage/reports/universal/gpii/node_modules/processReporter/src/index.html

      Why the difference in coverage for the same tests?  (My guess is that not all the tests are run in the web-based setup).

      (Aside:  note that the coverage for other process reporter related tests, namely "ProcessReporter.js" stays the same for both scenarios at about 50%.  SInce nothing was changed in terms of how its unit tests were run, that non-result was expected).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                clown Joseph Scheuhammer
                Reporter:
                clown Joseph Scheuhammer
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: