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

refactor isomorphic tests #595

Merged
merged 15 commits into from
Feb 3, 2017
Merged

refactor isomorphic tests #595

merged 15 commits into from
Feb 3, 2017

Conversation

giladgray
Copy link
Contributor

@giladgray giladgray commented Feb 1, 2017

cc @codebling

Changes proposed in this pull request:

  • DRY isotest code by introducing helper function that does all the work
  • move usage into test/ directory in each package

@giladgray
Copy link
Contributor Author

@codebling how can i be sure that these tests are actually passing and not reporting false positives? can you describe an easy way to make a component fail the test? (i'm an SSR noob and could use a hand.)

test/isotest.js Outdated
if (isReactClass(Component)) {
it("can be server-rendered", () => {
it(`<${ComponentKey}> can be server-rendered`, () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved component name into test name so they can be easily distinguished when run in parallel (previously all its had the exact same name)

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't had a look at all of the changes yet, but in my experience, console outputs can become interlaced when running in parallel/asynchronously. I'd imagined this to be the reason why the tests were set up to run in series when I first found then.

@blueprint-bot
Copy link

revert circle.yml to run gulp test

Preview: docs | table
Coverage: core | datetime

@giladgray
Copy link
Contributor Author

giladgray commented Feb 1, 2017

also @codebling is it isometric or isomorphic? I think the latter is correct, as in isomorphic-fetch.

@adidahiya
Copy link
Contributor

✅ isomorphic

@blueprint-bot
Copy link

bring back missing require

Preview: docs | table
Coverage: core | datetime

@codebling
Copy link
Contributor

@giladgray you can fail a test by attempting simply including a reference to document in the constructor (or any of the life cycle methods that run before DidMount, which never gets called on the server). document is undefined server-side

to produce static HTML, just as a server would.
expecting this build to fail and reveal several broken components.
gulp/aliases.js Outdated
@@ -22,7 +22,8 @@ module.exports = (gulp) => {
gulp.task("build", (done) => rs("clean", "compile", "webpack-compile-docs", done));

// build code, run unit tests, terminate
gulp.task("test", ["test-dist", "karma", "isotest"]);
// NOTE: circle.yml runs each of these separately for better error reporting; be sure to sync
Copy link
Contributor

Choose a reason for hiding this comment

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

"be sure to sync"? what does that mean? also, how does it produce better error reporting? does it run the next gulp task even if a previous one fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

means keep the two uses in sync. make sure they run the same tasks.

https://circleci.com/gh/palantir/blueprint/1503 shows two of the three failing.

i have an idea how to post comments on build failure, and we could post a different comment based on which ones fail.

test/isotest.js Outdated
* @param customProps {{ [componentName: string]: any}} custom props per component
* @param customChildren {{ [componentName: string]: React.ReactNode }} custom children per component
*/
module.exports = function isotest(Components, customProps, customChildren) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be more verbose to make it clear that it generates multiple tests? generateIsoTests? same for the import name elsewhere

},
},
files: filesToInclude,
frameworks: ["mocha", "chai", "phantomjs-shim", "sinon"],
mime: {
Copy link
Contributor

Choose a reason for hiding this comment

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

curious, why do we need this now?

Copy link
Contributor Author

@giladgray giladgray Feb 2, 2017

Choose a reason for hiding this comment

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

it was added in #409, then lost in #381 when moving config to separate file (notice the smaller number 😄), and now restored here.

@giladgray
Copy link
Contributor Author

giladgray commented Feb 2, 2017

@codebling got it. i tried messing with a few components and the tests didn't fail so i tried using enzyme's static HTML renderer and it revealed a handful of problematic components.

see build 1508 from commit above (edited) for some legit errors.

Gilad Gray added 4 commits February 1, 2017 17:59
run in series so outputs don't clash.
then we can just do the simple and maintainable `gulp test` in circle.yml instead of re-listing each task.
@blueprint-bot
Copy link

add required props and children

Preview: docs | table
Coverage: core | datetime

@adidahiya
Copy link
Contributor

please file follow-up tickets for any skipped tests

@codebling
Copy link
Contributor

@giladgray I see only passing tests in the build you linked. As far as switching to the Enzyme renderer, if you're able to find a way to pass specific Props and Children, then it should work. I wasn't able to find a way to do that with Enzyme (if I recall correctly), which is why I switched to ReactTestUtils. It's explained in the first comment in #381.

@giladgray
Copy link
Contributor Author

@codebling ah you're right that link was wrong. i fixed it above. here's the correct build:
https://circleci.com/gh/palantir/blueprint/1508.

regarding the specific children: you'd already built all the pieces with customProps and customChildren! 🏆 I just filled them out. but that validations happens in the constructor, which I believe is supposed to run as part of the server render? it seemed to me like TestUtils wasn't doing enough work, or wasn't reporting errors, (false positives indeed) but enzyme immediately told me what was wrong.

@giladgray giladgray added the P0 label Feb 3, 2017
@blueprint-bot
Copy link

Merge branch 'master' of github.com:palantir/blueprint into gg/isotest

Preview: docs | table
Coverage: core | datetime

Copy link
Contributor

@cmslewis cmslewis left a comment

Choose a reason for hiding this comment

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

[Timid approval] Looks good based on my very limited understanding of isomorphic stuff.

gulp/aliases.js Outdated
// build code, run unit tests, terminate
gulp.task("test", ["test-dist", "karma", "isotest"]);
// run test tasks in series to keep outputs separate
gulp.task("test", (done) => rs("test-dist", "karma", "isotest-mocha-w"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Call done() here.

@blueprint-bot
Copy link

call `done` in test alias

Preview: docs | table
Coverage: core | datetime

@giladgray giladgray removed the P0 label Feb 3, 2017
@giladgray giladgray merged commit 9af075c into master Feb 3, 2017
@giladgray giladgray deleted the gg/isotest branch February 3, 2017 21:06
@giladgray giladgray mentioned this pull request Feb 3, 2017
@codebling
Copy link
Contributor

@giladgray regarding the build failures in the linked test, none of them seem specifically server-rendering related. I can't check out that commit any more because it's been squashed and I see that no changes were made to some of the failing components, so I wonder if it was an issue with the task. I see everything is running well on latest master (1dced45), so you must have figured it out. Great work !

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.

None yet

6 participants