-
Notifications
You must be signed in to change notification settings - Fork 91
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
Adding additional configuration file options #436
Conversation
BREAKING CHANGE: switches to using NODE_V8_COVERAGE rather than inspector directly
Clarify project goals: I'd like this project to demonstrate a powerful code coverage solution relying primarily on native V8 functionality, and minimal user-land modules -- @bcoe
- issue template - PR template - contributing guide - maintainers guide closes bcoe#35
This commit fixes the conversion from `file://` urls to system-dependent paths. It ensures that it works on Windows and with special characters.
d26cfbd
to
2c5f1b2
Compare
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling
2c5f1b2
to
43c3a45
Compare
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling
0897804
to
a534f68
Compare
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling fix: bug in spawning of c8 process that dropped coverage significantly
a534f68
to
22a9c08
Compare
Skipped the config detection tests for the moment. |
|
||
// Should the process die if none of these filename extensions are found? | ||
if (Object.keys(config).length === 0) { | ||
throw new Error(`Unsupported file type ${ext} while reading file ${path}`) |
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.
I read why this was added, but it's going to result in bad UX when a config file return an empty object - in that situation it loaded fine, and is not an invalid file type, it's just not got any config entries.
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.
I want to be sure I am clear on what you stated above. To rewrite what you expressed in two use cases.
Scenario:
A user executes the c8 command with the --config parameter set to an existing file on the file system
Given:
The file has a valid file name as documented in the c8 readme
The file has no contents.
Result:
c8 will run with a default configuration
Scenario:
A user executes the c8 command without additional configuration arguments and c8 discovers a configuration file.
Given:
The file has a valid file name as documented in the c8 readme
The file has no contents.
Result:
c8 will run with a default configuration
Can you please confirm?
The block does cover the following use case.
Scenario:
A user executes the c8 command with the --config parameter set to an existing file on the file system.
Given:
The file does not have a valid file name as documented in the c8 readme
Result:
c8 will produce the error `Unsupported file type ...'
This test case can be found on Line 70 - Line 85 of the file test/parse-args.js
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.
Some notes before I hit the scenarios:
- Only YAML would have an empty file return an empty object.
- An empty JSON file is a syntax error.
- A JSON file of
{}
is valid. - A CJS script that doesn't export anything IMO SHOULD result in an error as this is a common mistake.
- A CJS script that exports an empty object, e.g.
{}
is valid.
So, scenarios:
Scenario:
A user executes the c8 command with the --config parameter set to an existing file on the file system
OR
A user executes the c8 command without the --config parameter set AND c8 discovers a configuration file.
Given any of:
- The file is JSON with the
.json
extension, case insensitive.
The file has the contents{}
or equivalent. - The file is YAML with the
.yaml
or.yml
extension, case insensitive.
The file has no contents - The file is CommonJS with the
.js
or.cjs
extension, case insensitive.
The file's contents result in an empty object{}
being exported.
Result:
c8 will run with a default configuration.
Scenario:
A user executes the c8 command with the --config parameter set to an existing file on the file system
OR
A user executes the c8 command without the --config parameter set AND c8 discovers a configuration file.
Given any of:
- The file has the
.json
extension, case insensitive.
The file is invalid JSON. - The file has the
.yaml
or.yml
extension, case insensitive.
The file is invalid YAML. - The file has the
.js
or.cjs
extension, case insensitive.
The file's contents are invalid CommonJS or have a runtime error. - The file has the
.js
or.cjs
extension, case insensitive.
The file doesn't export anything. - The file has the
.js
or.cjs
extension, case insensitive.
The file exports something that's not an object.
Result:
c8 will fail with an appropriate error based on the actual underlying problem that will be helpful to the user.
Some errors are really very obtuse or otherwise mask the real problem. I think over time of people testing this those errors will be discovered and made nicer, so making the errors nicer probably shouldn't be part of this PR.
Scenario:
A user executes the c8 command with the --config parameter set to an existing file on the file system.
Given:
The file name is NOT one of the ones documented in the c8 readme.
The file extension is one of the valid types, e.g. .js, .cjs, .json, .yaml, .yml
etc.
The file returns a valid c8 configuration.
Result:
c8 will run with the configuration coming from the file given.
This is because there are several reasons for using the --config
parameter, here's just a few:
- I've got multiple config files to choose from. This you've covered.
- My config file's at an unusual path that auto detection won't find, e.g.
.configs/c8rc.yaml
This I'm pretty sure you've covered, though maybe not directly with a test. - I don't like any of the default file names and have my own naming scheme I use, e.g.
.config.c8.yaml
- the current code looks like it handles this case already, there just doesn't seem to be a test covering this idea.
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.
I've created a PR for the branch of this PR that adds tests and changes to support the above.
if (jsExts.includes(ext)) { | ||
config = require(path) | ||
} else if (ymlExts.includes(ext)) { | ||
config = require('js-yaml').load(readFileSync(path, 'utf8')) | ||
} else if (ext === '.json' || fileName.slice(-2) === 'rc') { | ||
config = JSON.parse(readFileSync(path, 'utf8')) | ||
} |
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.
I am going to put this into a try/catch block for the following reasons ...
- If a not properly formated json or yaml object is returned, it will produce an error.
- If the path doesn't exist, it will produce an error.
- If an unsupported configuration value is present in the configuration file, the value will get ignored.
It could be helpful to have a config schema validator. Going to add unit tests for two of the potential issues above.
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.
I agree on a schema validator. It would help people a lot.
However masking erroneous configuration files by just ignoring them, or even just logging the problem and proceeding with defaults, is an antipattern to me. It results in unexpected behavior since c8 proceeds with different settings than intended.
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.
In my PR to this PR I did wrap some of these in try-catch, but I only caught specific errors, re-thowing the others. The idea was to enhance the message in those cases as the underlying error was obtuse. However I think that other errors, such as file not found, are generally acceptable to leave alone.
JSON.parse
is very well known for producing REALLY opaque errors. Unexpected end of JSON input
always got me.
d8681e2
to
22a9c08
Compare
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling fix: bug in spawning of c8 process that dropped coverage significantly
122be90
to
570ca76
Compare
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling fix: bug in spawning of c8 process that dropped coverage significantly
570ca76
to
51d420a
Compare
Wait what, why closed?😳 |
sorry was editing my name in the commit history and it closed the branch. I'll fix it. |
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling fix: bug in spawning of c8 process that dropped coverage significantly
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling fix: bug in spawning of c8 process that dropped coverage significantly
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling fix: bug in spawning of c8 process that dropped coverage significantly
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling fix: bug in spawning of c8 process that dropped coverage significantly
feat: Adding additional configuration file options test: unit test for config file detection test: unit test for config files pass via the cli test: unit test case for early exit of hideInstrumenteeArgs test: unit test for Node.js argument handling fix: bug in spawning of c8 process that dropped coverage significantly
Pull Request 436
Commit Message
commit 22a9c08
Author: The Nasty [email protected]
Date: Sat Jan 20 13:51:03 2024 -0500
Following the Contributions Recommendations here.
Unit Tests Results
Node Version Testing Matrix
Duplicate of #447
References #448