Skip to content

Commit

Permalink
Rename Parser::report -> ::stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed May 19, 2015
1 parent eb06d21 commit 742b49b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "soysauce",
"bin": "soysauce",
"description": "Create SauceLabs browser matrix widget",
"version": "0.0.2-beta.1",
"version": "0.0.2",

"scripts": {
"postinstall": "coffee -o lib -c src",
Expand Down
9 changes: 1 addition & 8 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cli= new Command
cliVersion= (require '../package').version

Promise= require 'bluebird'
travisFold= require 'travis-fold'

path= require 'path'
fs= Promise.promisifyAll(require 'fs')
Expand Down Expand Up @@ -92,13 +91,7 @@ class Soysauce extends Parser

Promise.all promises
.then (statuses)=>
widgetData= super statuses,travisJobId

data= ''
data+= travisFold.start 'soysauce' if travisJobId
data+= widgetData
data+= travisFold.end 'soysauce' if travisJobId
data
@stringify statuses,travisJobId

fetch: (travisJobId)->
new Promise (resolve,reject)=>
Expand Down
14 changes: 10 additions & 4 deletions src/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Build= require './build'
Widget= require './widget'

request= require 'request'
travisFold= require 'travis-fold'

fs= require 'fs'
path= require 'path'
Expand All @@ -22,14 +23,19 @@ class Parser
getKey: (id='UNKNOWN')->
'=====TRAVIS_JOB_'+id+'_RESULT====='

report: (statuses,id)->
stringify: (statuses,id)->
key= @getKey id

if id
report= key+'\n'+(JSON.stringify statuses)+'\n'+key
widgetData= key+'\n'+(JSON.stringify statuses)+'\n'+key
else
report= JSON.stringify statuses,null,2
report
widgetData= JSON.stringify statuses,null,2

data= ''
data+= travisFold.start 'soysauce' if id
data+= widgetData
data+= travisFold.end 'soysauce' if id
data

fetch: (id,callback)->
request travisLogUrl+id+'/log.txt',(error,response)->
Expand Down
13 changes: 9 additions & 4 deletions test/specs/API.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Dependencies
soysauce= require '../../'
Parser= require '../../src/parser'
parser= new Parser

fs= require 'fs'
path= require 'path'
Expand All @@ -11,17 +10,23 @@ express= require 'express'

# Environment
fixtureJson= path.join __dirname,'..','fixture.json'
fixture= JSON.parse fs.readFileSync(fixtureJson).toString()
fixtureIds= _.pluck fixture,'id'
TRAVIS_JOB_ID= 62974455

# Specs
describe 'API',->
it 'has Parser methods',->
parser= new Parser
expect(soysauce.constructor.__super__).toEqual parser.__proto__

it 'Fetch widget.json',(done)->
fixture= JSON.parse fs.readFileSync(fixtureJson).toString()
fixtureIds= _.pluck fixture,'id'
it 'Create widget.json for zuul',->
key= soysauce.getKey TRAVIS_JOB_ID
log= soysauce.stringify fixture,TRAVIS_JOB_ID

expect(log).toBe key+'\n'+JSON.stringify(fixture)+'\n'+key

it 'Fetch widget.json',(done)->
soysauce.report 59798,fixtureIds
.then (statuses)->
ids= _.pluck (JSON.parse statuses),'id'
Expand Down
4 changes: 2 additions & 2 deletions test/specs/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ describe 'Fetch SauceLabs Job statuses via TravisCI',->
travisLog= null

it 'Write widget.json',->
log= parser.report fixture
log= parser.stringify fixture

expect(log).toBe JSON.stringify fixture,null,2

it 'Write widget.json for log.txt',->
key= parser.getKey TRAVIS_JOB_ID
log= parser.report fixture,TRAVIS_JOB_ID
log= parser.stringify fixture,TRAVIS_JOB_ID

expect(log).toBe key+'\n'+JSON.stringify(fixture)+'\n'+key

Expand Down

0 comments on commit 742b49b

Please sign in to comment.