Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit ac4b98e

Browse files
author
Adam Kliment
committed
Merge pull request #59 from localmed/friendly-files
Better file handling for reporters (fixes #48 and #57)
2 parents cef670f + 781e9ce commit ac4b98e

7 files changed

+25
-27
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dredd",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "API Blueprint testing tool",
55
"main": "lib/dredd.js",
66
"bin": {
@@ -27,7 +27,8 @@
2727
"advisable": "~0.2.0",
2828
"proxyquire": "~0.5.1",
2929
"coffee-script": "1.6.3",
30-
"glob": "~3.2.8"
30+
"glob": "~3.2.8",
31+
"file": "~0.2.2"
3132
},
3233
"devDependencies": {
3334
"coffee-errors": "~0.8.4",

src/reporters/html-reporter.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
fs = require 'fs'
33

44
marked = require 'marked'
5+
file = require 'file'
56

67
logger = require './../logger'
78
prettifyResponse = require './../prettify-response'
@@ -29,10 +30,9 @@ class HtmlReporter extends EventEmitter
2930
@configureEmitter emitter
3031

3132
sanitizedPath: (path) =>
32-
filePath = if path? then process.cwd() + "/" + path else process.cwd() + "/report.html"
33+
filePath = if path? then file.path.abspath(path) else file.path.abspath("./report.html")
3334
if fs.existsSync(filePath)
34-
logger.info "File exists at #{filePath}, deleting..."
35-
fs.unlinkSync(filePath)
35+
logger.info "File exists at #{filePath}, will be overwritten..."
3636
filePath
3737

3838
configureEmitter: (emitter) =>

src/reporters/markdown-reporter.coffee

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{EventEmitter} = require 'events'
22
fs = require 'fs'
33

4+
file = require 'file'
5+
46
logger = require './../logger'
57
prettifyResponse = require './../prettify-response'
68

@@ -17,10 +19,9 @@ class MarkdownReporter extends EventEmitter
1719
@configureEmitter emitter
1820

1921
sanitizedPath: (path) =>
20-
filePath = if path? then process.cwd() + "/" + path else process.cwd() + "/report.md"
22+
filePath = if path? then file.path.abspath(path) else file.path.abspath("./report.md")
2123
if fs.existsSync(filePath)
22-
logger.info "File exists at #{filePath}, deleting..."
23-
fs.unlinkSync(filePath)
24+
logger.info "File exists at #{filePath}, will be overwritten..."
2425
filePath
2526

2627
configureEmitter: (emitter) =>

src/reporters/x-unit-reporter.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
fs = require 'fs'
33

44
htmlencode = require 'htmlencode'
5+
file = require 'file'
56

67
logger = require './../logger'
78
prettifyResponse = require './../prettify-response'
@@ -17,10 +18,9 @@ class XUnitReporter extends EventEmitter
1718
@configureEmitter emitter
1819

1920
sanitizedPath: (path) =>
20-
filePath = if path? then process.cwd() + "/" + path else process.cwd() + "/report.xml"
21+
filePath = if path? then file.path.abspath(path) else file.path.abspath("./report.xml")
2122
if fs.existsSync(filePath)
22-
logger.info "File exists at #{filePath}, deleting..."
23-
fs.unlinkSync(filePath)
23+
logger.info "File exists at #{filePath}, will be overwritten..."
2424
filePath
2525

2626
configureEmitter: (emitter) =>

test/unit/reporters/html-reporter-test.coffee

+4-5
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ describe 'HtmlReporter', () ->
4545
before () ->
4646
sinon.stub fsStub, 'existsSync', (path) ->
4747
return true
48-
sinon.stub fsStub, 'unlinkSync'
48+
sinon.stub loggerStub, 'info'
4949

5050
after () ->
5151
fsStub.existsSync.restore()
52-
fsStub.unlinkSync.restore()
52+
loggerStub.info.restore()
5353

54-
it 'should delete the existing file', () ->
55-
assert.ok fsStub.unlinkSync.called
54+
it 'should inform about the existing file', () ->
55+
assert.ok loggerStub.info.called
5656

5757
describe 'when file does not exist', () ->
5858

@@ -142,4 +142,3 @@ describe 'HtmlReporter', () ->
142142
emitter.emit 'test start', test
143143
emitter.emit 'test error', new Error('Error'), test
144144
assert.ok ~htmlReporter.buf.indexOf 'Error'
145-

test/unit/reporters/markdown-reporter-test.coffee

+4-7
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ describe 'MarkdownReporter', () ->
4646
before () ->
4747
sinon.stub fsStub, 'existsSync', (path) ->
4848
return true
49-
sinon.stub fsStub, 'unlinkSync'
49+
sinon.stub loggerStub, 'info'
5050

5151
after () ->
5252
fsStub.existsSync.restore()
53-
fsStub.unlinkSync.restore()
53+
loggerStub.info.restore()
5454

55-
it 'should delete the existing file', (done) ->
56-
assert.ok fsStub.unlinkSync.calledOnce
57-
done()
55+
it 'should inform about the existing file', () ->
56+
assert.ok loggerStub.info.called
5857

5958
describe 'when file does not exist', () ->
6059

@@ -149,5 +148,3 @@ describe 'MarkdownReporter', () ->
149148
it 'should write error to the buffer', (done) ->
150149
assert.ok ~mdReporter.buf.indexOf 'Error'
151150
done()
152-
153-

test/unit/reporters/x-unit-reporter-test.coffee

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ describe 'XUnitReporter', () ->
2727
before () ->
2828
sinon.stub fsStub, 'existsSync', (path) ->
2929
return true
30-
sinon.stub fsStub, 'unlinkSync'
30+
sinon.stub loggerStub, 'info'
3131

3232
after () ->
3333
fsStub.existsSync.restore()
34-
fsStub.unlinkSync.restore()
34+
loggerStub.info.restore()
3535

36-
it 'should delete the existing file', () ->
36+
it 'should inform about the existing file', () ->
3737
emitter = new EventEmitter()
3838
xUnitReporter = new XUnitReporter(emitter, {}, {}, "test.xml")
39-
assert.ok fsStub.unlinkSync.calledOnce
39+
assert.ok loggerStub.info.called
4040

4141
describe 'when file does not exist', () ->
4242

0 commit comments

Comments
 (0)