mirror of
https://github.com/wahyd4/play-sound.git
synced 2026-08-09 04:46:23 +10:00
start throwing errors when file doesn't exist
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
var fs = require('fs')
|
||||
|
||||
function Play(opts){
|
||||
var opts = opts || {}
|
||||
|
||||
@@ -9,6 +11,7 @@ function Play(opts){
|
||||
|
||||
this.play = function(what){
|
||||
if (!what) return;
|
||||
if (!fs.existsSync(what)) throw new Error("Couldn't find file: " + what)
|
||||
|
||||
var players = this.players,
|
||||
self = this
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"devDependencies": {
|
||||
"expect.js": "^0.3.1",
|
||||
"mocha": "^1.21.4",
|
||||
"mock-fs": "^2.3.1",
|
||||
"sinon": "^1.10.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
var expect = require('expect.js')
|
||||
, sinon = require('sinon')
|
||||
, mock = require('mock-fs')
|
||||
|
||||
|
||||
describe('cvlc has the maximum priority', function(){
|
||||
it('tries to play with cvlc first', function(){
|
||||
var command = "cvlc beep.mp3"
|
||||
, spy = sinon.stub()
|
||||
var command, spy, cli;
|
||||
|
||||
var cli = require('./')({ child_process: {
|
||||
exec: spy
|
||||
}})
|
||||
beforeEach(function(){
|
||||
command = "cvlc beep.mp3"
|
||||
, spy = sinon.stub()
|
||||
, cli = require('./')({ child_process: { exec: spy }})
|
||||
|
||||
mock({'./beep.mp3': ''})
|
||||
})
|
||||
|
||||
it('tries to play with cvlc first', function(){
|
||||
spy.callsArg(1)
|
||||
|
||||
cli.play("beep.mp3")
|
||||
@@ -20,31 +25,37 @@ describe('cvlc has the maximum priority', function(){
|
||||
})
|
||||
|
||||
it("doesn't try to play anything if nothing is passed", function(){
|
||||
var command = "cvlc beep.mp3"
|
||||
, spy = sinon.spy()
|
||||
|
||||
var cli = require('./')({ child_process: spy})
|
||||
cli.play()
|
||||
|
||||
expect(spy.called).to.not.be(true)
|
||||
})
|
||||
|
||||
it("fallbacks to other players if it's not available", function(){
|
||||
var command = "cvlc beep.mp3"
|
||||
, spy = sinon.stub()
|
||||
|
||||
var cli = require('./')({ child_process: {
|
||||
exec: spy
|
||||
}})
|
||||
spy.callsArg(1)
|
||||
spy.withArgs("cvlc beep.mp3").callsArgWith(1, "cvlc: command not found")
|
||||
|
||||
cli.play("beep.mp3")
|
||||
expect(cli.player).to.be("mplayer")
|
||||
})
|
||||
|
||||
after(function(){
|
||||
mock.restore()
|
||||
})
|
||||
})
|
||||
|
||||
describe('error handling', function(){
|
||||
it("throws errors if file doesn't exist")
|
||||
it("throws errors if the file doesn't exist", function(){
|
||||
var stub = sinon.stub()
|
||||
, cli = require('./')({ child_process: {exec: stub}})
|
||||
|
||||
expect(cli.play).withArgs("beep.mp3").to.throwException()
|
||||
})
|
||||
|
||||
it("throws errors if suitable audio tool couldn't be found")
|
||||
})
|
||||
|
||||
describe("overridable options", function(){
|
||||
it("supports overrides for the list of players")
|
||||
it("supports override for child_process")
|
||||
it("supports override for player")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user