Commit Graph

9 Commits

Author SHA1 Message Date
Paul Melnikow
64e9d13e76 Disallow unused variables and turn on a few recommended rules 2017-04-12 23:55:13 +02:00
Paul Melnikow
5a45003bc3 Test server logic for img2svg error, and run the server in-process
Running the server in process is necessary for the mock to work. This is an approach I’ve taken in the past. I experimented with this setup quite a bit when I was playing around with a test suite, and it seemed to work well enough. Setting `process.argv` is a admitedly a bit gross, though a cleaner approach would require more involved changes to `server.js`.
2017-04-12 23:13:16 +02:00
Paul Melnikow
8b77d16a72 Always call the callback + reliable erroring
Fixes #914
2017-04-12 23:13:16 +02:00
Paul Melnikow
0760d17d82 Return data from svg2img via callback
Given the chunks coming from imagemagick are getting stored memory and
then tucked into a cache, this function could as easily return a buffer
via callback. Streaming is just making it more complex. (And trickier to
test!)
2017-04-12 23:13:16 +02:00
Paul Melnikow
ad1e419d42 Add tests for svgToImg 2017-04-12 23:13:16 +02:00
Thaddee Tyl
2d71e844a2 Store raster badges in the LRU cache
In ef1a5159, the switch to using imagemagick made a faulty use of the library by
listening for an 'end' event that is never raised. As a result, the cache was
never populated.

In d985f81f, a fix that takes care of the fact that the previously mentioned
dead code relies on a non-existent variable caused it to kill the server when a
raster badge is requested twice, as what it stored in the cache was the pipe
transmitting chunks, not the chunks themselves, and the pipe (a Socket object)
cannot be subsequently sent through a pipe. The following error occured instead:

    events.js:163
          throw er; // Unhandled 'error' event
          ^

    TypeError: Invalid non-string/buffer chunk
        at chunkInvalid (_stream_readable.js:395:10)
        at readableAddChunk (_stream_readable.js:150:12)
        at DataStream.Readable.push (_stream_readable.js:136:10)
        at DataStream._read (/home/m/shields/lib/svg-to-img.js:45:21)
        at DataStream.Readable.read (_stream_readable.js:350:10)
        at resume_ (_stream_readable.js:739:12)
        at _combinedTickCallback (internal/process/next_tick.js:80:11)
        at process._tickDomainCallback (internal/process/next_tick.js:128:9)
2017-04-12 23:13:16 +02:00
Thaddee Tyl
a0e6a6aeba Use new Buffer() instead of Buffer()
The following warning is emitted by Node.js:

> DeprecationWarning: Using Buffer without `new` will soon stop working. Use `new
> Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()` or
> `Buffer.alloc()` instead.

This patch removes this warning.
2017-03-29 18:28:48 -04:00
Paul Melnikow
d985f81f8e Disallow undefined variables 2017-03-29 20:09:30 +02:00
Thaddee Tyl
11b6e06f2f Organize local modules in lib 2017-03-26 22:57:55 +02:00