diff --git a/README.md b/README.md index 1dd69ca23..292cebe6c 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,36 @@ Dredd is a command-line tool for testing API documentation written in [API Bluep ## Get Started Testing Your API $ dredd blueprint.md http://api.myservice.tld - + ## Installation [Node.js][] and [NPM][] is required. $ npm install -g dredd -[Node.js]: https://npmjs.org/ +[Node.js]: https://npmjs.org/ [NPM]: https://npmjs.org/ + +## Command Line Options + + $ dredd -h + + Usage: + dredd [OPTIONS] + + Example: + dredd ./apiary.md http://localhost:3000 --dry-run + + Options: + -d, --dry-run Run without performing tests. + -s, --silent Suppress all command line output + -r, --reporter STRING Output additional report format. Options: junit + -o, --output FILE Specifies output file when using additional + reporter + -k, --no-color Omit color from output + --debug Show debug information + -v, --version Display the current version + -h, --help Display help and usage details + ## API Blueprint testability Dredd can test only API resources specified by *well defined transaction*. Any Non specific resources in the Blueprint e. g. with URI template or query parameters without default or example values are considered as *ambiguous transaction* thus they are resulting in a *warning* during the test run and are skipped. diff --git a/src/cli-reporter.coffee b/src/cli-reporter.coffee index e2e3e70e5..162dc56a7 100644 --- a/src/cli-reporter.coffee +++ b/src/cli-reporter.coffee @@ -15,8 +15,9 @@ class CliReporter extends Reporter logger.pass test.title when 'fail' logger.fail test.title - - logger.info test.message + logger.fail test.message + logger.expected "\n" + (JSON.stringify test.expected, null, 4) + "\n" + logger.actual "\n" + (JSON.stringify test.actual, null, 4) + "\n\n" return callback() @@ -25,13 +26,7 @@ class CliReporter extends Reporter return callback(error) if error if @stats.tests > 0 - logger.complete "Tests Complete\n" \ - + "tests: #{@stats.tests} \n" \ - + "failures: #{@stats.failures} \n" \ - + "errors: #{@stats.failures} \n" \ - + "skip: #{@stats.tests - @stats.failures - @stats.passes} \n" \ - + "timestamp: #{(new Date).toUTCString()} \n" \ - + "time: #{@stats.duration / 1000} \n" + logger.complete "#{@stats.passes} passing, #{@stats.failures} failing, #{@stats.tests - @stats.failures - @stats.passes} skipped" return callback() module.exports = CliReporter diff --git a/src/execute-transaction.coffee b/src/execute-transaction.coffee index 30b08dffe..e6dd1dc84 100644 --- a/src/execute-transaction.coffee +++ b/src/execute-transaction.coffee @@ -93,6 +93,11 @@ executeTransaction = (transaction, callback) -> status: "fail", title: options['method'] + ' ' + options['path'], message: message + actual: real + expected: expected + cli.debug "REAL: " + JSON.stringify real + cli.debug "EXPECTED: " + JSON.stringify expected + cli.debug "RESULT: " + JSON.stringify result configuration.reporter.addTest test, (error) -> return callback error if error return callback() diff --git a/src/logger.coffee b/src/logger.coffee index 8a1db6e44..e3bc4ef56 100644 --- a/src/logger.coffee +++ b/src/logger.coffee @@ -2,17 +2,24 @@ winston = require 'winston' config = levels: - test: 0, - info: 1, - pass: 2, - fail: 3, + test: 0 + info: 1 + pass: 2 + fail: 3 complete: 4 + actual: 5 + expected: 6 + diff: 7 colors: - test: 'yellow', - info: 'blue', - pass: 'green', - fail: 'red', + test: 'yellow' + info: 'blue' + pass: 'green' + fail: 'red' complete: 'green' + actual: 'red' + expected: 'red' + diff: 'red' + logger = new (winston.Logger) ({ transports: [ diff --git a/src/x-unit-reporter.coffee b/src/x-unit-reporter.coffee index 6673e49bc..d1a886e87 100644 --- a/src/x-unit-reporter.coffee +++ b/src/x-unit-reporter.coffee @@ -39,10 +39,11 @@ class XUnitReporter extends Reporter attrs = classname: test.title name: test.title - time: test.duration ? test.duration / 1000 : 0 if 'fail' is test.status attrs.message = test.message + attrs.expected = JSON.stringify test.expected + attrs.actual = JSON.stringify test.actual appendLine(path, toTag('testcase', attrs, false, toTag('failure', attrs, false, cdata(test.errorMessage)))) else appendLine(path, toTag('testcase', attrs, true) ) diff --git a/test/unit/cli-reporter-test.coffee b/test/unit/cli-reporter-test.coffee index eb14cdd4b..e99d43625 100644 --- a/test/unit/cli-reporter-test.coffee +++ b/test/unit/cli-reporter-test.coffee @@ -44,7 +44,7 @@ describe 'CliReporter', () -> it 'should write fail to the console', (done) -> cliReporter = new CliReporter() cliReporter.addTest test, ()-> - assert.ok loggerStub.fail.calledOnce + assert.ok loggerStub.fail.called done() diff --git a/test/unit/x-unit-reporter-test.coffee b/test/unit/x-unit-reporter-test.coffee index dde0312b8..8efe9bac4 100644 --- a/test/unit/x-unit-reporter-test.coffee +++ b/test/unit/x-unit-reporter-test.coffee @@ -16,7 +16,7 @@ describe 'XUnitReporter', () -> describe 'when creating report', () -> beforeEach () -> - sinon.spy fsStub, 'appendFileSync' + sinon.spy fsStub, 'appendFileSync' afterEach () -> fsStub.appendFileSync.restore() @@ -29,6 +29,7 @@ describe 'XUnitReporter', () -> xUnitReporter.addTest { status: 'pass', title: 'Passing Test' }, () -> xUnitReporter.createReport () -> assert.ok fsStub.appendFileSync.called + fsStub.unlinkSync(xUnitReporter.path) done() describe 'when there are no tests', () -> @@ -37,4 +38,5 @@ describe 'XUnitReporter', () -> xUnitReporter = new XUnitReporter() xUnitReporter.createReport () -> assert.ok fsStub.appendFileSync.calledTwice + fsStub.unlinkSync(xUnitReporter.path) done()