-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Fork per test. #89
Fork per test. #89
Conversation
This currently runs sans-coverage (and passes). So it's a potential solution to #79 as well. |
Just added a self-coverage solution. Tests can now be run with or without coverage enabled!! (#79 is fixed!) It no longer uses This has the added benefit of not mixing in fixture coverage data into our coverage results. The entire build process is implemented using npm build scripts. It's a little unwieldy. I think we should move to |
for non-coverage, de-obfuscated stack-trace goodness |
Below is the output of the first test file. Note that it is smart enough to only pull in the helper functions needed. The generated tests are stored as separate files inside the test dir. This has the added benefit of providing People evaluating this PR should actually clone it and run /* global describe, it */
require('source-map-support').install()
var _ = require('lodash')
var fs = require('fs')
var NYC
try {
NYC = require('../index.covered.js')
} catch (e) {
NYC = require('../')
}
var path = require('path')
var rimraf = require('rimraf')
var sinon = require('sinon')
var spawn = require('child_process').spawn
var fixtures = path.resolve(__dirname, './fixtures')
var bin = path.resolve(__dirname, '../bin/nyc')
require('chai').should()
require('tap').mochaGlobals()
describe('nyc', function () {
describe('cwd', function () {
function afterEach () {
delete process.env.NYC_CWD
rimraf.sync(path.resolve(fixtures, './nyc_output'))
}
it('sets cwd to process.cwd() if no environment variable is set', function () {
var nyc = new NYC()
nyc.cwd.should.eql(process.cwd())
afterEach()
})
})
}) (source map comment omitted - but it is generated) |
curious to see how this work turns out, my main ask is that the flow continues to be;
So let's bake any build steps into pretest 👍 |
That is still the process for builds with coverage (I do indeed use pretest). I would say this ready for preliminary review. The only thing that I think could be improved is the build. As stated I am thinking gulp. If you can, I would like you to at least clone it, run it locally and peek at the transformed files. I just want to make sure we don't feel that what I am doing is too magical before I dump a lot of extra time in it. I think it's a viable plan, but it is definitely out of the ordinary |
I'm partial to just using npm scripts. |
"dev": "npm run clean && npm run build && npm run run-tests", | ||
"instrument": "node ./instrument-index.js", | ||
"report": "istanbul report --include=self_coverage/*.json lcov text", | ||
"run-tests": "tap -b ./test/built-*.js ./test/source-map-cache.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.
I'm partial to just using npm scripts.
Yeah, but this feels pretty close to being unmaintainable going forward.
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 suppose.
'use strict' | ||
|
||
var fs = require('fs') | ||
var Path = require('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.
Out of interest, why the capital P
?
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.
Because I named another variable path
down below. Normally I'd just rename the other variable, but path
is the de facto variable name for your node path in AST transforms.
I've extracted the transform into it's own module anyways, so I can fix this up.
@jamestalmage what's outstanding on this? |
1bfc2df
to
76d2030
Compare
OK, |
With all the files this thing now generates, and especially because of this, we should probably start using the explicit |
Could get this in first, then fix what's remaining.
👍 |
OK, just updated "files": [
"index.js",
"bin/*.js",
"lib/*.js",
"!**/*covered.js"
] Before:
After:
Note that I've used grep to remove the bundled dependency noise from the output above. The bundled dependency is included in both cases, you do not need to list it in the |
Hmm, oddly enough TL; DR; - I have double and triple checked my changes to |
I agree. Let's do that. |
@jamestalmage just testing this out, really slick! A couple things:
|
2ba8fdf
to
c355787
Compare
Done
The reason I did not do that was so that require paths still looked right in the main file you were editing. If you move them into We could solve this by moving test sources into
|
That last commit reorganizes the directory structure as I suggested in my previous comment. |
not sure why the last commit caused coverage to drop, but I've got to head out for a couple hours. Will take another look later tonight |
Found it, I missed an update to one of the |
@jamestalmage this is looking great, feel free to merge this and your other test refactor work when you feel it's ready. |
It is basically ready to merge (I will likely squash the history a bit first), but I am not a collaborator. |
This adds a build step to the test process that rewrites `test/nyc-test.js` into multiple files with one test per file. Since taps forks for each test file, this provides a pristine environment for testing our various system hooks. squashed commits: Working test suite without coverage tweak build script
add back coveralls report
squashed commits: rename instrument-index to build-self-coverage (more accurate description) add leading `.` to self_coverage output directory minor fixups to npm scripts fix `npm run report` - it was using the old coverage folder name move built tests to test/build/, originals sources to test/src fix test script
e632d65
to
3eb8cbf
Compare
Landed. Thanks @bcoe! |
Similar to #83,
This actually uses an AST transform to generate multiple files for forking and testing. This has a couple added benefits:
_header
file I was using in fork for every test innyc-test
#83, or separate helpers. The transform intelligently copies helper functions into each file.