2014-02-14 11:39:05 -05:00
|
|
|
assert = require("chai").assert
|
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../app/js/ImageOptimiser.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "ImageOptimiser", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
2014-02-19 08:02:53 -05:00
|
|
|
@child_process =
|
|
|
|
exec : sinon.stub()
|
2019-01-07 10:54:24 -05:00
|
|
|
@settings =
|
|
|
|
enableConversions:true
|
2014-02-14 11:39:05 -05:00
|
|
|
@optimiser = SandboxedModule.require modulePath, requires:
|
2014-02-19 08:02:53 -05:00
|
|
|
'child_process': @child_process
|
2014-02-14 11:39:05 -05:00
|
|
|
"logger-sharelatex":
|
|
|
|
log:->
|
|
|
|
err:->
|
2017-06-21 10:18:36 -04:00
|
|
|
warn:->
|
2019-01-07 10:54:24 -05:00
|
|
|
"settings-sharelatex": @settings
|
|
|
|
|
2014-02-14 11:39:05 -05:00
|
|
|
|
|
|
|
@sourcePath = "/this/path/here.eps"
|
|
|
|
@error = "Error"
|
|
|
|
|
|
|
|
describe "compressPng", ->
|
|
|
|
|
|
|
|
|
2014-02-19 08:02:53 -05:00
|
|
|
it "convert the file", (done)->
|
|
|
|
@child_process.exec.callsArgWith(2)
|
2014-02-14 11:39:05 -05:00
|
|
|
@optimiser.compressPng @sourcePath, (err)=>
|
2014-02-19 08:02:53 -05:00
|
|
|
args = @child_process.exec.args[0][0]
|
|
|
|
args.should.equal "optipng #{@sourcePath}"
|
2014-02-14 11:39:05 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
|
2019-01-07 10:54:24 -05:00
|
|
|
it "should return the error", (done)->
|
2014-02-19 08:02:53 -05:00
|
|
|
@child_process.exec.callsArgWith(2, @error)
|
2014-02-14 11:39:05 -05:00
|
|
|
@optimiser.compressPng @sourcePath, (err)=>
|
2014-02-19 08:02:53 -05:00
|
|
|
err.should.equal @error
|
2017-06-21 10:18:36 -04:00
|
|
|
done()
|
|
|
|
|
2019-01-07 10:54:24 -05:00
|
|
|
describe 'when enableConversions is disabled', ->
|
|
|
|
|
|
|
|
it 'should produce an error', (done) ->
|
|
|
|
@settings.enableConversions = false
|
|
|
|
@child_process.exec.callsArgWith(2)
|
|
|
|
@optimiser.compressPng @sourcePath, (err)=>
|
|
|
|
@child_process.exec.called.should.equal false
|
|
|
|
expect(err).to.exist
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
describe 'when optimiser is sigkilled', ->
|
2017-06-21 10:18:36 -04:00
|
|
|
|
2019-01-07 10:54:24 -05:00
|
|
|
it 'should not produce an error', (done) ->
|
|
|
|
@error = new Error('woops')
|
|
|
|
@error.signal = 'SIGKILL'
|
|
|
|
@child_process.exec.callsArgWith(2, @error)
|
|
|
|
@optimiser.compressPng @sourcePath, (err)=>
|
|
|
|
expect(err).to.equal(null)
|
|
|
|
done()
|