Skip to content

Commit

Permalink
Merge pull request #3 from luckymarmot/paw-2.3.3
Browse files Browse the repository at this point in the history
Adapt to use the new import API
  • Loading branch information
mittsh committed Apr 2, 2016
2 parents 914d93e + fb05543 commit 8631500
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions HARImporter.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,60 @@
HARImporter = ->
@importString = (context, stringToImport) ->
har = JSON.parse(stringToImport)

@canImport = (context, items) ->
a = 0
b = 0
for item in items
a += @_canImportItem(context, item)
b += 1
return if b > 0 then a/b else 0

@_canImportItem = (context, item) ->
try
har = JSON.parse(item.content)
catch error
return 0
if not (har and har.log and har.log.entries)
return 0
if har.log.entries.length > 0 and not har.log.entries[0].request
return 0
if har.log.version == '1.2'
return 1
return 0.9

@import = (context, items, options) ->
order = options?.order or null
parent = options?.parent or null
for item in items
@_importStringToGroup(context, item.content, {
parent: parent,
order: order,
groupName: item.file?.name or 'HAR file'
})
order += 1
return true

@importString = (context, str) ->
return @_importStringToGroup(context, str)

@_importStringToGroup = (context, str, options={}) ->
try
har = JSON.parse(str)
catch e
throw new Error('Invalid JSON for HAR import')

# If the HAR was not valid JSON
unless har or har.log or har.log.entries
# To report an error, just throw a JavaScript Error
throw new Error('Invalid input format (see https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HAR/Overview.html)')

# Create a request group
group = context.createRequestGroup('HAR import')
group = context.createRequestGroup(options.groupName or 'HAR file')

# Set parent and order of group
if options.parent
options.parent.appendChild(group)
if options.order and options.order >= 0
group.order = options.order

for entry in har.log.entries
# Create a request
Expand Down

0 comments on commit 8631500

Please sign in to comment.