Skip to content

Clean up API #1061

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

Merged
merged 1 commit into from
Oct 6, 2016
Merged

Clean up API #1061

merged 1 commit into from
Oct 6, 2016

Conversation

vadimdemedes
Copy link
Contributor

@vadimdemedes vadimdemedes commented Oct 1, 2016

Starting a series of "cleaning up" PRs to make AVA's codebase cleaner and friendlier to everyone. These PRs don't change any functionality and don't modify tests on purpose, those are just code improvements.

This PR removes lots of nesting, nested functions (tryRun(), run(), runner()) and confusing code. Also, it brings little improvements in the naming, options objects and makes functions shorter by extracting their parts into individual functions.

@vadimdemedes vadimdemedes force-pushed the cleanup-api branch 4 times, most recently from 93d1b9b to ea25e80 Compare October 2, 2016 10:59
@vadimdemedes vadimdemedes changed the title [WIP] Clean up api.js Clean up api.js Oct 2, 2016
@vadimdemedes
Copy link
Contributor Author

PR is ready for review!

Copy link
Member

@sindresorhus sindresorhus left a comment

Choose a reason for hiding this comment

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

Generally looks good, but a little bit hard to review due to all the changes. I ended up looking at https://github.com/avajs/ava/blob/ea25e802bce67b195d5f0fc331291bb02f16b866/api.js and https://github.com/avajs/ava/blob/master/api.js on a per method basis.

var findOptions = {
cwd: this.options.resolveTestsFrom,
files: files
};
Copy link
Member

Choose a reason for hiding this comment

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

I don't really see how this improves anything though. It was already clear what the options are for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point of this is not the name (I named it findOptions, because options is already defined there), but extracting options to reduce nesting. I can move it back, not insisting on this one.

options = {};
}

var prefixTitles = this.options.explicitTitles || files.length > 1;
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the point of extracting this either. It has the same title as the option name, so I don't see how this makes it any clearer.

Api.prototype._run = function (files, options) {
if (!options) {
options = {};
}
Copy link
Member

Choose a reason for hiding this comment

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

options = options || {};

@@ -153,7 +153,14 @@ module.exports = function (file, opts, execArgv) {
return promise;
};

var isExitInitiated = false;
Copy link
Member

@sindresorhus sindresorhus Oct 3, 2016

Choose a reason for hiding this comment

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

What change made this necessary? Maybe worth using onetime here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, I forgot... I remember it had something to do with this

ava/api.js

Line 305 in ea25e80

runStatus.on('timeout', function () {
. Sure, I'll use onetime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this completely and tests ran successfully, I guess there's no need for it.


runStatus.processResults(results);

return runStatus;
});
};

function getBlankResults() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this to the the top? Better to have it defined before use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

base: path.relative('.', commonPathPrefix(files)) + path.sep
runOnlyExclusive: options.runOnlyExclusive,
prefixTitles: prefixTitles,
base: basePath
Copy link
Member

Choose a reason for hiding this comment

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

If base is unclear, I think we instead should rename it in RunStatus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it'd rename it to basePath, but in a separate PR dedicated to cleaning up RunStatus.

@sindresorhus
Copy link
Member

Would be good if @jamestalmage could review, as he's the one that wrote most of the code in api.js.

@vadimdemedes
Copy link
Contributor Author

@sindresorhus addressed all your feedback, thanks!

@vadimdemedes vadimdemedes changed the title Clean up api.js Clean up API Oct 4, 2016
@sotojuan
Copy link
Contributor

sotojuan commented Oct 4, 2016

LGTM as well :-) Good work!

@sindresorhus sindresorhus merged commit 446886e into master Oct 6, 2016
@sindresorhus sindresorhus deleted the cleanup-api branch October 6, 2016 04:08
@sindresorhus
Copy link
Member

Alright. Landed. Good stuff @vdemedes :)

@vadimdemedes
Copy link
Contributor Author

vadimdemedes commented Oct 6, 2016

Thanks guys!

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.

3 participants