2020-02-19 06:15:25 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
chai-friendly/no-unused-expressions,
|
|
|
|
no-path-concat,
|
|
|
|
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:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* 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')
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../app/js/CompileManager'
|
|
|
|
)
|
|
|
|
const tk = require('timekeeper')
|
|
|
|
const { EventEmitter } = require('events')
|
|
|
|
const Path = require('path')
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('CompileManager', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.CompileManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'./LatexRunner': (this.LatexRunner = {}),
|
|
|
|
'./ResourceWriter': (this.ResourceWriter = {}),
|
|
|
|
'./OutputFileFinder': (this.OutputFileFinder = {}),
|
|
|
|
'./OutputCacheManager': (this.OutputCacheManager = {}),
|
2021-07-12 12:47:21 -04:00
|
|
|
'@overleaf/settings': (this.Settings = {
|
2020-02-19 06:15:37 -05:00
|
|
|
path: {
|
2020-12-16 10:14:18 -05:00
|
|
|
compilesDir: '/compiles/dir',
|
2021-07-13 07:04:48 -04:00
|
|
|
outputDir: '/output/dir',
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
|
|
|
synctexBaseDir() {
|
|
|
|
return '/compile'
|
|
|
|
},
|
|
|
|
clsi: {
|
|
|
|
docker: {
|
2021-07-13 07:04:48 -04:00
|
|
|
image: 'SOMEIMAGE',
|
|
|
|
},
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
}),
|
|
|
|
|
|
|
|
child_process: (this.child_process = {}),
|
|
|
|
'./CommandRunner': (this.CommandRunner = {}),
|
|
|
|
'./DraftModeManager': (this.DraftModeManager = {}),
|
|
|
|
'./TikzManager': (this.TikzManager = {}),
|
|
|
|
'./LockManager': (this.LockManager = {}),
|
|
|
|
fs: (this.fs = {}),
|
2021-07-13 07:04:48 -04:00
|
|
|
'fs-extra': (this.fse = { ensureDir: sinon.stub().callsArg(1) }),
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
this.project_id = 'project-id-123'
|
|
|
|
return (this.user_id = '1234')
|
|
|
|
})
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('doCompileWithLock', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.request = {
|
|
|
|
resources: (this.resources = 'mock-resources'),
|
|
|
|
project_id: this.project_id,
|
2021-07-13 07:04:48 -04:00
|
|
|
user_id: this.user_id,
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
|
|
|
this.output_files = ['foo', 'bar']
|
|
|
|
this.Settings.compileDir = 'compiles'
|
|
|
|
this.compileDir = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`
|
|
|
|
this.CompileManager.doCompile = sinon
|
|
|
|
.stub()
|
2021-05-13 09:07:54 -04:00
|
|
|
.yields(null, this.output_files)
|
2020-02-19 06:15:37 -05:00
|
|
|
return (this.LockManager.runWithLock = (lockFile, runner, callback) =>
|
|
|
|
runner((err, ...result) => callback(err, ...Array.from(result))))
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('when the project is not locked', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.CompileManager.doCompileWithLock(
|
|
|
|
this.request,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should ensure that the compile directory exists', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.fse.ensureDir.calledWith(this.compileDir).should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should call doCompile with the request', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.CompileManager.doCompile
|
|
|
|
.calledWith(this.request)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should call the callback with the output files', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback
|
|
|
|
.calledWithExactly(null, this.output_files)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('when the project is locked', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.error = new Error('locked')
|
|
|
|
this.LockManager.runWithLock = (lockFile, runner, callback) => {
|
|
|
|
return callback(this.error)
|
|
|
|
}
|
|
|
|
return this.CompileManager.doCompileWithLock(
|
|
|
|
this.request,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should ensure that the compile directory exists', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.fse.ensureDir.calledWith(this.compileDir).should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should not call doCompile with the request', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.CompileManager.doCompile.called.should.equal(false)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should call the callback with the error', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback.calledWithExactly(this.error).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('doCompile', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.output_files = [
|
|
|
|
{
|
|
|
|
path: 'output.log',
|
2021-07-13 07:04:48 -04:00
|
|
|
type: 'log',
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'output.pdf',
|
2021-07-13 07:04:48 -04:00
|
|
|
type: 'pdf',
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
]
|
|
|
|
this.build_files = [
|
|
|
|
{
|
|
|
|
path: 'output.log',
|
|
|
|
type: 'log',
|
2021-07-13 07:04:48 -04:00
|
|
|
build: 1234,
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'output.pdf',
|
|
|
|
type: 'pdf',
|
2021-07-13 07:04:48 -04:00
|
|
|
build: 1234,
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
]
|
|
|
|
this.request = {
|
|
|
|
resources: (this.resources = 'mock-resources'),
|
|
|
|
rootResourcePath: (this.rootResourcePath = 'main.tex'),
|
|
|
|
project_id: this.project_id,
|
|
|
|
user_id: this.user_id,
|
|
|
|
compiler: (this.compiler = 'pdflatex'),
|
|
|
|
timeout: (this.timeout = 42000),
|
|
|
|
imageName: (this.image = 'example.com/image'),
|
2020-06-11 11:01:44 -04:00
|
|
|
flags: (this.flags = ['-file-line-error']),
|
2021-07-13 07:04:48 -04:00
|
|
|
compileGroup: (this.compileGroup = 'compile-group'),
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
|
|
|
this.env = {}
|
|
|
|
this.Settings.compileDir = 'compiles'
|
|
|
|
this.compileDir = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`
|
2020-12-16 10:14:18 -05:00
|
|
|
this.outputDir = `${this.Settings.path.outputDir}/${this.project_id}-${this.user_id}`
|
2020-02-19 06:15:37 -05:00
|
|
|
this.ResourceWriter.syncResourcesToDisk = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, this.resources)
|
|
|
|
this.LatexRunner.runLatex = sinon.stub().callsArg(2)
|
|
|
|
this.OutputFileFinder.findOutputFiles = sinon
|
|
|
|
.stub()
|
2021-05-13 09:07:54 -04:00
|
|
|
.yields(null, this.output_files)
|
2020-02-19 06:15:37 -05:00
|
|
|
this.OutputCacheManager.saveOutputFiles = sinon
|
|
|
|
.stub()
|
2021-05-13 09:07:54 -04:00
|
|
|
.yields(null, this.build_files)
|
2020-02-19 06:15:37 -05:00
|
|
|
this.DraftModeManager.injectDraftMode = sinon.stub().callsArg(1)
|
|
|
|
return (this.TikzManager.checkMainFile = sinon.stub().callsArg(3, false))
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('normally', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.CompileManager.doCompile(this.request, this.callback)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should write the resources to disk', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.ResourceWriter.syncResourcesToDisk
|
|
|
|
.calledWith(this.request, this.compileDir)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should run LaTeX', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.LatexRunner.runLatex
|
|
|
|
.calledWith(`${this.project_id}-${this.user_id}`, {
|
|
|
|
directory: this.compileDir,
|
|
|
|
mainFile: this.rootResourcePath,
|
|
|
|
compiler: this.compiler,
|
|
|
|
timeout: this.timeout,
|
|
|
|
image: this.image,
|
|
|
|
flags: this.flags,
|
2020-06-11 11:01:44 -04:00
|
|
|
environment: this.env,
|
2021-07-13 07:04:48 -04:00
|
|
|
compileGroup: this.compileGroup,
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should find the output files', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.OutputFileFinder.findOutputFiles
|
|
|
|
.calledWith(this.resources, this.compileDir)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should return the output files', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, this.build_files)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should not inject draft mode by default', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.DraftModeManager.injectDraftMode.called.should.equal(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('with draft mode', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.request.draft = true
|
|
|
|
return this.CompileManager.doCompile(this.request, this.callback)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should inject the draft mode header', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.DraftModeManager.injectDraftMode
|
|
|
|
.calledWith(this.compileDir + '/' + this.rootResourcePath)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('with a check option', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.request.check = 'error'
|
|
|
|
return this.CompileManager.doCompile(this.request, this.callback)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should run chktex', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.LatexRunner.runLatex
|
|
|
|
.calledWith(`${this.project_id}-${this.user_id}`, {
|
|
|
|
directory: this.compileDir,
|
|
|
|
mainFile: this.rootResourcePath,
|
|
|
|
compiler: this.compiler,
|
|
|
|
timeout: this.timeout,
|
|
|
|
image: this.image,
|
|
|
|
flags: this.flags,
|
|
|
|
environment: {
|
|
|
|
CHKTEX_OPTIONS: '-nall -e9 -e10 -w15 -w16',
|
|
|
|
CHKTEX_EXIT_ON_ERROR: 1,
|
2021-07-13 07:04:48 -04:00
|
|
|
CHKTEX_ULIMIT_OPTIONS: '-t 5 -v 64000',
|
2020-06-11 11:01:44 -04:00
|
|
|
},
|
2021-07-13 07:04:48 -04:00
|
|
|
compileGroup: this.compileGroup,
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('with a knitr file and check options', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.request.rootResourcePath = 'main.Rtex'
|
|
|
|
this.request.check = 'error'
|
|
|
|
return this.CompileManager.doCompile(this.request, this.callback)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should not run chktex', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.LatexRunner.runLatex
|
|
|
|
.calledWith(`${this.project_id}-${this.user_id}`, {
|
|
|
|
directory: this.compileDir,
|
|
|
|
mainFile: 'main.Rtex',
|
|
|
|
compiler: this.compiler,
|
|
|
|
timeout: this.timeout,
|
|
|
|
image: this.image,
|
|
|
|
flags: this.flags,
|
2020-06-11 11:01:44 -04:00
|
|
|
environment: this.env,
|
2021-07-13 07:04:48 -04:00
|
|
|
compileGroup: this.compileGroup,
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('clearProject', function () {
|
|
|
|
describe('succesfully', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.Settings.compileDir = 'compiles'
|
|
|
|
this.fs.lstat = sinon.stub().callsArgWith(1, null, {
|
|
|
|
isDirectory() {
|
|
|
|
return true
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
this.proc = new EventEmitter()
|
|
|
|
this.proc.stdout = new EventEmitter()
|
|
|
|
this.proc.stderr = new EventEmitter()
|
2020-05-07 05:30:14 -04:00
|
|
|
this.proc.stderr.setEncoding = sinon.stub().returns(this.proc.stderr)
|
2020-02-19 06:15:37 -05:00
|
|
|
this.child_process.spawn = sinon.stub().returns(this.proc)
|
|
|
|
this.CompileManager.clearProject(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
return this.proc.emit('close', 0)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should remove the project directory', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.child_process.spawn
|
|
|
|
.calledWith('rm', [
|
|
|
|
'-r',
|
2020-12-16 10:14:18 -05:00
|
|
|
'-f',
|
|
|
|
'--',
|
|
|
|
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`,
|
2021-07-13 07:04:48 -04:00
|
|
|
`${this.Settings.path.outputDir}/${this.project_id}-${this.user_id}`,
|
2020-02-19 06:15:37 -05:00
|
|
|
])
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should call the callback', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback.called.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('with a non-success status code', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.Settings.compileDir = 'compiles'
|
|
|
|
this.fs.lstat = sinon.stub().callsArgWith(1, null, {
|
|
|
|
isDirectory() {
|
|
|
|
return true
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
this.proc = new EventEmitter()
|
|
|
|
this.proc.stdout = new EventEmitter()
|
|
|
|
this.proc.stderr = new EventEmitter()
|
2020-05-07 05:30:14 -04:00
|
|
|
this.proc.stderr.setEncoding = sinon.stub().returns(this.proc.stderr)
|
2020-02-19 06:15:37 -05:00
|
|
|
this.child_process.spawn = sinon.stub().returns(this.proc)
|
|
|
|
this.CompileManager.clearProject(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
this.proc.stderr.emit('data', (this.error = 'oops'))
|
|
|
|
return this.proc.emit('close', 1)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should remove the project directory', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.child_process.spawn
|
|
|
|
.calledWith('rm', [
|
|
|
|
'-r',
|
2020-12-16 10:14:18 -05:00
|
|
|
'-f',
|
|
|
|
'--',
|
|
|
|
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`,
|
2021-07-13 07:04:48 -04:00
|
|
|
`${this.Settings.path.outputDir}/${this.project_id}-${this.user_id}`,
|
2020-02-19 06:15:37 -05:00
|
|
|
])
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should call the callback with an error from the stderr', function () {
|
2020-03-12 05:35:11 -04:00
|
|
|
this.callback.calledWithExactly(sinon.match(Error)).should.equal(true)
|
2020-02-19 06:15:37 -05:00
|
|
|
|
2020-03-12 05:35:11 -04:00
|
|
|
this.callback.args[0][0].message.should.equal(
|
2020-12-16 10:14:18 -05:00
|
|
|
`rm -r ${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id} ${this.Settings.path.outputDir}/${this.project_id}-${this.user_id} failed: ${this.error}`
|
2020-02-19 06:15:37 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('syncing', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.page = 1
|
|
|
|
this.h = 42.23
|
|
|
|
this.v = 87.56
|
|
|
|
this.width = 100.01
|
|
|
|
this.height = 234.56
|
|
|
|
this.line = 5
|
|
|
|
this.column = 3
|
|
|
|
this.file_name = 'main.tex'
|
|
|
|
this.child_process.execFile = sinon.stub()
|
2021-07-13 07:04:48 -04:00
|
|
|
return (this.Settings.path.synctexBaseDir = project_id =>
|
2020-02-19 06:15:37 -05:00
|
|
|
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('syncFromCode', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.fs.stat = sinon.stub().callsArgWith(1, null, {
|
|
|
|
isFile() {
|
|
|
|
return true
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
this.stdout = `NODE\t${this.page}\t${this.h}\t${this.v}\t${this.width}\t${this.height}\n`
|
|
|
|
this.CommandRunner.run = sinon
|
|
|
|
.stub()
|
2021-03-30 08:22:11 -04:00
|
|
|
.yields(null, { stdout: this.stdout })
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.CompileManager.syncFromCode(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.file_name,
|
|
|
|
this.line,
|
|
|
|
this.column,
|
2021-03-30 08:22:11 -04:00
|
|
|
'',
|
2020-02-19 06:15:37 -05:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should execute the synctex binary', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
const bin_path = Path.resolve(__dirname + '/../../../bin/synctex')
|
|
|
|
const synctex_path = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}/output.pdf`
|
|
|
|
const file_path = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}/${this.file_name}`
|
|
|
|
return this.CommandRunner.run
|
|
|
|
.calledWith(
|
|
|
|
`${this.project_id}-${this.user_id}`,
|
|
|
|
[
|
|
|
|
'/opt/synctex',
|
|
|
|
'code',
|
|
|
|
synctex_path,
|
|
|
|
file_path,
|
|
|
|
this.line,
|
2021-07-13 07:04:48 -04:00
|
|
|
this.column,
|
2020-02-19 06:15:37 -05:00
|
|
|
],
|
|
|
|
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`,
|
|
|
|
this.Settings.clsi.docker.image,
|
|
|
|
60000,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-03-30 08:22:11 -04:00
|
|
|
it('should call the callback with the parsed output', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, [
|
|
|
|
{
|
|
|
|
page: this.page,
|
|
|
|
h: this.h,
|
|
|
|
v: this.v,
|
|
|
|
height: this.height,
|
2021-07-13 07:04:48 -04:00
|
|
|
width: this.width,
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
])
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2021-03-30 08:22:11 -04:00
|
|
|
|
|
|
|
describe('with a custom imageName', function () {
|
|
|
|
const customImageName = 'foo/bar:tag-0'
|
|
|
|
beforeEach(function () {
|
|
|
|
this.CommandRunner.run.reset()
|
|
|
|
this.CompileManager.syncFromCode(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.file_name,
|
|
|
|
this.line,
|
|
|
|
this.column,
|
|
|
|
customImageName,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should execute the synctex binary in a custom docker image', function () {
|
|
|
|
const synctex_path = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}/output.pdf`
|
|
|
|
const file_path = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}/${this.file_name}`
|
|
|
|
this.CommandRunner.run
|
|
|
|
.calledWith(
|
|
|
|
`${this.project_id}-${this.user_id}`,
|
|
|
|
[
|
|
|
|
'/opt/synctex',
|
|
|
|
'code',
|
|
|
|
synctex_path,
|
|
|
|
file_path,
|
|
|
|
this.line,
|
2021-07-13 07:04:48 -04:00
|
|
|
this.column,
|
2021-03-30 08:22:11 -04:00
|
|
|
],
|
|
|
|
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`,
|
|
|
|
customImageName,
|
|
|
|
60000,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('syncFromPdf', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.fs.stat = sinon.stub().callsArgWith(1, null, {
|
|
|
|
isFile() {
|
|
|
|
return true
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
this.stdout = `NODE\t${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}/${this.file_name}\t${this.line}\t${this.column}\n`
|
|
|
|
this.CommandRunner.run = sinon
|
|
|
|
.stub()
|
2020-06-11 11:01:44 -04:00
|
|
|
.callsArgWith(7, null, { stdout: this.stdout })
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.CompileManager.syncFromPdf(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.page,
|
|
|
|
this.h,
|
|
|
|
this.v,
|
2021-03-30 08:22:11 -04:00
|
|
|
'',
|
2020-02-19 06:15:37 -05:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should execute the synctex binary', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
const bin_path = Path.resolve(__dirname + '/../../../bin/synctex')
|
|
|
|
const synctex_path = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}/output.pdf`
|
|
|
|
return this.CommandRunner.run
|
|
|
|
.calledWith(
|
|
|
|
`${this.project_id}-${this.user_id}`,
|
|
|
|
['/opt/synctex', 'pdf', synctex_path, this.page, this.h, this.v],
|
|
|
|
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`,
|
|
|
|
this.Settings.clsi.docker.image,
|
|
|
|
60000,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-03-30 08:22:11 -04:00
|
|
|
it('should call the callback with the parsed output', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, [
|
|
|
|
{
|
|
|
|
file: this.file_name,
|
|
|
|
line: this.line,
|
2021-07-13 07:04:48 -04:00
|
|
|
column: this.column,
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
])
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2021-03-30 08:22:11 -04:00
|
|
|
|
|
|
|
describe('with a custom imageName', function () {
|
|
|
|
const customImageName = 'foo/bar:tag-1'
|
|
|
|
beforeEach(function () {
|
|
|
|
this.CommandRunner.run.reset()
|
|
|
|
this.CompileManager.syncFromPdf(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.page,
|
|
|
|
this.h,
|
|
|
|
this.v,
|
|
|
|
customImageName,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should execute the synctex binary in a custom docker image', function () {
|
|
|
|
const synctex_path = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}/output.pdf`
|
|
|
|
this.CommandRunner.run
|
|
|
|
.calledWith(
|
|
|
|
`${this.project_id}-${this.user_id}`,
|
|
|
|
['/opt/synctex', 'pdf', synctex_path, this.page, this.h, this.v],
|
|
|
|
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`,
|
|
|
|
customImageName,
|
|
|
|
60000,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('wordcount', function () {
|
|
|
|
beforeEach(function () {
|
2020-06-11 11:01:44 -04:00
|
|
|
this.CommandRunner.run = sinon.stub().callsArg(7)
|
2020-02-19 06:15:37 -05:00
|
|
|
this.fs.readFile = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
(this.stdout = 'Encoding: ascii\nWords in text: 2')
|
|
|
|
)
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
|
|
|
|
this.project_id
|
|
|
|
this.timeout = 60 * 1000
|
|
|
|
this.file_name = 'main.tex'
|
|
|
|
this.Settings.path.compilesDir = '/local/compile/directory'
|
|
|
|
this.image = 'example.com/image'
|
|
|
|
|
|
|
|
return this.CompileManager.wordcount(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.file_name,
|
|
|
|
this.image,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should run the texcount command', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.directory = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`
|
|
|
|
this.file_path = `$COMPILE_DIR/${this.file_name}`
|
|
|
|
this.command = [
|
|
|
|
'texcount',
|
|
|
|
'-nocol',
|
|
|
|
'-inc',
|
|
|
|
this.file_path,
|
2021-07-13 07:04:48 -04:00
|
|
|
`-out=${this.file_path}.wc`,
|
2020-02-19 06:15:37 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
return this.CommandRunner.run
|
|
|
|
.calledWith(
|
|
|
|
`${this.project_id}-${this.user_id}`,
|
|
|
|
this.command,
|
|
|
|
this.directory,
|
|
|
|
this.image,
|
|
|
|
this.timeout,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should call the callback with the parsed output', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, {
|
|
|
|
encode: 'ascii',
|
|
|
|
textWords: 2,
|
|
|
|
headWords: 0,
|
|
|
|
outside: 0,
|
|
|
|
headers: 0,
|
|
|
|
elements: 0,
|
|
|
|
mathInline: 0,
|
|
|
|
mathDisplay: 0,
|
|
|
|
errors: 0,
|
2021-07-13 07:04:48 -04:00
|
|
|
messages: '',
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|