-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Support code coverage #9
Comments
Bump into one issue: systemjs/systemjs#1744 |
I don't, I would imagine that the istanbul hooks into On a side note, when you wrote this, did you think about just doing a mini-bundle with webpack or browserify and evaluating that in jsdom? Then the whole mini-bundle could probably be instrumented instead of instrumenting on every require. |
I think that will lose the ability to track the individual dependency between files. In my idea, this instrumentation has two use cases: code coverage and dependency tracking used by test runner. |
What is your use case? |
That's probably would work. Thanks for the link. 🌷 |
I never used the watch features of test runners, I always run tests manually (with debugger attached) and filter to the tests I want to run - didn't think about that use case. So for me, support for code coverage > support for watch. Of course it would be great if both worked. |
I just gave
|
Also, seems like it does not work with |
I have some update: To get around it, all |
I have some time I could invest this week, what's the current state? |
Same as before. Did some investigation and I think we need to implement similar mechanism as One approach is store the result in Since there can be multiple tests running, multiple writes can occurs in Currently, I'm trying to make one improvement: #29 |
Done with #29 Feel free to experiment any idea you have. 🌷 |
@felixfbecker as I have encountered some issues with node resolution in systemjs. I try switching to using webpack and ts-loader to do the bundling and load into jsdom. It seems to work so far. If I get all my test passes then will release a new version based on that. Adding istanbul should be easy by then. |
That sounds awesome. Do you have a branch for it? |
It's on the |
I rewrote my tests to use domture (from the next dist tag) and it works. How do see the instrumentation come in? Maybe https://github.com/webpack-contrib/istanbul-instrumenter-loader? I currently don't see a way to provide webpack options to |
Yes. Just need to test and add that into the code. Maybe later I can open up the config for webpack as I was doing for systemjs. FYI, I'll need to maintain both solutions (systemjs and webpack). Another package of mine Will need to release them in two different names. Any suggestion? |
On a second thought, the API of the domture instance is the same. The only difference this the configuration. So I'll keep the same names and use a i.e.: createDomture({
loader: 'webpack' // 'systemjs'
...
})
interface WebpackDomtureConfig {
loader: 'webpack'
...
}
interface SystemJSDomtureConfig {
loader: 'systemjs'
...
}
createDomture(config: WebpackDomtureConfig | SystemJSDomtureConfig) { ... } |
@unional could you add a way to pass webpack config? Your proposal looks good to me |
Sure, will create 1.1 to just expose the config so you can play with it. I'm doing some validation to see if I can completely drop systemjs. If that works, then I can simplify the code. |
|
FYI you will not see the converge folder created because webpack output is streamed to memfs: So in order to get coverage, we need to collect the coverage from each test and merge them together (along with the |
Do you want to be added as a contributor to |
Yeah feel free to add me. I can't make any commitment but would hack on it when I find the time |
No problem. Invite sent. |
So I just tried it with this config: const domture = await createDomture({
transpiler: 'typescript',
rootDir: __dirname,
webpackConfig: {
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'istanbul-instrumenter-loader',
},
},
],
},
},
})
dom = await domture.import('./dom') // this is the browser utility under test Then running it with
The only thing I am missing is the source map support (out/util/dom.js should be src/util/dom.ts) |
I think this is because of webpack-contrib/istanbul-instrumenter-loader#73 |
I finally got it to work with Browserify instead of webpack: 🎉 🎉 🎉 export const createTestBundle = async (modulePath: string): Promise<TestBundle> => {
const bundler = browserify(modulePath, {
// Generate sourcemaps for debugging
debug: true,
// Expose the module under this global variable
standalone: 'moduleUnderTest',
// rootDir for sourcemaps
basedir: __dirname + '/../../src',
})
bundler.plugin(tsify, { project: __dirname + '/../../tsconfig.test.json' })
// If running through nyc, instrument bundle for coverage reporting too
if (process.env.NYC_CONFIG) {
bundler.transform(babelify.configure({ plugins: [babelPluginIstanbul], extensions: ['.tsx', '.ts'] }))
}
const bundle = await getStream(bundler.bundle())
return {
load(): DOMModuleSandbox {
const jsdom = new JSDOM('', { runScripts: 'dangerously' }) as JSDOM & {
window: { moduleUnderTest: any }
}
jsdom.window.eval(bundle)
return { window: jsdom.window, module: jsdom.window.moduleUnderTest }
},
}
} |
Nice! Add 'browserify' as another loader? |
Yeah that should be possible, but I don't know how we can make the above part of domture while also making it configurable. Wondering also how many loaders we want to bake into dependencies - it's not that great having to pull down SystemJS, webpack and Browserify. Maybe split into multiple packages. Another thought I had when doing the above was that in tests there is the desire to run each test in a fresh JSDOM instance, but rebundling on every test is very slow. That's why I separated the two above. |
Yes, splitting would make sense.
You probably mean rebuilding (or rebundling, or both. :P). I thought about saving the context and inflate it back for each test, but it could be leaky on the DOM side, and it can become fragile when JSDOM upgrades. let domture
before(() => { domture = new Domture(...) })
afterEach(() => {
domture.cleanup()
})
test('...', () => {
await domture.loadScript(...)
// do test
}) |
That's basically what I am doing above in my snippet, first bundle in a |
I originally wanted to avoid that to reduce the mental burden of the consumer. Apologize for not pushing this forward fast enough. Recently I have been fully occupied by |
@felixfbecker I'm hitting on some issue in using JSDOM to run tests. Or use headless chrome directly, instead of JSDOM or electron |
I think that would make debugging a lot harder because you cannot step through the code with a debugger anymore, it would break at the RPC boundary. So you would have to attach a debugger to the headless Chrome and to Node running the test. I think headless Chrome is great for e2e testing but for unit tests that just need a DOM I prefer JSDOM. What are the issues you are having? Btw, Puppeteer is a lot more advanced than Chromeless and developed by Chrome. |
@felixfbecker I have updated the project to use latest code.
Now all script loading is done by
systemjs
.Do you know how to hook into it for code coverage purpose?
The text was updated successfully, but these errors were encountered: