Skip to content
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

Rework hook error tests to actually assert #1781

Merged
merged 2 commits into from Jul 5, 2015

Conversation

glenjamin
Copy link
Contributor

The current hook.err tests don't actually assert anything, to check that they work you have to uncomment a bunch of lines, and then see if the failing tests are the ones which are supposed to fail.

In particular, this makes it difficult to safely implement #1635

I have converted these tests to a new approach which means they do now actually assert things.

I originally began using the runMocha helper along with fixtures to do this, but I found that the tests were extremely opaque as they asserted on the details of a complex out-of-band fixture. To combat this I've done something a bit wacky - defined the fixture inline as a function, and then used toString to send that function over the filesystem boundary to generate a fixture on the fly.

I think the implementation wackiness is worth the expressive benefit here, but I wanted to get some feedback before I add any more tests for the new functionality described in #1635

As mentioned in the commit message, git isn't smart enough to detect the rewrite of this file, but you can force it to see that the diff doesn't change what is being asserted in any way.

git diff -w --word-diff HEAD^1:test/hook.err.js HEAD:test/integration/hook.err.js

@jbnicolai
Copy link

As mentioned in the commit message, git isn't smart enough to detect the rewrite of this file, but you can force it to see that the diff doesn't change what is being asserted in any way.

Yeah, this is a common issue. One way around it is to separate things out into two commits, one with a git mv and the other with the actual changes.

@jbnicolai
Copy link

🎉 this commit is awesome!

@glenjamin
Copy link
Contributor Author

I've split the move and the rewrite into separate commits, that's much neater.

Also related to #1528

var path = resolveFixturePath(fixture.name + '.js' || 'tempfile.js');
args = args || [];

var fixtureContent = 'var fn = ' + fixture.toString() + '; fn()';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty damn (beautifully) hacky ;)

@jbnicolai
Copy link

I think the implementation wackiness is worth the expressive benefit here, but I wanted to get some feedback before I add any more tests for the new functionality described in #1635

Agree with both statements here. Definitely worth it though! 😄

jbnicolai pushed a commit that referenced this pull request Jul 5, 2015
Rework hook error tests to actually assert
@jbnicolai jbnicolai merged commit 93d5a3a into mochajs:master Jul 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants