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 Compatibility #121

Merged
merged 22 commits into from
Nov 23, 2015
Merged

VideoJS 5.0 Compatibility #121

merged 22 commits into from
Nov 23, 2015

Conversation

misteroneill
Copy link
Member

This branch is for the VideoJS 5.0 compatible version of videojs-contrib-ads; merging this pull request to master will make master no longer compatible with VideoJS pre-5.0.

Functional Changes

There is no longer any use of setImmediate (non-standard) or requestAnimationFrame; rather, timers are 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.

There are two minor naming changes:

  • player.ads.timeout has been renamed player.ads.adTimeoutTimeout.
  • player.ads.resumeEndedTimeout is now exposed.

For the most part, the upgrade process (outside the VideoJS 5.0 upgrade) should be mostly transparent for this plugin.

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!

- 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 misteroneill changed the title VideoJS 5.0 Compatibility - CAUTION! VideoJS 5.0 Compatibility Nov 23, 2015
misteroneill added a commit that referenced this pull request Nov 23, 2015
@misteroneill misteroneill merged commit 6b7b3f8 into master Nov 23, 2015
@misteroneill misteroneill deleted the vjs-5-upgrade branch November 23, 2015 19:10
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.

1 participant