Skip to content

Commit

Permalink
Merge pull request #69 from apiaryio/netmilk/new-rest-reporter
Browse files Browse the repository at this point in the history
Netmilk/new rest reporter
  • Loading branch information
Adam Kliment committed Jun 11, 2014
2 parents dc86f2b + 553cd88 commit 210e7a8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dredd",
"version": "0.3.1",
"version": "0.3.2",
"description": "API Blueprint testing tool",
"main": "lib/dredd.js",
"bin": {
Expand Down
2 changes: 2 additions & 0 deletions src/configure-reporters.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ configureReporters = (config, stats, tests) ->
usedFileReportersLength = usedFileReporters.length
if reporters.indexOf('apiary') != -1
usedFileReportersLength = usedFileReportersLength - 1
if process.env['DREDD_REST_TOKEN'] == undefined or process.env['DREDD_REST_SUITE'] == undefined
logger.warn "Apiary reporter environment variable DREDD_REST_TOKEN or DREDD_REST_SUITE not defined."

if usedFileReportersLength > outputs.length
logger.warn "There are more reporters requiring output paths than there are output paths provided, using default paths for additional file-based reporters."
Expand Down
33 changes: 21 additions & 12 deletions src/reporters/apiary-reporter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ApiaryReporter
@configuration =
apiUrl: process.env['DREDD_REST_URL'] || "https://api.apiary.io"
apiToken: process.env['DREDD_REST_TOKEN'] || null
apiSuite: process.env['DREDD_REST_SUITE'] || "anonymous"
apiSuite: process.env['DREDD_REST_SUITE'] || null

logger.info 'Using apiary reporter.'

Expand All @@ -34,6 +34,19 @@ class ApiaryReporter
@uuid = uuid.v4()
@startedAt = Math.round(new Date().getTime() / 1000)

ciVars = [/^TRAVIS/, /^CIRCLE/, /^CI/, /^DRONE/]
envVarNames = Object.keys process.env
ciEnvVars = {}
for envVarName in envVarNames
ciEnvVar = false

for ciVar in ciVars
if envVarName.match(ciVar) != null
ciEnvVar = true

if ciEnvVar == true
ciEnvVars[envVarName] = process.env[envVarName]

data =
blueprint: rawBlueprint
agent: process.env['DREDD_AGENT'] || process.env['USER']
Expand All @@ -42,19 +55,13 @@ class ApiaryReporter
startedAt: @startedAt
public: true
status: 'running'
agentEnvironment:
ci: process.env['CI']?
name: process.env['CI_NAME']
buildId: process.env['CI_BUILD_ID']
buildNumber: process.env['CI_BUILD_NUMBER']
jobId: process.env['CI_JOB_ID']
jobNumber: process.env['CI_JOB_NUMBER']
agentEnvironment: ciEnvVars

path = '/apis/' + @configuration['apiSuite'] + '/tests/runs'

@_performRequest path, 'POST', data, (error, response, parsedBody) =>
if error
console.log error
logger.error error
callback()
else
@remoteId = parsedBody['_id']
Expand All @@ -65,25 +72,27 @@ class ApiaryReporter
path = '/apis/' + @configuration['apiSuite'] + '/tests/steps?testRunId=' + @remoteId
@_performRequest path, 'POST', data, (error, response, parsedBody) =>
if error
console.log error
logger.error error

emitter.on 'test fail', (test) =>
data = @_transformTestToReporter test
path = '/apis/' + @configuration['apiSuite'] + '/tests/steps?testRunId=' + @remoteId
@_performRequest path, 'POST', data, (error, response, parsedBody) =>
if error
console.log error
logger.error error

emitter.on 'end', (callback) =>
data =
endedAt: Math.round(new Date().getTime() / 1000)
result: @stats
status: if (@stats['failures'] > 0 or @stats['errors'] > 0) then 'failed' else 'passed'

path = '/apis/' + @configuration['apiSuite'] + '/tests/run/' + @remoteId

@_performRequest path, 'PATCH', data, (error, response, parsedBody) =>
if error
console.log error
logger.error error
logger.complete 'See results in Apiary at: https://app.apiary.io/' + @configuration.apiSuite + '/tests/run/' + @remoteId
callback()

_transformTestToReporter: (test) ->
Expand Down
19 changes: 10 additions & 9 deletions src/transaction-runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TransactionRunner
status: ''
title: transaction.id
message: transaction.name
origin: transaction.origin

if configuration.options.names
logger.info transaction.name
Expand Down Expand Up @@ -169,15 +170,15 @@ class TransactionRunner
for entity, data of result
for entityResult in data['results']
message += entity + ": " + entityResult['message'] + "\n"
test =
status: "fail",
title: transaction.id,
message: message
actual: real
expected: transaction.expected
request: transaction.request
start: test.start
results: result

test.status = "fail"
test.title = transaction.id
test.message = message
test.actual = real
test.expected = transaction.expected
test.request = transaction.request
test.start = test.start
test.results = result
configuration.emitter.emit 'test fail', test
return callback()

Expand Down

0 comments on commit 210e7a8

Please sign in to comment.