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

VideoJS 5.0 Updates (DO NOT MERGE) #116

Closed
wants to merge 19 commits into from

Conversation

misteroneill
Copy link
Member

This updates the plugin for use with VideoJS 5.0 changes.

There is one functional change that should not affect consumers of the plugin whatsoever: there is no longer any use of setImmediate (non-standard) or requestAnimationFrame; rather, this is simplified to use setTimeout universally. This not only makes code easier to reason about - no need to think about the minor differences in 3 separate APIs - but it makes testing using Sinon's fake timers more straight-forward.

Testing Changes

The bulk of the changes in this PR are related to testing; this seemed like a good opportunity for that work. There were significant sources of fragility in the tests previously and this sweeps the entire test suite with changes like:

Reduced reliance on globals

Each test should have whatever scaffolding it needs attached to this, imported from other sources, or hidden in a closure. Leaking globals is a good way to cause hard-to-debug issues.

Eliminated duplicated code

Particularly in setup/teardown processes, there was a ton of repetition. This should now be minimized via sharedModuleHooks.

Switched to QUnit 2.0-style tests

  • The only QUnit global that should be used now is QUnit.
  • QUnit.module should be passed beforeEach/afterEach hooks instead of the deprecated setup/teardown.
  • All assertion functions can be referenced on the assert object passed into each test (defined by QUnit.test).

Reduced assertion fragility

There was a lot of use of QUnit.assert.equal, which could potentially lead to bugs. QUnit.assert.strictEqual is used now, for the same reason === is preferred to ==.

Used Sinon extensively

Fake timers were already in use in a few places, but this makes that universal (particularly in the Flash tests). All custom/manual function spying is replaced by uses of sinon.spy - no more manual counting or pushing onto arrays!

@misteroneill misteroneill changed the title VideoJS 5.0 Updates (NOT READY) VideoJS 5.0 Updates Sep 8, 2015
@@ -1,2 +1,3 @@
/dist/
Copy link
Member

Choose a reason for hiding this comment

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

do we have an npmignore? Because otherwise, npm would ignore the dist folder as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Added an empty .npmignore file.

Copy link
Member

Choose a reason for hiding this comment

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

Also, when this is ready to go, we should try publishing it to npm under a next or beta tag.

@misteroneill
Copy link
Member Author

This can probably be reviewed, but should not be merged until we are sure it should be in master since it's not 4.x compatible!

@misteroneill
Copy link
Member Author

Also, worth noting: two tests are currently broken in events.html, but this is a result of a bug in VideoJS.

"qunitjs": "^1.17.1",
"video.js": "^4.12.4"
"sinon": "~1.16.1",
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick but isn't ^ the best-practice version specifier these days?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it was ~.

I've run into a lot of issues in the past with ^ bringing in breaking changes (despite semver saying minor versions should be backward-compatible); sometimes multiple dependency layers deep.

That said, I'm fine with changing these. It ought to be a company/project-wide standard, though.

Copy link
Member

Choose a reason for hiding this comment

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

With sinon, I would even just get rid of the prefix altogether. They broke too many times on minor and patch releases to trust them.
lodash I think is fine to use ^.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. I've never had a problem with Sinon at all.

@dmlap
Copy link
Member

dmlap commented Sep 17, 2015

This was really tough to review. I know the timeout stuff was a pain to convert but it would have been a lot easier if we could have split the upgrade + refactor.

@misteroneill
Copy link
Member Author

Yeah, that's fair.

There were so many test failures related to subtle differences in things that are now async that were not previously - as well as the order and structure of events between video.js and contrib-ads - that it would've been a big thing regardless.

@misteroneill
Copy link
Member Author

This is good for review once again.

@nickygerritsen
Copy link

I'm using this PR for implementing ads in 5.0, but I have a suggestion:

Could you add a main section to package.json. Then I can use a nice import 'videojs-contrib-ads' instead of import '../node_modules/videojs-contrib-ads/dist/videojs.ads.js'.

Maybe this only makes sense after releasing?

@dmlap
Copy link
Member

dmlap commented Sep 24, 2015

Would be nice to get @nickygerritsen's suggestions in here too but LGTM either way.

player.ads = {
state: 'content-set',

// Call this when an ad response has been recieved and there are

Choose a reason for hiding this comment

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

Although not changed in this PR, recieved does not seem as a valid word to me ;). This is already wrong in the src file of course.

The same typo is there 15 lines lower.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right - "i" before "e" except after "c"! :)

@misteroneill misteroneill changed the title VideoJS 5.0 Updates VideoJS 5.0 Updates (DO NOT MERGE) Sep 28, 2015
- This removes the variable use of setImmediate/clearImmediate and RAF;
  replacing it with universal use of setTimeout.
- Tests were not great because they did a lot of manual overriding of
  setTimeout and friends. They will now use Sinon's fake timers feature
  instead.
- Updates tests to use QUnit 2.0 style, for future compatibility.
  Related to this, there is a general shift here away from relying on
  any global state (outside of helper functions) in tests as that
  makes them less atomic.
Also added a `hasClass` function to make it easier to test that.
Not sure why this one test needs async handling, but it appears to. The
only way to make it not async is to trigger the 'play' event on the
player's `tech_` object.
This also renames the obscure `timeout` in the plugin to the more
meaningful `adTimeoutTimeout`.
@misteroneill
Copy link
Member Author

Closing in favor of #121

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

Successfully merging this pull request may close these issues.

4 participants