Skip to content

Commit

Permalink
show file
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrancois committed Mar 31, 2015
1 parent b01d1be commit 1a96d6b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/jsio.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ try {
case "copy":
jsiojs.copyFile(params[0], params[1])
break
case "show":
jsiojs.showFile(params[0])
break
default:
console.error("Invalid command")
break
Expand Down
6 changes: 6 additions & 0 deletions lib/jsiojs_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ exports.copyFile = function(source, destination){
fs.createReadStream(source).pipe(fs.createWriteStream(destination));
console.info('File '+source+' copied to '+destination+' with success !')
}

exports.showFile = function(fileName){
checkJsFile(fileName)
checkFileExist(fileName)
fs.createReadStream(fileName).pipe(process.stdout);
}

function checkJsFile(fileName){
if(fileName === undefined)
Expand Down
48 changes: 48 additions & 0 deletions test/jsiojs_core_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,54 @@ describe('jsiojs', function() {

})

describe('jsiojs', function() {
describe('#showFile', function() {
it('Should show a javascript file', function() {
// Given
var fileName = generateFileName()
fs.writeFileSync(fileName,"")
fs.existsSync(fileName).should.be.true
// When
jsiojs.showFile(fileName)
// Then
fs.existsSync(fileName).should.be.true
})
})


describe('#showFile', function() {
it('Should fail when no fileName', function() {
// When
var fn = function(){ jsiojs.showFile() }
// Then
expect(fn).to.throw("file name is missing")
})
})

describe('#showFile', function() {
it('Should fail when not a javascript file', function() {
// Given
var fileName = generateFileName()+".txt"
// When
var fn = function(){ jsiojs.showFile(fileName) }
// Then
expect(fn).to.throw(fileName+" is not a valid javascript file name")

})
})

describe('#showFile', function() {
it('Should fail when file does not exist', function() {
// Given
var fileName = generateFileName()
fs.existsSync(fileName).should.be.false
// When
var fn = function(){ jsiojs.showFile(fileName) }
// Then
expect(fn).to.throw(fileName+" does not exist")
})
})
})

function generateFileName(){
return tmpDir+Math.random()+".js"
Expand Down

0 comments on commit 1a96d6b

Please sign in to comment.