Skip to content

Commit

Permalink
Merge pull request #195 from cybertk/0.5.0
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
galkin authored Nov 9, 2016
2 parents 565d7a8 + 76bd805 commit 2279bae
Show file tree
Hide file tree
Showing 24 changed files with 284 additions and 93 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,15 @@ Options:
[boolean]
--grep, -g Only run tests matching <pattern> [string]
--invert, -i Invert --grep matches [boolean]
--sorted Sorts requests in a sensible way so that objects are not
modified before they are created. Order: CONNECT, OPTIONS,
POST, GET, HEAD, PUT, PATCH, DELETE, TRACE. [boolean]
--timeout, -t Set test-case timeout in milliseconds
[number] [default: 2000]
--template Specify the template file to use for generating hooks
[string]
[string]
--names, -n List names of requests and exit [boolean]
--generate-hooks Output hooks generated from template file and exit [boolean]
--reporters Display available reporters and exit [boolean]
--help Show usage information and exit [boolean]
--version Show version number and exit [boolean]
Expand Down
2 changes: 1 addition & 1 deletion lib/abao.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Abao
if !config.options.server
if raml.baseUri
config.options.server = raml.baseUri
addTests raml, tests, hooks, callback, factory
addTests raml, tests, hooks, callback, factory, config.options.sorted
,
# Run tests
(callback) ->
Expand Down
53 changes: 48 additions & 5 deletions lib/add-tests.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
async = require 'async'
_ = require 'underscore'
_ = require 'lodash'
csonschema = require 'csonschema'


Expand All @@ -21,11 +21,11 @@ parseHeaders = (raml) ->

headers

# addTests(raml, tests, [parent], callback, config)
addTests = (raml, tests, hooks, parent, callback, testFactory) ->
addTests = (raml, tests, hooks, parent, callback, testFactory, sortFirst) ->

# Handle 4th optional param
if _.isFunction(parent)
sortFirst = testFactory
testFactory = callback
callback = parent
parent = null
Expand All @@ -41,7 +41,7 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) ->
# Apply parent properties
if parent
path = parent.path + path
params = _.clone parent.params
params = _.clone parent.params # shallow copy

# Setup param
if resource.uriParameters
Expand All @@ -52,6 +52,49 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) ->
# In case of issue #8, resource does not define methods
resource.methods ?= []

if sortFirst && resource.methods.length > 1
methodTests = [
method: 'CONNECT', tests: []
,
method: 'OPTIONS', tests: []
,
method: 'POST', tests: []
,
method: 'GET', tests: []
,
method: 'HEAD', tests: []
,
method: 'PUT', tests: []
,
method: 'PATCH', tests: []
,
method: 'DELETE', tests: []
,
method: 'TRACE', tests: []
]

# Group endpoint tests by method name
_.each methodTests, (methodTest) ->
isSameMethod = (test) ->
return methodTest.method == test.method.toUpperCase()

ans = _.partition resource.methods, isSameMethod
if ans[0].length != 0
_.each ans[0], (test) -> methodTest.tests.push test
resource.methods = ans[1]

# Shouldn't happen unless new HTTP method introduced...
leftovers = resource.methods
if leftovers.length > 1
console.error 'unknown method calls present!', leftovers

# Now put them back, but in order of methods listed above
sortedTests = _.map methodTests, (methodTest) -> return methodTest.tests
leftoverTests = _.map leftovers, (leftover) -> return leftover
reassembled = _.flattenDeep [_.reject sortedTests, _.isEmpty,
_.reject leftoverTests, _.isEmpty]
resource.methods = reassembled

# Iterate response method
async.each resource.methods, (api, callback) ->
method = api.method.toUpperCase()
Expand Down Expand Up @@ -108,7 +151,7 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) ->
return callback(err) if err

# Recursive
addTests resource, tests, hooks, {path, params}, callback, testFactory
addTests resource, tests, hooks, {path, params}, callback, testFactory, sortFirst
, callback


Expand Down
1 change: 1 addition & 0 deletions lib/apply-configuration.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ applyConfiguration = (config) ->
grep: ''
invert: false
'hooks-only': false
sorted: false

# Normalize options and config
for own key, value of config
Expand Down
6 changes: 6 additions & 0 deletions lib/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ options =
description: 'Invert --grep matches'
type: 'boolean'

sorted:
description: 'Sorts requests in a sensible way so that objects are not ' +
'modified before they are created.\nOrder: ' +
'CONNECT, OPTIONS, POST, GET, HEAD, PUT, PATCH, DELETE, TRACE.'
type: 'boolean'

timeout:
alias: 't'
description: 'Set test-case timeout in milliseconds'
Expand Down
3 changes: 1 addition & 2 deletions lib/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class TestFactory
if schemaLocation

files = glob.sync schemaLocation
console.error 'Found JSON ref schemas: ' + files
console.error ''
console.log '\tJSON ref schemas: ' + files.join(', ')

tv4.banUnknown = true

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "abao",
"version": "0.4.1",
"version": "0.5.0",
"description": "RAML testing tool",
"bin": "bin/abao",
"main": "lib/index.js",
Expand Down Expand Up @@ -60,6 +60,7 @@
"source-map-support": "^0.4.0",
"tv4": "^1.2.7",
"underscore": "^1.8.2",
"lodash": "^4.16.4",
"yargs": "~6.0.0"
}
}
10 changes: 5 additions & 5 deletions test/cli-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ execCommand = (cmd, callback) ->

describe 'Command line interface', ->

describe 'When run with "one and done" options', (done) ->
describe 'when run with "one and done" options', (done) ->

describe 'when RAML argument unnecessary', () ->

Expand Down Expand Up @@ -161,7 +161,7 @@ describe 'Command line interface', ->
assert.include stderr, 'template -> generate-hooks'


describe 'When RAML file not found', (done) ->
describe 'when RAML file not found', (done) ->
before (done) ->
ramlFile = "#{RAML_DIR}/nonexistent_path.raml"
cmd = "#{ABAO_BIN} #{ramlFile} --server #{SERVER}"
Expand All @@ -177,9 +177,9 @@ describe 'Command line interface', ->
assert.include stderr, 'Error: ENOENT'


describe 'Arguments with existing RAML and responding server', () ->
describe 'arguments with existing RAML and responding server', () ->
describe 'when invoked without "--server" option', () ->
describe 'when RAML file hasn\'t correct baseUri', () ->
describe 'when RAML file does not specify "baseUri"', () ->
before (done) ->
ramlFile = "#{RAML_DIR}/no-base-uri.raml"
cmd = "#{ABAO_BIN} #{ramlFile} --reporter json"
Expand All @@ -192,7 +192,7 @@ describe 'Command line interface', ->
it 'should print error message to stderr', ->
assert.include stderr, 'no API endpoint specified'

describe 'when RAML file has correct baseUri', () ->
describe 'when RAML file does specify "baseUri"', () ->

before (done) ->
ramlFile = "#{RAML_DIR}/single-get.raml"
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/1-get-1-post.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://example.api.com/{version}
version: v1

Expand Down Expand Up @@ -34,3 +34,4 @@ version: v1
name: 'string'
example: |
{ "type": "Kulu", "name": "Mike" }
63 changes: 63 additions & 0 deletions test/fixtures/contacts.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#%RAML 0.8

title: Address Book API
baseUri: http://example.api.com/{version}
version: v1

/contacts:
post:
body:
application/json:
schema: |
type: 'string'
name: 'string'
example: |
{ "type": "Kulu", "name": "Mike" }
responses:
201:
body:
application/json:
schema: |
type: 'string'
name: 'string'
example: |
{ "type": "Kulu", "name": "Mike" }
/contacts/{id}
delete:
responses:
204:
put:
body:
application/json:
schema: |
type: 'string'
name: 'string'
example: |
{ "type": "Kulu", "name": "Mike" }
responses:
201:
body:
application/json:
schema: |
type: 'string'
name: 'string'
example: |
{ "type": "Kulu", "name": "Mike" }
get:
responses:
200:
body:
application/json:
schema: |
[
type: 'string'
name: 'string'
phone: 'string'
]
example: |
{
"type": "contact",
"name": "Jenny",
"phone": "867-5309"
}
3 changes: 2 additions & 1 deletion test/fixtures/include_other_raml.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://example.api.com/{version}
version: v1

Expand All @@ -20,3 +20,4 @@ securitySchemes:
]
example: |
{ "type": "Kulu", "name": "Mike" }
3 changes: 2 additions & 1 deletion test/fixtures/inline_and_included_schemas.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://example.api.com/{version}
version: v1

Expand All @@ -23,3 +23,4 @@ schemas:
"name": "string"
}
}
1 change: 1 addition & 0 deletions test/fixtures/no-base-uri.raml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ traits:
delete:
description: |
This method will *delete* an **individual song**
3 changes: 2 additions & 1 deletion test/fixtures/no-method.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://example.api.com/{version}
version: v1

Expand All @@ -18,3 +18,4 @@ version: v1
]
example: |
{ "type": "Kulu", "name": "Mike" }
3 changes: 2 additions & 1 deletion test/fixtures/non_required_query_parameter.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://example.api.com/{version}
version: v1

Expand All @@ -22,3 +22,4 @@ version: v1
]
example: |
{ "type": "Kulu", "name": "Mike" }
3 changes: 2 additions & 1 deletion test/fixtures/ref_other_schemas.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://example.api.com/{version}
version: v1

Expand All @@ -15,3 +15,4 @@ schemas:
body:
application/json:
schema: type2

3 changes: 2 additions & 1 deletion test/fixtures/required_query_parameter.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://example.api.com/{version}
version: v1

Expand All @@ -22,3 +22,4 @@ version: v1
]
example: |
{ "type": "Kulu", "name": "Mike" }
1 change: 1 addition & 0 deletions test/fixtures/simple.raml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ traits:
delete:
description: |
This method will *delete* an **individual song**
3 changes: 2 additions & 1 deletion test/fixtures/single-get.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://localhost:3333

/machines:
Expand All @@ -20,3 +20,4 @@ baseUri: http://localhost:3333
]
example: |
{ "type": "Kulu", "name": "Mike" }
3 changes: 2 additions & 1 deletion test/fixtures/three-levels.raml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#%RAML 0.8

title: World Music API
title: Machines API
baseUri: http://example.api.com/{version}
version: v1

Expand Down Expand Up @@ -34,3 +34,4 @@ version: v1
schema: |
type: 'string'
name: 'string'
1 change: 1 addition & 0 deletions test/fixtures/vendor-content-type.raml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ version: v1
example: |
{ "title": "A Beautiful Day", "artist": "Mike" }
text/plain:

Loading

1 comment on commit 2279bae

@plroebuck
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nikita, I didn't communicate/document this, but I'd prefer to follow "normal" semantic versioning of releases. So from this aspect, we don't release versions with odd minor numbers. Concept would be to do all development in the "next up" odd minor release number, then release with an even minor release number. In this case, we would have added new features/bug fixes, tested them internally on the 0.5.x branch, and (when satisfied) merged into 0.6.0 branch for release. I think we should vote on when a new release is to occur, or at least give a drop-dead day with warning. I'll attempt to document the process as explained above soon, but please don't release stuff on a whim; I had updates which would have made this much more palatable for people merging our changes...

Please sign in to comment.