Skip to content

Commit

Permalink
added support for decoding image fixtures as base64
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mann committed Jul 4, 2015
1 parent 91008f3 commit 8ce5967
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/fixtures.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ formatter = require("jsonlint/lib/formatter").formatter

fs = Promise.promisifyAll(fs)

extensions = ".json .js .coffee .html .txt".split(" ")
extensions = ".json .js .coffee .html .txt .png .jpg .jpeg .gif .tif .tiff".split(" ")

## TODO: add image conversion to base64

Expand Down Expand Up @@ -69,9 +69,10 @@ class Fixtures
when ".coffee" then @parseCoffee(p, fixture)
when ".html" then @parseHtml(p, fixture)
when ".txt" then @parseText(p, fixture)
when ".png", ".jpg", ".jpeg", ".gif", ".tif", ".tiff"
@parseImage(p, fixture)
else
## make sure to update the valid extensions
throw new Error("Invalid fixture extension: '#{ext}'. Acceptable file extensions are: [json, js, coffee, jpg, jpeg, png, gif, tiff]")
throw new Error("Invalid fixture extension: '#{ext}'. Acceptable file extensions are: #{extensions.join(", ")}")

parseJson: (p, fixture) ->
fs.readFileAsync(p, "utf8")
Expand Down Expand Up @@ -138,6 +139,10 @@ class Fixtures
fs.readFileAsync(p, "utf8")
.bind(@)

parseImage: (p, fixture) ->
fs.readFileAsync(p, "base64")
.bind(@)

copyExample: (fixturesDir) ->
src = path.join(process.cwd(), "lib", "scaffold", "example.json")
dest = path.join(fixturesDir, "example.json")
Expand Down
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions spec/server/unit/fixtures_spec.coffee

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/server/unit/socket_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe "Socket", ->
@socket.onFixture("invalid.exe", cb).then ->
obj = cb.getCall(0).args[0]
expect(obj).to.have.property("__error")
expect(obj.__error).to.eq "Invalid fixture extension: '.exe'. Acceptable file extensions are: [json, js, coffee, jpg, jpeg, png, gif, tiff]"
expect(obj.__error).to.eq "Invalid fixture extension: '.exe'. Acceptable file extensions are: .json, .js, .coffee, .html, .txt, .png, .jpg, .jpeg, .gif, .tif, .tiff"

context "#startListening", ->
beforeEach ->
Expand Down

0 comments on commit 8ce5967

Please sign in to comment.