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

Fail when tests executed without cli #191

Merged
merged 1 commit into from
Nov 11, 2015
Merged

Conversation

vadimdemedes
Copy link
Contributor

This PR fixes #179.

Here's the output:

screen shot 2015-11-11 at 7 45 53 pm

var runner = new Runner();

// check if the test is being run without AVA cli
var isForked = typeof process.send === 'function';
Copy link
Member

Choose a reason for hiding this comment

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

Probably clearer to just check if the file was executed directly: require.main === module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But index.js is never required directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No matter if I use node test.js or ava test.js, require.main === module is always false.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, nvm. I'm sleepy...

var path = relative('.', process.argv[1]);

log.write();
log.error('Test files must be run with the AVA CLI::\n\n $ ava ' + path + '\n');
Copy link
Member

Choose a reason for hiding this comment

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

double ::

Copy link
Contributor Author

Choose a reason for hiding this comment

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

damn it

var path = relative('.', process.argv[1]);

log.write();
log.error('Test files must be run with the AVA CLI:\n\n $ ava ' + path + '\n');
Copy link
Member

Choose a reason for hiding this comment

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

and maybe add chalk.dim('$') and chalk.cyan to the command? just to be fancy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chalk.grey.dim('$') + ' ' + chalk.cyan('ava') + ' ' + path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

screen shot 2015-11-11 at 8 02 24 pm

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking the full command:

chalk.dim('$') + ' ' + chalk.cyan('ava ' + path)

To indicate what they can copy-paste.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

screen shot 2015-11-11 at 8 03 59 pm

Copy link
Member

Choose a reason for hiding this comment

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

Perfect. Just ava in cyan looks better, but this is clearer.

sindresorhus added a commit that referenced this pull request Nov 11, 2015
@sindresorhus sindresorhus merged commit 79233c7 into master Nov 11, 2015
@sindresorhus sindresorhus deleted the run-without-ava-error branch November 11, 2015 19:06
@sindresorhus
Copy link
Member

heart-universe

@vdemedes being productive today :D

@vadimdemedes
Copy link
Contributor Author

giphy 1

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.

Better error when launched without AVA cli
2 participants