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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
add new data-driven test suite + move all existing tests to it #178
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Dec 4, 2017
This is awesome. |
This change looks generally well received (two hearts + 1 good comment), and only affects our test suite so I will merge it now. Plus, it's blocking some other changes I have in the pipeline like #180. Also, I've decided I will not squash merge this change both because it is disabled in the repo (to prevent myself from doing that) and to stay consistent. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change moves us over to a data-driven test suite and moves all existing tests over to it.
The basic idea is that instead of writing a bunch of DOM mocking code like we used to, we now just create a test by performing some Vecty actions and the DOM operations are recorded to a file. We keep the file of wanted DOM operations around, and they are compared.
For example,
TestSetTitle
used to look like this:The vast majority of this code is setting up a fake JS DOM
global
,global.get
,document
,document.set
, etc. objects & methods in order to properly checkwas global.document.title set to the string "foobar"?
. It's far too verbose and unreadable for such a simple test. The problem is even worse for larger tests that we have.Instead of the above, the new test suite makes this test be written just as:
When
go test
is ran, a new filetestdata/TestSetTitle.got.txt
is written which looks like this:It tells us that first
global.Get("document")
was called, and subsequentlySet("title", "foobartitle")
was called on the pointer returned byglobal.Get("document")
originally (that is, the second line does not say thatglobal.Get("document")
was called twice).The test suite also tells you that
testdata/TestSetTitle.got.txt
does not match (the non-existent)testdata/TestSetTitle.want.txt
file and it shows you a nice colored diff and informs you:If you then run the suggested command and commit the
testdata
folder changes, the test now succeeds & no regressions can occur here in the future.Additionally, what the diff stats on GitHub here does not show is that:
testdata/**.want.txt
files have been added.I think that this new test suite will substantially help in our goal to achieve 100% test coverage (#168) because adding a new test requires no more mocking. Just perform some Vecty actions in the Go test code, run
go test
from the command line, confirm the DOM operations look correct & follow the instructions when prompted. 馃槂Note: I will merge this change not as a squash commit, because it is in logical commits & is useful to see how each individual test was migrated over to the new test suite.
Helps #168
/cc @pdf (and @shurcooL who may find this to be an interesting/cool simplification :) )