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

Improve metadata checks #980

Merged
merged 14 commits into from
Jan 26, 2017

Conversation

asafigan
Copy link
Contributor

Fixes #847

validate-test.js checks the following:

  • always should only be used with after or afterEach
  • todo may not have an implementation, but must have a title
  • todo should not be combined with any other modifiers. It's simply for documentation. So no skipped, no failing, no afterEach, etc.
  • skip.only should be a failure
  • failing shouldn't be used with hooks
  • failing shouldn't be skipped
  • only shouldn't be used with hooks

All unit tests are in test/validate-test.js. Integration tests are in test/runner.js. Moved some tests from test/test-collection.js to test/runner.js.

@vadimdemedes vadimdemedes changed the title Fixes #847 Improve metadata checks Aug 9, 2016
@vadimdemedes
Copy link
Contributor

Good work, @asafigan! Sorry for not taking a look sooner. Let's hear one more LGTM and merge it in.

@sindresorhus @jamestalmage @novemberborn @sotojuan @jfmengels looks good to you?

}

if (metadata.failing) {
return '`only` tests cannot be failing';
Copy link
Contributor

@jfmengels jfmengels Sep 4, 2016

Choose a reason for hiding this comment

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

I'm not well aware of how this works, but the message talks about only tests, not skipped tests. Are tests skipped due to the presence of an only marked as skipped, or is the message inconsistent with what is checked?

Not sure why failing tests should not be skipped/only-ed by the way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think just the message is wrong and should be fixed.

Not sure why failing tests should not be skipped/only-ed by the way.

I agree, failing tests should be allowed to skip and only.

@asafigan
Copy link
Contributor Author

Thanks for the feed back guys. I'm going to be busy for awhile, but I will try to look into everything.

@sotojuan
Copy link
Contributor

Few nitpicks but overall LGTM. Should be merged by the next push!

@vadimdemedes
Copy link
Contributor

Hey @asafigan, any chance you have some free time to complete this? :)

@asafigan
Copy link
Contributor Author

Sorry I have been so slow on this. I will do it this weekend.

@vadimdemedes
Copy link
Contributor

@asafigan No worries, thanks!

@asafigan
Copy link
Contributor Author

@vdemedes unless there is any other feedback, I believe it ready to merge

@vadimdemedes
Copy link
Contributor

@asafigan Thanks for finishing this up! I'm a little busy now, I'll try to review ASAP, unless someone from the team beats me to it.

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

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

Thanks for coming back to this @asafigan!

I wonder if the tests should be added to test/runner.js instead. The examples are clearer that way and less coupled to how tests definitions are represented internally.

Also, @sindresorhus, do we have rules around when error messages end in a period? Looking at the deletions we haven't been consistent about this before, and perhaps we don't care, but wanted to raise it regardless.

@sindresorhus
Copy link
Member

Also, @sindresorhus, do we have rules around when error messages end in a period? Looking at the deletions we haven't been consistent about this before, and perhaps we don't care, but wanted to raise it regardless.

See: sindresorhus/eslint-plugin-unicorn#26

@sindresorhus
Copy link
Member

@asafigan Any chance you would be able to address @novemberborn's feedback so this can be merged?

@sindresorhus
Copy link
Member

ping @asafigan

@asafigan
Copy link
Contributor Author

So, I need to rewrite the tests in test/runner.js. What about reformatting the error messages? I couldn't tell if there was a discussion with that.

@sindresorhus
Copy link
Member

So, I need to rewrite the tests in test/runner.js.

Yes, so they're not tied to the internal implementation. Just make them like the existing ones you already have there: https://github.com/avajs/ava/pull/980/files#diff-a0b87ab613d07bba77930609ec360b3dR323

What about reformatting the error messages? I couldn't tell if there was a discussion with that.

What you have now is fine.

@novemberborn
Copy link
Member

@asafigan how's it going? Wondering if you're still interested in completing this? Thanks :)

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

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

(Just updating PR status.)

@asafigan
Copy link
Contributor Author

I'm getting major issues when I try to test now.

@asafigan
Copy link
Contributor Author

I pull from master and solved the merge conflicts but now there are a bunch of errors when I run npm test or npm run test-win

@asafigan
Copy link
Contributor Author

I went to my master branch and pulled from upstream master and I get the same issues

@@ -4,6 +4,7 @@ const Promise = require('bluebird');
const optionChain = require('option-chain');
const matcher = require('matcher');
const TestCollection = require('./test-collection');
const validateTest = require('./test-colection');
Copy link
Member

Choose a reason for hiding this comment

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

You have a typo. You're also importing the same thing twice.

@asafigan
Copy link
Contributor Author

oh yeah I noticed that

@asafigan
Copy link
Contributor Author

the real issue was that I forgot to rerun npm install

@asafigan
Copy link
Contributor Author

I had to fix some other things, too.
Sorry, it took me so long to circle back on this.

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up again @asafigan. Nearly there! 😄


t.throws(() => {
runner.beforeEach.only('', noop);
}, {message: '`only` is only for tests and cannot be used with hooks'});
Copy link
Member

Choose a reason for hiding this comment

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

This is better as:

t.throws(() => {
	runner.beforeEach.only('', noop);
}, TypeError, '`only` is only for tests and cannot be used with hooks');

Same goes for the other tests. See http://www.node-tap.org/asserts/#tthrowsfn-expectederror-message-extrafor specifics.

@asafigan
Copy link
Contributor Author

Will do

@@ -234,7 +234,7 @@ test('skip test', t => {

t.throws(() => {
runner.skip('should be a todo');
}, {message: 'Expected an implementation. Use `test.todo()` for tests without an implementation.'});
}, TypeError, 'Expected an implementation. Use `test.todo()` for tests without an implementation.');
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect. You're no longer testing the error message. The third argument is just an assert failure message.

You could do:

t.throws(() => {
	runner.todo('todo', () => {});
}, new TypeError('`todo` tests are not allowed to have an implementation. Use `test.skip()` for tests with an implementation.'));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for catching that

@sindresorhus sindresorhus merged commit 9616dde into avajs:master Jan 26, 2017
@sindresorhus
Copy link
Member

Thank you @asafigan. Excited to finally land this :)

@asafigan asafigan deleted the improve-metadata-checks-issue-847 branch January 26, 2017 13:57
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.

6 participants