Skip to content

Conversation

@cesine
Copy link
Member

@cesine cesine commented Jan 26, 2026

Before 2019 we had coverag with grunt, this brings it back using nyc

% ls -alt coverage-2019 
total 4320
drwxr-xr-x  53 cesine  staff     1696 Jan 25 22:26 ..
-rwxr-xr-x   1 cesine  staff  1880426 Aug 20  2019 coverage.json
-rwxr-xr-x   1 cesine  staff   326081 Aug 20  2019 lcov.info
drwxr-xr-x   5 cesine  staff      160 Aug 20  2019 .
drwxr-xr-x   9 cesine  staff      288 Aug 20  2019 lcov-report
Screenshot 2026-01-25 at 10 35 33 PM

@gemini-code-assist
Copy link

Summary of Changes

Hello @cesine, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on re-establishing code coverage for the project by integrating nyc, a modern JavaScript test coverage tool. It involves configuring nyc to monitor code execution during tests, updating project dependencies to support this new tool, and making minor adjustments to existing code and tests to ensure compatibility with nyc's instrumentation process. The primary goal is to provide better visibility into the test coverage of the codebase.

Highlights

  • Code Coverage Re-enabled: Code coverage measurement has been re-enabled for the project, transitioning from an older grunt-based system to nyc.
  • NYC Integration and Configuration: The nyc tool has been integrated as a development dependency, and a new nyc.config.js file defines its behavior, including exclusion paths for various directories and specific coverage thresholds for branches, functions, lines, and statements.
  • Dependency Updates: The package.json and package-lock.json files have been updated to include nyc and its extensive dependency tree, along with a general version bump for the project.
  • Test Script Modification: The test script in package.json has been modified to execute tests with nyc, ensuring coverage data is collected during test runs.
  • Temporary Test Disablement: Several test suites across multiple files have been temporarily disabled (describe changed to xdescribe) due to conflicts with nyc's instrumentation, specifically related to the use of eval which causes ReferenceError issues.
  • Git Ignore Update: The .nyc_output directory, where nyc stores generated coverage reports, has been added to .gitignore to prevent it from being tracked by version control.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/node.js.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully re-enables code coverage using nyc. The changes are well-structured, including adding nyc as a dependency, updating the test script, and configuring nyc through nyc.config.js. You've correctly identified and worked around an issue with eval and coverage instrumentation by ignoring problematic code and disabling related tests.

My review includes a suggestion to make the nyc configuration more robust by excluding the test-e2e directory and the config file itself. I've also recommended adding explanatory comments to all disabled test suites for better maintainability, similar to the one in Glosser-spec.js.

Comment on lines +2 to +8
exclude: [
'coverage',
'public',
'test',
'tests',
'db',
],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The exclude array is a good start, but it could be more comprehensive. It's missing the test-e2e directory, which contains end-to-end tests and shouldn't be part of the coverage report. It's also good practice to exclude configuration files like nyc.config.js itself from coverage.

Suggested change
exclude: [
'coverage',
'public',
'test',
'tests',
'db',
],
exclude: [
'coverage',
'public',
'test',
'tests',
'test-e2e',
'db',
'nyc.config.js'
],

describe("semi-automatic segmentation knowledgebase", function() {
// FIXME: using coverage with eval causes ReferenceError: cov_3h7cg3999 is not defined
// https://github.com/istanbuljs/istanbuljs/issues/499
xdescribe("semi-automatic segmentation knowledgebase", function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's great that you've added a FIXME comment here to explain why this test suite is disabled. This is very helpful for future maintenance.

});

describe("map reduces", function() {
xdescribe("map reduces", function() {
Copy link

@gemini-code-assist gemini-code-assist bot Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and future maintenance, it would be helpful to add a comment explaining why this test suite is disabled, similar to what you did in Glosser-spec.js. This is likely due to the eval issue with nyc's code instrumentation.

Suggested change
xdescribe("map reduces", function() {
// FIXME: using coverage with eval causes issues with code instrumentation.
// See: https://github.com/istanbuljs/istanbuljs/issues/499
xdescribe("map reduces", function() {

});

describe("emit data by user", function() {
xdescribe("emit data by user", function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and future maintenance, it would be helpful to add a comment explaining why this test suite is disabled, similar to what you did in Glosser-spec.js. This is likely due to the eval issue with nyc's code instrumentation.

  // FIXME: using coverage with eval causes issues with code instrumentation.
  // See: https://github.com/istanbuljs/istanbuljs/issues/499
  xdescribe("emit data by user", function() {

});

describe("support data v1.22", function() {
xdescribe("support data v1.22", function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and future maintenance, it would be helpful to add a comment explaining why this test suite is disabled, similar to what you did in Glosser-spec.js. This is likely due to the eval issue with nyc's code instrumentation.

  // FIXME: using coverage with eval causes issues with code instrumentation.
  // See: https://github.com/istanbuljs/istanbuljs/issues/499
  xdescribe("support data v1.22", function() {

});

describe("map on an array", function() {
xdescribe("map on an array", function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and future maintenance, it would be helpful to add a comment explaining why this test suite is disabled, similar to what you did in Glosser-spec.js. This is likely due to the eval issue with nyc's code instrumentation.

  // FIXME: using coverage with eval causes issues with code instrumentation.
  // See: https://github.com/istanbuljs/istanbuljs/issues/499
  xdescribe("map on an array", function() {

});

describe("custom emit", function() {
xdescribe("custom emit", function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and future maintenance, it would be helpful to add a comment explaining why this test suite is disabled, similar to what you did in Glosser-spec.js. This is likely due to the eval issue with nyc's code instrumentation.

  // FIXME: using coverage with eval causes issues with code instrumentation.
  // See: https://github.com/istanbuljs/istanbuljs/issues/499
  xdescribe("custom emit", function() {

});

describe("support data v1.22", function() {
xdescribe("support data v1.22", function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and future maintenance, it would be helpful to add a comment explaining why this test suite is disabled, similar to what you did in Glosser-spec.js. This is likely due to the eval issue with nyc's code instrumentation.

  // FIXME: using coverage with eval causes issues with code instrumentation.
  // See: https://github.com/istanbuljs/istanbuljs/issues/499
  xdescribe("support data v1.22", function() {

});

describe("support gamify data", function() {
xdescribe("support gamify data", function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and future maintenance, it would be helpful to add a comment explaining why this test suite is disabled, similar to what you did in Glosser-spec.js. This is likely due to the eval issue with nyc's code instrumentation.

  // FIXME: using coverage with eval causes issues with code instrumentation.
  // See: https://github.com/istanbuljs/istanbuljs/issues/499
  xdescribe("support gamify data", function() {

});

describe("emit", function() {
xdescribe("emit", function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and future maintenance, it would be helpful to add a comment explaining why this test suite is disabled, similar to what you did in Glosser-spec.js. This is likely due to the eval issue with nyc's code instrumentation.

  // FIXME: using coverage with eval causes issues with code instrumentation.
  // See: https://github.com/istanbuljs/istanbuljs/issues/499
  xdescribe("emit", function() {

// using coverage with eval causes ReferenceError: cov_3h7cg3999 is not defined
// https://github.com/istanbuljs/istanbuljs/issues/499
/* istanbul ignore next */
var MapReduceFactory = function(options) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist can you look into the history of api/map_reduce/MapReduce.js and idenitfy any alternative implementations that would work both in the skipped test suites in this PR and in a couchdb map reduce that do not use eval?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've correctly identified a common challenge when integrating with systems like CouchDB that rely on string-evaluated JavaScript functions for map-reduce operations, especially when trying to maintain code coverage with tools like Istanbul. The ReferenceError: cov_3h7cg3999 is not defined typically occurs because Istanbul injects instrumentation variables into the code, but these variables are not available in the isolated scope created by eval().

While CouchDB inherently executes map-reduce functions from strings (which is akin to an internal eval), we can refactor your application's local implementation and testing strategy to avoid explicit eval() calls in your JavaScript code, thus resolving the coverage issue and improving maintainability.

Here's a recommended approach:

  1. Define Map/Reduce Logic as Standard JavaScript Functions: Instead of storing your map and reduce logic as strings, define them as regular JavaScript functions within your api/map_reduce/MapReduce.js file (or a dedicated module).

    // Example: api/map_reduce/MyMapFunctions.js
    export function myMapFunction(doc) {
      // Your map logic here
      // For local testing, you'll need to provide a mock 'emit' function
      // For CouchDB, 'emit' is globally available
      if (doc.type === 'example') {
        emit(doc.key, doc.value);
      }
    }
    
    export function myReduceFunction(keys, values, rereduce) {
      // Your reduce logic here
      return values.length;
    }
  2. Local Testing and Coverage: In your test suites, you can directly import and call these JavaScript function objects. You would also need to provide a mock emit function for your map tests to capture the emitted key-value pairs.

    // Example: tests/map_reduce/MyMapFunctions-spec.js
    import { myMapFunction } from '../../api/map_reduce/MyMapFunctions.js';
    
    describe('myMapFunction', () => {
      it('should emit correctly', () => {
        const emitted = [];
        const mockEmit = (key, value) => emitted.push({ key, value });
        
        // Call the function, passing the mockEmit into its scope
        // This might require modifying your MapReduceFactory to accept an 'emit' context
        myMapFunction.call({ emit: mockEmit }, { _id: 'doc1', type: 'example', key: 'a', value: 1 });
        myMapFunction.call({ emit: mockEmit }, { _id: 'doc2', type: 'other', key: 'b', value: 2 });
    
        expect(emitted).toEqual([{ key: 'a', value: 1 }]);
      });
    });
  3. CouchDB Deployment: When deploying your design documents to CouchDB, you would convert these function objects into strings using their .toString() method. CouchDB will then eval these strings on its server.

    // Example: During CouchDB design document generation/deployment
    const couchdbDesignDoc = {
      _id: '_design/my_app',
      views: {
        my_view: {
          map: myMapFunction.toString(),
          reduce: myReduceFunction.toString()
        }
      }
    };
    // Push couchdbDesignDoc to CouchDB

This approach allows your local development and testing environment to work with actual JavaScript functions, which are fully instrumentable by Istanbul, while still providing CouchDB with the string-based functions it requires. This eliminates the need for eval() in your application's runtime code and should resolve the coverage issues you're encountering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant