-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
Covering code loaded with jsdom
and systemjs
#529
Comments
@unional would you be able to provide a minimal repo that would let us dig into I'm sure there are approaches that we can use to support this. |
Repo: https://github.com/unional/issues/tree/nyc-systemjs Steps: git clone https://github.com/unional/issues.git
cd issues
git checkout nyc-systemjs
npm install
npm run coverage Thanks for looking into this! 🌷 In the repo, you will see
|
@unional sorry it's taken so long to get to this (put out a new major release of yargs, and have been doing some work around monorepos to try to consolidate some of the work on istanbuljs). Thanks for providing this reproduction! |
@unional I took a quick look at your repo and it looks like #176 (comment) might help. Could you try giving that a shot and reporting back? |
Sure I can give it a try, but what does it solve? It seems like a solution to get coverage with |
I have created a tool I still don't know if this can be fixed because I notice that What I mean is this: // src/a.ts
export function foo() { ... }
// src/a.spec.ts
// load `foo` thru jsdom/systemjs when I run |
Same problem here. Any updates on the issue @unional ? Any alternative to systemjs for loading amd modules with path, shim configs, etc? |
Finally I tried requirejs in node after struggling with systemjs coverage hooks. I get lots of Although you can configure the node environment as follows:
cheers |
@sergueyarellano what you did is essentially what |
@unional @sergueyarellano me thinks to get this working an additional plugin would be required for jsdom. What you basically want is that when JSDom loads a block of JavaScript, you should hook into this step and run the JavaScript through the istanbul instrumenter -- I think you'd probably be better to do this in an additional helper module rather than nyc itself. Could be a fun project (and I'd happily link to and document it in nyc and on the istanbul website). |
@felixfbecker have not get the chance to work on @bcoe idea. The idea sounds good. Need to see if there is such a hook and create it if needed. Do you want to give it a try? |
Here's what I use right now to have coverage on any script run by jsdom. It just maps URLs encountered in vm.runInContext to local files: const webroot = "public";
const originalRunInContext = vm.runInContext;
vm.runInContext = function(code, context, options) {
// this should probably only match on localhost, still WIP
if (options && options.filename && options.filename.match(/^https?:\/\//i)) {
let filename = url.parse(options.filename).path;
if (filename.match(/\/$/)) filename += "index.html";
// this is optional but gives coverage on inline <script> tags
if (options.lineOffset > 0) {
filename += "." + options.lineOffset + ".js";
fs.writeFileSync(path.resolve(path.join(webroot, filename)), code);
}
return originalRunInContext.call(vm, code, context, {
...options,
filename: path.resolve(path.join(webroot, filename))
});
}
return originalRunInContext.call(vm, code, context, options);
}; Needs nyc's sourceMap and hookRunInContext set to true. Does not work with --all, though. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
is this issue solved? How can I cover a file loaded by JSDOM? |
Please use the template provided below, when reporting bugs:
Expected Behavior
Able to walk through the code loaded by:
Observed Behavior
Not covered (pretty much expected)
Is there a way to configure
nyc
to trace code like this?Bonus Points! Code (or Repository) that Reproduces Issue
Forensic Information
Window 2012 R2
node: 7.5.0
npm: 4.0.5
The text was updated successfully, but these errors were encountered: