-
Notifications
You must be signed in to change notification settings - Fork 45
Turn coverage back on #2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Turn coverage back on #2194
Conversation
Summary of ChangesHello @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 Highlights
Ignored Files
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
| exclude: [ | ||
| 'coverage', | ||
| 'public', | ||
| 'test', | ||
| 'tests', | ||
| 'db', | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| }); | ||
|
|
||
| describe("map reduces", function() { | ||
| xdescribe("map reduces", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
-
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.jsfile (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; }
-
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
emitfunction 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 }]); }); });
-
CouchDB Deployment: When deploying your design documents to CouchDB, you would convert these function objects into strings using their
.toString()method. CouchDB will thenevalthese 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.
Before 2019 we had coverag with grunt, this brings it back using nyc