-
Notifications
You must be signed in to change notification settings - Fork 83
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 support for single file instrumentation via stdio #100
Conversation
…dio output. Adding NPE guards in jscoverage.js report viewer.
Thanks. I'll take a look. I'll have to add a few things - feel free to help:
|
I've merged and the only tasks left are the documentation and an example. What's the use case so I can add an example and why this is useful? Without these I'll have to revert the changes. |
The use case is for a file based unit testing harness in a large, complicated codebase that is impractical or impossible to process in its entirety, or even a folder at a time. Each target script file is requested and imported by the test file, and the import strategy determines whether or not to instrument the file based on configuration/input parameters to the runner. As these happen in the engine memory space, the effect is cumulative, and collects coverage statistics for every file imported by any tests run. This provides a nice silo effect for run isolation: rather than reporting on all files in a folder, it reports only on files exercised by a subset of tests, making it easier to identify accidental versus intentional coverage. |
The example is: java -jar JSCover.jar FileToInstrument.js -io This outputs the instrumentation to stdio, which gives you shell/piping support for, e.g. integration with a command line automation/CI system with or without writing to file. You can, e.g. java -jar JSCover.jar FileToInstrument.js -io > InstrumentedFile.js Or read it directly into memory by any language or engine that can process std io; Or continue processing it with standard command tools, grep, sed, awk, etc. |
Sounds OK (I can leave in if it's required for you). Can you think of a small example that goes from instrumented file to a coverage report or JSON coverage file that demonstrates the usefulness to others?
That would be great to demonstrate. Would you be able to help create a sample or describe your test harness set-up that does this?
That can be probably be handled by the |
You're probably correct that the paths could be handled with the regex pattern, but we have over 500 modules, each with their own patterns. It's much simpler and cleaner to deal with in-memory representations of each file, as it's requested. I'll try to craft an example of isolating files, but it's difficult given our setup. The runner operates on files directly in each script engine, without a browser or web server. Isolating files, directories, or criteria-matching tests is built into the runner, so the value here is in being able to specify a single new flag that changes the dependency import behavior from non-instrumented to instrumented, and executing the same exact run, except with intent to capture coverage statistics instead of failures. |
OK.
Thanks. I can leave it in with minimal documentation. |
Adding support for single file instrumentation via command line to stdio output. Adding NPE guards in jscoverage.js report viewer.