Contributing to open source: Buzz Audio Library

One of the best ways to learn a new language or new approaches to solve daily problems is to see how other people deals with it. When I started to code Vitrola's HTML Player, I've had a hard work to find out a good JS library to handle the HTML5's audio tag, but after some hours of searching I've found the fantastic Buzz Audio Library.

Buzz is a simple JavaScript library that abstracts HTML5 Audio tag. With it, you can create audio groups, audio looping, fade in and fade out effects and other features that we needed for our player. It has a good documentation, but the library doesn't have any tests or automated builds. So, why not contribute to it and make a better solution?

First contribution

In order to add unit tests to this library, I started to describe the features we needed in our project: increase/decrease volume, mute and the audio commands like play/pause/stop, etc. In other words, I've just used my player features to create specs for the library and this was very good, because I see that the library fits my needs and works as expected

For this task, I decided to use Jasmine. For those who doesn't know, Jasmine, as the official website says, is a behavior-driven development framework for testing JavaScript code. It's a kind of RSpec for Javascript.

So, imagine audio controls feature: play/pause/etc:

describe('audio control', function() {
    beforeEach(function(done) {
        jasmine.Expectation.addMatchers(matchers);

        sound.play();
        songHasStarted(done);
    });

    afterEach(function() {
        sound.stop();
    });
    
    it('should play a song normally', function() {
        expect(sound.getTime()).toBeGreaterThan(0);
    });
    
    it('should pause a song', function() {
        sound.pause();
        expect(sound.isPaused()).toBeTruthy();
    });
    
    it('should stop a song', function() {
        sound.stop();
        expect(sound.getTime()).toBe(0);
        expect(sound.isPaused()).toBeTruthy();
    });
});

Among that, I've added TravisCI support to run this tests and build the project with Grunt, a Javascript task runner, to make the process more automated. The complete list of pull requests you can find here.

So what I want to say with this? This contribution helped me to understand the library I was using and turned it more reliable to other people that wants to use. Go ahead, maybe you can contribute to some open source libraries you are using and this is, definitely, one of the best ways to learn and improve your code skills, you'll feel more confident to contribute to other projects.