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

Add tests for existing functionality #9

Merged
merged 20 commits into from
May 12, 2017
Merged

Conversation

leoj3n
Copy link
Contributor

@leoj3n leoj3n commented Apr 28, 2017

Changes some of the code in demo_frame.js, most notably show now sets display to '' instead of 'block'. Shouldn't cause any issues on any of the sites, but that is more correct.

The tests should be pretty comprehensive, but could add a test for a more complex example.
See test/basics/demo-complex.html for an example of a complex demo tag usage.

Update: Complex demo tag usage example test has been added.

❯ npm test

> bit-docs-tag-demo@0.3.0 test /Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo
> mocha test.js --reporter spec



  bit-docs-tag-demo
    temp directory
      ✓ is generated (13981ms)
    demo widget
      with ids
        ✓ exists on page
        tabs and contents
          ✓ has three
          ✓ only one active
          ✓ defaults to demo
        clicking HTML tab
          ✓ changes tab and content
        Demo
          iframe (demo-with-ids.html)
            ✓ has correct url and parent
            ✓ has correct content
        HTML
          data-for=html
            ✓ has correct content
        JS
          data-for=js
            ✓ has correct content
      without ids
        ✓ exists on page
        tabs and contents
          ✓ has three
          ✓ only one active
          ✓ defaults to demo
        clicking HTML tab
          ✓ changes tab and content
        Demo
          iframe (demo-without-ids.html)
            ✓ has correct url and parent
            ✓ has correct content
        HTML
          data-for=html
            ✓ has correct content
        JS
          data-for=js
            ✓ has correct content
      without js
        ✓ exists on page
        tabs and contents
          ✓ has three
          ✓ only one active
          ✓ defaults to demo
        clicking HTML tab
          ✓ changes tab and content
        Demo
          iframe (demo-without-js.html)
            ✓ has correct url and parent
            ✓ has correct content
        HTML
          data-for=html
            ✓ has correct content
        JS
          ✓ tab is hidden
          data-for=js
            ✓ has correct content
      complex
        ✓ exists on page
        tabs and contents
          ✓ has three
          ✓ only one active
          ✓ defaults to demo
        clicking HTML tab
          ✓ changes tab and content
        Demo
          iframe (demo-complex.html)
            ✓ has correct url and parent
            ✓ has correct content
        HTML
          data-for=html
            ✓ has correct content
        JS
          data-for=js
            ✓ has correct content
      multiple instances
        ✓ exist on page
        clicking all HTML tabs
          ✓ changes all tabs and contents


  40 passing (18s)

@leoj3n
Copy link
Contributor Author

leoj3n commented Apr 29, 2017

🥇 Reviewers:

I'd like feedback and to get this merged sooner than later, as it may influence tests I write elsewhere.
Thanks!

Copy link
Contributor

@chasenlehara chasenlehara left a comment

Choose a reason for hiding this comment

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

I left a few suggestions 🙂

demo_frame.js Outdated
@@ -86,11 +88,11 @@ module.exports = function(node){
}
}
}
return source.trim();
return (source ? source.trim() : false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I’d recommend just returning a string, not a string or boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.


<script src="../../node_modules/steal/steal.js" main="@empty" id='demo-source'>
import "can-view-autorender";
import "can-stache-bindings";
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems excessive to bring in so many dependencies for a test. Is this one needed? Are there any others that could be removed?

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 was wondering the same thing, but I don't know much about CanJS. Can you recommend a better "complex" test to do? I like this one because it takes a second (literally) to load.

Copy link
Contributor

Choose a reason for hiding this comment

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

can-stache-bindings is for stuff like {prop}="value"

What specifically did you want to test? To me, it looks like “complex” means loading modules with StealJS, so I would probably simplify the file to something like this:

<script src="../../node_modules/steal/steal.js" main="@empty" id='demo-source'>
import stache from "can-stache";
var renderer = stache("<h1>Hello {{subject}}</h1>");
var fragment = renderer({subject: "World"})
document.body.appendChild(fragment)
</script>

Copy link
Contributor Author

@leoj3n leoj3n Apr 30, 2017

Choose a reason for hiding this comment

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

There was a (click) handler that was causing errors under zombie that I removed, so that explains where the can-stache-bindings came from. The error had to do with cloneNode, but don't think that's something we would want to resolve just to support zombie. I took this from the canjs/canjs repo, so it's a real example, which I thought would be important to include next to the overly simple examples. The deps aren't that big of a burden since they're small and quick to install, and are dev only, but I can certainly simplify it if we're not losing anything beneficial by doing so.

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 made this change almost exactly as you have it here. Thanks for the snippet.

test.js Outdated
assert = require('assert'),
Browser = require('zombie'),
express = require('express'),
generate = require('bit-docs-generate-html/generate');
Copy link
Contributor

Choose a reason for hiding this comment

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

You don’t have to change this[1], but I’d recommend keeping variable declarations on separate lines. In this case, it’d be easier to scan through the list if they were formatted the same way and alphabetical.

[1] As far as I can tell, this isn’t covered in jQuery’s style guide… now I see why someone (@andrejewski?) was advocating for stricter guidelines.

Copy link
Contributor Author

@leoj3n leoj3n Apr 30, 2017

Choose a reason for hiding this comment

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

Well, the use of tabs is something I picked from other parts of the bit-docs codebase, and it is my understanding that it is @justinbmeyer's preference. I personally prefer spaces, but technically these do line up properly with your editor configured properly:

image

The spacing on GitHub's website could be resolved by adding .editorconfig.

I thought tabs were desired, and that's why I used them here. I'm fine with changing to using var on each declaration, replacing tabs with spaces, or adding .editorconfig.

At the end of the day, these tests do their job, and that's most important! I'll leave this for now, as eventually I imagine we'll run everything through a code formatter anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn’t say anything about using spaces instead of tabs. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For me, the odd spacing would stand out as a bigger issue when it comes to "easier to scan through the list if they were formatted the same way", and assumed that's what you meant.

The fact that I'm using tabs instead of spaces is a testament to the fact that I'm not having personal preference about formatting. I will change it however you like, but I was mostly concerned about getting your feedback on the functionality and test coverage!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change made.

@leoj3n leoj3n self-assigned this May 9, 2017
@leoj3n
Copy link
Contributor Author

leoj3n commented May 10, 2017

With current commits, assuming you manually run npm install inside of test/demos/demo-complex, the demo will work fine in a normal browser, but zombie seems to have the following issue...

(when running npm test):

{ Error: Error loading "package.json!npm" at <unknown>
Error loading "npm" at http://example.com/node_modules/steal/ext/npm.js
Not Found: http://example.com/node_modules/steal/ext/npm.js
    at error (http://example.com/demos/demo-complex/node_modules/steal/steal.js:3069:19)
    at XMLHttpRequest.xhr.onreadystatechange (http://example.com/demos/demo-complex/node_modules/steal/steal.js:3079:13)
    at XMLHttpRequest.callback.(anonymous function) (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:230:32)
    at invokeEventListeners (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:195:25)
    at invokeInlineListeners (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:163:7)
    at EventTargetImpl._dispatch (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:7)
    at EventTargetImpl.dispatchEvent (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
    at XMLHttpRequest.dispatchEvent (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:60:35)
    at XMLHttpRequest.DOM.EventTarget.dispatchEvent (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/zombie/lib/dom/jsdom_patches.js:182:31)
    at XMLHttpRequest._fire (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/zombie/lib/xhr.js:248:12) statusCode: 404 } 'Error: Error loading "package.json!npm" at <unknown>\nError loading "npm" at http://example.com/node_modules/steal/ext/npm.js\nNot Found: http://example.com/node_modules/steal/ext/npm.js\n    at error (http://example.com/demos/demo-complex/node_modules/steal/steal.js:3069:19)\n    at XMLHttpRequest.xhr.onreadystatechange (http://example.com/demos/demo-complex/node_modules/steal/steal.js:3079:13)\n    at XMLHttpRequest.callback.(anonymous function) (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:230:32)\n    at invokeEventListeners (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:195:25)\n    at invokeInlineListeners (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:163:7)\n    at EventTargetImpl._dispatch (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:7)\n    at EventTargetImpl.dispatchEvent (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)\n    at XMLHttpRequest.dispatchEvent (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:60:35)\n    at XMLHttpRequest.DOM.EventTarget.dispatchEvent (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/zombie/lib/dom/jsdom_patches.js:182:31)\n    at XMLHttpRequest._fire (/Users/leoj/bitovi/,+/bd/1/bit-docs-tag-demo/node_modules/zombie/lib/xhr.js:248:12)'

Perhaps something in steals npm ext is not compatible with jsdom?:

https://github.com/stealjs/steal/blob/master/ext/npm-load.js

It would be nice to have encapsulation of the demo deps, as mentioned in #11.

@chasenlehara
Copy link
Contributor

@leoj3n Is that blocking this from being merged? If not, will you merge this?

@leoj3n
Copy link
Contributor Author

leoj3n commented May 11, 2017

The latest commits are blocking; I should have made them a separate branch/PR (though, I didn't expect zombie to error after some simple reorganization).

I'll back out the commits for isolating demo deps, so that this PR will be merge-able again, and break out that idea into it's own PR.

Also simplifies the "complex" demo and test.
Additionally, moves location of "temp" into test/
@leoj3n
Copy link
Contributor Author

leoj3n commented May 11, 2017

@chasenlehara Should be merge-able again now.

@chasenlehara
Copy link
Contributor

Ok go for it

@leoj3n leoj3n merged commit 7e45843 into master May 12, 2017
@chasenlehara chasenlehara deleted the mocha-qunit-tests-working branch December 29, 2017 00:35
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.

2 participants