Skip to content

Commit

Permalink
add test suite (katspaugh#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
thijstriemstra committed Apr 11, 2015
1 parent bebc43e commit b9020c5
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
/node_modules
/bower_components
/npm-debug.log
/.grunt
/bin
/_SpecRunner.html
.DS_Store
34 changes: 32 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ module.exports = function(grunt) {
src: ['<%= concat.dist.src %>', 'plugin/*.js']
},
},
jasmine: {
core: {
src: '<%= concat.dist.src %>',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/helpers/*Helper.js',
vendor: [
'node_modules/jasmine-expect/dist/jasmine-matchers.js'
]
}
},
coverage: {
src: '<%= concat.dist.src %>',
options: {
specs: ['spec/*Spec.js'],
helpers: 'spec/helpers/*Helper.js',
vendor: [
'node_modules/jasmine-expect/dist/jasmine-matchers.js'
],
template: require('grunt-template-jasmine-istanbul'),
templateOptions: {
coverage: 'bin/coverage/coverage.json',
report: 'bin/coverage'
}
}
}
}
});

// ==========================================================================
Expand Down Expand Up @@ -127,8 +154,11 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jasmine');

// Default task.
grunt.registerTask('default', ['jshint', 'concat', 'commonjs', 'amd', 'uglify']);

grunt.registerTask('test', ['jasmine:core']);
grunt.registerTask('coverage', ['jasmine:coverage']);
grunt.registerTask('default', ['jshint', 'test', 'coverage', 'concat', 'commonjs',
'amd', 'uglify']);
};
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ General events:
Install `grunt-cli` using npm:

```
npm install -g grunt-cli
npm install -g grunt-cli jasmine istanbul
```

Install development dependencies:
Expand All @@ -215,14 +215,28 @@ npm install
```

Build a minified version of the library and plugins. This command also checks
for code-style mistakes:
for code-style mistakes and runs the tests:

```
grunt
```

Generated files are placed in the `dist` directory.

Running tests only:

```
grunt test
```

Creating a coverage report:

```
grunt coverage
```

The HTML report can be found in `bin/coverage/index.html`.

# Credits

Initial idea by [Alex Khokhulin](https://github.com/xoxulin). Many
Expand Down
2 changes: 1 addition & 1 deletion dist/wavesurfer.min.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"example": "example"
},
"scripts": {
"test": "echo No tests yet!"
"test": "grunt test"
},
"repository": {
"type": "git",
Expand All @@ -22,7 +22,10 @@
"grunt": ">=0.4.5",
"grunt-contrib-concat": ">=0.4.0",
"grunt-contrib-uglify": ">=0.5.0",
"grunt-contrib-jshint": ">=0.10.0"
"grunt-contrib-jshint": ">=0.10.0",
"grunt-contrib-jasmine": ">=0.8.2",
"grunt-template-jasmine-istanbul": ">=0.3.3",
"jasmine-expect": ">=1.22.3"
},
"homepage": "https://github.com/katspaugh/wavesurfer.js"
}
7 changes: 7 additions & 0 deletions spec/UtilSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("util", function() {

it("getId returns a unique string", function() {
expect(WaveSurfer.util.getId()).toStartWith('wavesurfer_');
});

});
15 changes: 15 additions & 0 deletions spec/helpers/SpecHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
beforeEach(function () {
jasmine.addMatchers({
toBePlaying: function () {
return {
compare: function (actual, expected) {
var player = actual;

return {
pass: player.currentlyPlayingSong === expected && player.isPlaying
}
}
};
}
});
});
9 changes: 9 additions & 0 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"spec_dir": "/spec/",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"spec/helpers/*[hH]elper.js"
]
}

0 comments on commit b9020c5

Please sign in to comment.