-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
|
That's amazing. How much faster is it? |
@blowery : Looks pretty significant, about 92% faster (3.7412s average now, 48.1172s average previously). |
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. |
This is great. |
Messing around with it a little bit, I'm not sure we're using the babel cache. Running this from client/state:
I get a timing of about 5s cold, 2s hot.
I get ~3s hot. Cold is back around 5s. |
It wasn't much trouble to include |
Just confirmed with Cold = 5s So finding the cache location takes babel a full second? Weird. |
@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? 😄 |
Do we have instructions for testing a single test file? |
Spent some time wrestling with |
👍 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. 🚢 |
|
||
describe( 'state', () => { | ||
before( () => { | ||
Chai.use( sinonChai ); |
There was a problem hiding this comment.
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 👍
@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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
5f0307c
to
bc0576c
Compare
State: Remove subtree Makefiles in favor of single test runner
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' ); |
There was a problem hiding this comment.
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.
Part of #3822.
This pull request seeks to eliminate subtree-specific
Makefile
s in theclient/state
directory, used always for testing, with a single test runner for the entirety of theclient/state
directory.The changes include 22 eliminated
Makefiles
.Benefits include:
before
/after
helpers (specificallychai
middleware andnock
lifecycle)Testing instructions:
Ensure tests pass by running
make test
from the project root directory.