2020-02-19 06:15:25 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-19 06:15:08 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-19 06:15:37 -05:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
require('chai').should()
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../app/js/LatexRunner'
|
|
|
|
)
|
|
|
|
const Path = require('path')
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
describe('LatexRunner', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
let Timer
|
|
|
|
this.LatexRunner = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'settings-sharelatex': (this.Settings = {
|
|
|
|
docker: {
|
|
|
|
socketPath: '/var/run/docker.sock'
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
'logger-sharelatex': (this.logger = {
|
|
|
|
log: sinon.stub(),
|
|
|
|
error: sinon.stub()
|
|
|
|
}),
|
|
|
|
'./Metrics': {
|
|
|
|
Timer: (Timer = class Timer {
|
|
|
|
done() {}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
'./CommandRunner': (this.CommandRunner = {})
|
|
|
|
}
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
this.directory = '/local/compile/directory'
|
|
|
|
this.mainFile = 'main-file.tex'
|
|
|
|
this.compiler = 'pdflatex'
|
|
|
|
this.image = 'example.com/image'
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
this.project_id = 'project-id-123'
|
|
|
|
return (this.env = { foo: '123' })
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
return describe('runLatex', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return (this.CommandRunner.run = sinon.stub().callsArg(6))
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
describe('normally', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return this.LatexRunner.runLatex(
|
|
|
|
this.project_id,
|
|
|
|
{
|
|
|
|
directory: this.directory,
|
|
|
|
mainFile: this.mainFile,
|
|
|
|
compiler: this.compiler,
|
|
|
|
timeout: (this.timeout = 42000),
|
|
|
|
image: this.image,
|
|
|
|
environment: this.env
|
|
|
|
},
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
return it('should run the latex command', function() {
|
|
|
|
return this.CommandRunner.run
|
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
sinon.match.any,
|
|
|
|
this.directory,
|
|
|
|
this.image,
|
|
|
|
this.timeout,
|
|
|
|
this.env
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
describe('with an .Rtex main file', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return this.LatexRunner.runLatex(
|
|
|
|
this.project_id,
|
|
|
|
{
|
|
|
|
directory: this.directory,
|
|
|
|
mainFile: 'main-file.Rtex',
|
|
|
|
compiler: this.compiler,
|
|
|
|
image: this.image,
|
|
|
|
timeout: (this.timeout = 42000)
|
|
|
|
},
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
return it('should run the latex command on the equivalent .tex file', function() {
|
|
|
|
const command = this.CommandRunner.run.args[0][1]
|
|
|
|
const mainFile = command.slice(-1)[0]
|
|
|
|
return mainFile.should.equal('$COMPILE_DIR/main-file.tex')
|
|
|
|
})
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
return describe('with a flags option', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return this.LatexRunner.runLatex(
|
|
|
|
this.project_id,
|
|
|
|
{
|
|
|
|
directory: this.directory,
|
|
|
|
mainFile: this.mainFile,
|
|
|
|
compiler: this.compiler,
|
|
|
|
image: this.image,
|
|
|
|
timeout: (this.timeout = 42000),
|
|
|
|
flags: ['-file-line-error', '-halt-on-error']
|
|
|
|
},
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2019-05-10 11:51:40 -04:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
return it('should include the flags in the command', function() {
|
|
|
|
const command = this.CommandRunner.run.args[0][1]
|
|
|
|
const flags = command.filter(
|
|
|
|
arg => arg === '-file-line-error' || arg === '-halt-on-error'
|
|
|
|
)
|
|
|
|
flags.length.should.equal(2)
|
|
|
|
flags[0].should.equal('-file-line-error')
|
|
|
|
return flags[1].should.equal('-halt-on-error')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|