Skip to content

Commit

Permalink
Remove Parser.options.standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed May 19, 2015
1 parent 3c81944 commit 23bbfe4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 40 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"main": "soysauce",
"bin": "soysauce",
"description": "Create SauceLabs browser matrix widget",
"version": "0.0.4-beta.1",
"version": "0.0.4",

"scripts": {
"postinstall": "coffee -o lib -c src",

"start": "jasminetea test --file '*.coffee' --verbose --watch --recursive --timeout 5000",
"test": "jasminetea test --file '*.coffee' --verbose --recursive --cover --lint --report --timeout 5000"
"start": "jasminetea test --file '*.coffee' --verbose --watch --recursive --timeout 6000",
"test": "jasminetea test --file '*.coffee' --verbose --recursive --cover --lint --report --timeout 6000"
},

"dependencies": {
Expand Down
46 changes: 26 additions & 20 deletions src/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,45 @@ sauceLabsUrl= 'https://saucelabs.com/rest/v1/'
travisLogUrl= 'https://s3.amazonaws.com/archive.travis-ci.org/jobs/'

class Parser
constructor: (@options={})->
@options.fold?= yes
@options.standalone?= yes
constructor: (@datauri=on)->

fetchBuild: (username,sessionId,callback)->
request sauceLabsUrl+username+'/jobs/'+sessionId,(error,response)->
callback error,response.body

getKey: (id='UNKNOWN')->
'=====TRAVIS_JOB_'+id+'_RESULT====='

stringify: (statuses,id)->
key= @getKey id
getKey: (travisJobId='UNKNOWN')->
'=====TRAVIS_JOB_'+travisJobId+'_RESULT====='
getPrefix: (travisJobId)->
prefix= ''
prefix+= 'travis_fold:start:widget\n'
prefix+= @getKey()+'\n'
prefix
getSuffix: (travisJobId)->
suffix= ''
suffix+= @getKey()+'\n'
suffix+= 'travis_fold:end:widget\n'
suffix

stringify: (statuses,travisJobId)->
data= ''

if id
widgetData= key+'\n'+(JSON.stringify statuses)+'\n'+key
if travisJobId
data+= @getPrefix travisJobId
data+= JSON.stringify statuses
data+= @getSuffix travisJobId
else
widgetData= JSON.stringify statuses,null,2
data= JSON.stringify statuses,null,2

data= ''
data+= 'travis_fold:start:widget\n' if @options.fold
data+= widgetData+'\n'
data+= 'travis_fold:end:widget\n' if @options.fold
data

widget: (id,callback)->
request travisLogUrl+id+'/log.txt',(error,response)->
widget: (travisJobId,callback)->
request travisLogUrl+travisJobId+'/log.txt',(error,response)->
callback error,response.body,response.headers

parse: (log,id)->
parse: (log,travisJobId)->
statuses= []

key= @getKey id
key= @getKey travisJobId

begin= log.indexOf key
begin+= key.length if begin > -1
Expand Down Expand Up @@ -73,7 +79,7 @@ class Parser
widget.svg.append widget.h1 browser,i
widget.svg.append widget.ul browser,i

if @options.standalone
if @datauri
images= widget.document('image')
for image in images
imagePath= path.join widget.themePath,image.attribs['xlink:href']
Expand Down
7 changes: 3 additions & 4 deletions test/specs/API.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Dependencies
soysauce= require '../../'
soysauce.options.fold= no
soysauce.options.standalone= no
Parser= require '../../src/parser'

fs= require 'fs'
Expand All @@ -24,10 +22,11 @@ describe 'API',->
expect(soysauce.constructor.__super__).toEqual parser.__proto__

it 'Create widget.json for zuul',->
key= soysauce.getKey TRAVIS_JOB_ID
prefix= soysauce.getPrefix TRAVIS_JOB_ID
suffix= soysauce.getSuffix TRAVIS_JOB_ID
log= soysauce.stringify fixture,TRAVIS_JOB_ID

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

it 'Fetch widget.json',(done)->
soysauce.report 59798,fixtureIds
Expand Down
2 changes: 0 additions & 2 deletions test/specs/middleware.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Dependencies
soysauce= require '../../'
soysauce.options.fold= no
soysauce.options.standalone= no

express= require 'express'
request= require 'request'
Expand Down
9 changes: 4 additions & 5 deletions test/specs/parser.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Dependencies
Parser= require '../../src/parser'
parser= new Parser
parser.options.fold= no
parser.options.standalone= no

path= require 'path'
fs= require 'fs'
Expand All @@ -21,13 +19,14 @@ describe 'Parser: Fetch SauceLabs Job statuses via TravisCI',->
it 'Write widget.json',->
log= parser.stringify fixture

expect(log).toBe (JSON.stringify fixture,null,2)+'\n'
expect(log).toBe JSON.stringify fixture,null,2

it 'Write widget.json for log.txt',->
key= parser.getKey TRAVIS_JOB_ID
prefix= parser.getPrefix TRAVIS_JOB_ID
suffix= parser.getSuffix TRAVIS_JOB_ID
log= parser.stringify fixture,TRAVIS_JOB_ID

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

it 'Fetch log.txt',(done)->
parser.widget TRAVIS_JOB_ID,(error,log)->
Expand Down
6 changes: 0 additions & 6 deletions test/specs/widget.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Dependencies
soysauce= require '../../'
soysauce.options.fold= no
soysauce.options.standalone= no

cheerio= require 'cheerio'

Expand All @@ -27,8 +25,6 @@ describe 'Widget: Browser matrix widget',->
svg= soysauce.render []
$= cheerio.load svg

# fs.writeFileSync fixturePath.replace(/.json$/,'.svg'),svg

expect($('text').text()).toBe 'Build unknown'

it 'Create standalone',->
Expand All @@ -39,7 +35,5 @@ describe 'Widget: Browser matrix widget',->
builds= $ 'g.li'
hrefs= $('image').map(->$(this).attr 'xlink:href').get().toString()

# fs.writeFileSync fixturePath.replace(/.json$/,'.svg'),svg

expect(builds.length).toBe fixture.length
expect(hrefs).not.toMatch 'http:\/\/'

0 comments on commit 23bbfe4

Please sign in to comment.