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

State: Remove subtree Makefiles in favor of single test runner #3773

Merged
merged 6 commits into from
Mar 4, 2016

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Mar 4, 2016

Part of #3822.

This pull request seeks to eliminate subtree-specific Makefiles in the client/state directory, used always for testing, with a single test runner for the entirety of the client/state directory.

The changes include 22 eliminated Makefiles.

Benefits include:

  • Improved performance by decreasing number of Mocha/Babel reinitializations
  • Common before / after helpers (specifically chai middleware and nock lifecycle)
  • Fewer files to maintain
  • Assurance of proper test teardown for eventual inclusion in global test runner

Testing instructions:

Ensure tests pass by running make test from the project root directory.

@aduth aduth added Framework [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Mar 4, 2016
@aduth
Copy link
Contributor Author

aduth commented Mar 4, 2016

For the moment, this does not include plugins/wporg, as there are more customized mocked functions there. I'll see if it's simple enough to include in these changes.

#3773 (comment)

@blowery
Copy link
Contributor

blowery commented Mar 4, 2016

That's amazing. How much faster is it?

@aduth
Copy link
Contributor Author

aduth commented Mar 4, 2016

@blowery : Looks pretty significant, about 92% faster (3.7412s average now, 48.1172s average previously).

https://gist.github.com/aduth/389940df7aebc0805167

@blowery
Copy link
Contributor

blowery commented Mar 4, 2016

And it appears that most all of that time is spent compiling the JS. Big pause, then all of the tests spit out pretty quickly. This will likely scale up quite well.

@mtias
Copy link
Member

mtias commented Mar 4, 2016

This is great.

@blowery
Copy link
Contributor

blowery commented Mar 4, 2016

Messing around with it a little bit, I'm not sure we're using the babel cache. Running this from client/state:

time env BABEL_CACHE_PATH=/tmp/babel/cache-new.json REPORTER=min make test

I get a timing of about 5s cold, 2s hot.

time env REPORTER=min make test

I get ~3s hot. Cold is back around 5s.

@aduth
Copy link
Contributor Author

aduth commented Mar 4, 2016

It wasn't much trouble to include plugins in the single test runner, so there's now only a single Makefile for the entire client/state directory with the changes here.

@blowery
Copy link
Contributor

blowery commented Mar 4, 2016

Just confirmed with BABEL_DISABLE_CACHE=1.

Cold = 5s
Default babel caching = 3.3s
Specified babel cache = 2.2s

So finding the cache location takes babel a full second? Weird.

@aduth
Copy link
Contributor Author

aduth commented Mar 4, 2016

@blowery : Looks like CircleCI would let us specify custom directories for cached files, so might be an interesting way to keep tests hot between builds.

Perhaps out of scope of this pull request though? 😄

@gwwar
Copy link
Contributor

gwwar commented Mar 4, 2016

Do we have instructions for testing a single test file?

@blowery
Copy link
Contributor

blowery commented Mar 4, 2016

@aduth #3782

@aduth
Copy link
Contributor Author

aduth commented Mar 4, 2016

Do we have instructions for testing a single test file?

Spent some time wrestling with Makefile, and came up with a solution in 5f0307c which lets a developer run make test-posts from client/state to run only the posts-related tests. This can be even more granular if they wish, e.g. make test-"sites plans".

@gwwar
Copy link
Contributor

gwwar commented Mar 4, 2016

👍 I gave it a spin, and it works as described. I think I'd still want the granularity of being able to test a specific file, instead of relying on the grep flag, but I'll spin up a separate PR for that. 🚢

@gwwar gwwar added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Mar 4, 2016

describe( 'state', () => {
before( () => {
Chai.use( sinonChai );
Copy link
Member

Choose a reason for hiding this comment

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

I really like that we are doing setup and tear down on the top level, especially I'm happy about disabling all network requests 👍

@gziolo
Copy link
Member

gziolo commented Mar 4, 2016

@aduth: Great work on that PR. In my opinion this is a really simple approach that scales well. We can repeat all steps taken here in other subfolders. In parallel we cane figure out how to optimise the way we load single files. There is also very high probability that if tests loaded for given subfolder execute successfully they are going to work also when combined at top level with other subfolders. :)

🚢

@@ -5,6 +5,9 @@ BASE_DIR := $(NODE_BIN)/../..
NODE_PATH := $(BASE_DIR)/client

test:
@NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register,js:babel/register --reporter $(REPORTER)
@NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register,js:babel/register --reporter $(REPORTER) $(addprefix --grep ,$(GREP))
Copy link
Contributor

Choose a reason for hiding this comment

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

I played around with this a bit too, and came up with:

REPORTER ?= spec
NODE_BIN := $(shell npm bin)
MOCHA ?= $(NODE_BIN)/mocha
BASE_DIR := $(NODE_BIN)/../..
NODE_PATH := $(BASE_DIR)/client
FILE = "./test"
test:
    @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register,js:babel/register --reporter $(REPORTER) $(FILE)

.PHONY: test

With single test usage:

make test FILE=/Users/kerryliu/checkouts/wp-calypso/client/state/test/initial-state.js

The only downside is we don't get the setup/cleanup from the index.js file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gwwar: I think we might be able to do something with package.json scripts, as npm will automatically traverse up to the closest package.json. The idea would be to specify the test as running Mocha with all of our environment variables. This could be in a package.json in client/state, or in the root package.json, so long as we detect whether the current working directory is outside the project root.

Then, running cd client/state/sites/plans && npm test would only run the site plans tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

The only downside is we don't get the setup/cleanup from the index.js file.

That seems like a big downside?

Maybe something to bake into a custom runner at the root? Only add files that match a glob, but always add the root, which has setup / teardown.

@aduth aduth force-pushed the update/redux-single-test-runner branch from 5f0307c to bc0576c Compare March 4, 2016 22:14
aduth added a commit that referenced this pull request Mar 4, 2016
State: Remove subtree Makefiles in favor of single test runner
@aduth aduth merged commit e28400e into master Mar 4, 2016
@aduth aduth deleted the update/redux-single-test-runner branch March 4, 2016 22:27
@aduth
Copy link
Contributor Author

aduth commented Mar 4, 2016

Thanks for the reviews, all! Going to go through any related open pull requests that might be affected and ping the authors.

} );

describe( 'ui', () => {
require( '../users/test/actions' );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gah, these should be ../ui 😧 Will put together a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants