Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to ignore tests. #443

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Options:
[default: false]
--only, -x Run only specified transaction name. Can
be used multiple times [default: []]
--ignore, -z Exclude specified transaction name. Can
be used multiple times [default: []]
--reporter, -r Output additional report format. This
option can be used multiple times to add
multiple reporters. Options: junit, nyan,
Expand Down
2 changes: 2 additions & 0 deletions src/apply-configuration.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ applyConfiguration = (config) ->
details: false
method: []
only: []
skip: []
color: true
level: 'info'
timestamp: false
Expand Down Expand Up @@ -70,6 +71,7 @@ applyConfiguration = (config) ->
configuration.options.header = coerceToArray(configuration.options.header)
configuration.options.method = coerceToArray(configuration.options.method)
configuration.options.only = coerceToArray(configuration.options.only)
configuration.options.skip = coerceToArray(configuration.options.skip)
configuration.options.path = coerceToArray(configuration.options.path)

# support for legacy JS API options
Expand Down
5 changes: 5 additions & 0 deletions src/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ options =
description: "Run only specified transaction name. Can be used multiple times"
default: []

skip:
alias: "z"
description: "Skip the specified transaction name. Can be used multiple times"
default: []

reporter:
alias: "r"
description: """Output additional report format. This option can be used \
Expand Down
16 changes: 12 additions & 4 deletions src/reporters/apiary-reporter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class ApiaryReporter
apiUrl: @_get 'apiaryApiUrl', 'APIARY_API_URL', 'https://api.apiary.io'
apiToken: @_get 'apiaryApiKey', 'APIARY_API_KEY', null
apiSuite: @_get 'apiaryApiName', 'APIARY_API_NAME', null
proxyHost: @_get 'proxyHost', 'PROXY_HOST', null
proxyPort: @_get 'proxyPort', 'PROXY_PORT', null
proxyProtocol: @_get 'proxyProtocol', 'PROXY_PROTOCOL', null

logger.info 'Using apiary reporter.'
if not @configuration.apiToken? and not @configuration.apiSuite?
Expand Down Expand Up @@ -228,16 +231,21 @@ class ApiaryReporter
return callback(undefined, res, parsedBody)

parsedUrl = url.parse @configuration['apiUrl']
hostToUse = @configuration['proxyHost'] || parsedUrl['hostname']
portToUse = @configuration['proxyPort'] || parsedUrl['port']
protocolToUse = @configuration['proxyProtocol'] || parsedUrl['protocol ']
pathToUse = @configuration['apiUrl'] + path
system = os.type() + ' ' + os.release() + '; ' + os.arch()

postData = JSON.stringify body

options =
host: parsedUrl['hostname']
port: parsedUrl['port']
path: path
host: hostToUse
port: portToUse
path: pathToUse
method: method
headers:
'Host': parsedUrl['hostname'],
'User-Agent': "Dredd REST Reporter/" + packageConfig['version'] + " (" + system + ")"
'Content-Type': 'application/json'
'Content-Length': Buffer.byteLength(postData, 'utf8')
Expand All @@ -258,7 +266,7 @@ class ApiaryReporter
else
return callback error, req, null

if @configuration.apiUrl?.indexOf('https') is 0
if protocolToUse?.indexOf('https') is 0
if @verbose
logger.log 'Starting REST Reporter HTTPS Request'
req = https.request options, handleResponse
Expand Down
4 changes: 4 additions & 0 deletions src/transaction-runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ class TransactionRunner
@configuration.emitter.emit 'test skip', test, () ->
transaction.skip = true
return callback()
else if @configuration.options.skip.length > 0 and (transaction.name in @configuration.options.skip)
@configuration.emitter.emit 'test skip', test, () ->
transaction.skip = true
return callback()
else
return @performRequestAndValidate(test, transaction, hooks, callback)

Expand Down
41 changes: 41 additions & 0 deletions test/integration/cli/cli-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,47 @@ describe 'CLI', () ->
it 'exit status should be 0', () ->
assert.equal exitStatus, 0

describe "when filtering transaction to particular name with -z or --skip", () ->

machineHit = false
messageHit = false
before (done) ->
cmd = "#{DREDD_BIN} ./test/fixtures/single-get.apib http://localhost:#{PORT} --path=./test/fixtures/multifile/*.apib --skip=\"Message API > /message > GET\" --no-color"

app = express()

app.get '/machines', (req, res) ->
machineHit = true
res.setHeader 'Content-Type', 'application/json; charset=utf-8'
machine =
type: 'bulldozer'
name: 'willy'
response = [machine]
res.status(200).send response

app.get '/message', (req, res) ->
messageHit = true
res.setHeader 'Content-Type', 'text/plain; charset=utf-8'
res.status(200).send "Hello World!\n"

server = app.listen PORT, () ->
execCommand cmd, () ->
server.close()

server.on 'close', done

it 'should not send the request', () ->
assert.isFalse messageHit

it 'should notify skipping to the stdout', () ->
assert.include stdout, 'skip: GET /message'

it 'should hit the only transaction', () ->
assert.isTrue machineHit

it 'exit status should be 0', () ->
assert.equal exitStatus, 0

describe 'when suppressing color with --no-color', () ->
before (done) ->
cmd = "#{DREDD_BIN} ./test/fixtures/single-get.apib http://localhost:#{PORT} --no-color"
Expand Down
2 changes: 2 additions & 0 deletions test/unit/config-utils-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ argvData =
names: false
n: false
only: []
skip: []
x: []
reporter: []
r: []
Expand Down Expand Up @@ -152,6 +153,7 @@ describe 'configUtils', () ->
custom: []
names: false
only: []
skip: []
reporter: []
output: []
header: []
Expand Down
1 change: 1 addition & 0 deletions test/unit/dredd-command-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ describe "DreddCommand class", () ->
custom: []
names: false
only: []
skip: []
reporter: []
output: []
header: []
Expand Down
34 changes: 34 additions & 0 deletions test/unit/transaction-runner-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe 'TransactionRunner', ()->
'dry-run': false
method: []
only: []
skip: []
header: []
reporter: []
transaction = {}
Expand Down Expand Up @@ -73,6 +74,7 @@ describe 'TransactionRunner', ()->
'dry-run': false
method: []
only: []
skip: []
header: []
reporter: []

Expand All @@ -91,6 +93,7 @@ describe 'TransactionRunner', ()->
'dry-run': false
method: []
only: []
skip: []
header: []
reporter: []
runner = new Runner(configuration)
Expand Down Expand Up @@ -327,6 +330,36 @@ describe 'TransactionRunner', ()->
assert.ok configuration.emitter.emit.calledWith 'test skip'
done()

describe 'when skipping certain names by the configuration', () ->

beforeEach () ->
server = nock('http://localhost:3000').
post('/machines', {"type":"bulldozer","name":"willy"}).
reply transaction['expected']['status'],
transaction['expected']['body'],
{'Content-Type': 'application/json'}

configuration.options['skip'] = ['Group Machine > Machine > Delete Message > Bogus example name']
sinon.stub configuration.emitter, 'emit'
runner = new Runner(configuration)

afterEach () ->
configuration.emitter.emit.restore()
configuration.options['skip'] = []
nock.cleanAll()

it 'should not skip transactions with different names', (done) ->
runner.executeTransaction transaction, () ->
assert.notOk configuration.emitter.emit.calledWith 'test skip'
done()

it 'should skip transactions with matching names', (done) ->
transaction['name'] = 'Group Machine > Machine > Delete Message > Bogus different example name'
runner.executeTransaction transaction, () ->
assert.ok configuration.emitter.emit.calledWith 'test skip'
done()


describe 'when a test has been manually set to skip in a hook', () ->
clonedTransaction = null

Expand Down Expand Up @@ -1100,6 +1133,7 @@ describe 'TransactionRunner', ()->
header: []
reporter: []
only: []
skip: []
# do not actually search & load hookfiles from disk
# hookfiles: './**/*_hooks.*'

Expand Down