2022-07-18 10:11:30 -04:00
|
|
|
const Path = require('path')
|
2020-02-19 06:15:37 -05:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
2022-07-07 08:27:20 -04:00
|
|
|
const { expect } = require('chai')
|
2020-02-19 06:15:37 -05:00
|
|
|
const sinon = require('sinon')
|
2022-07-07 08:27:20 -04:00
|
|
|
|
|
|
|
const MODULE_PATH = require('path').join(
|
2020-02-19 06:15:37 -05:00
|
|
|
__dirname,
|
|
|
|
'../../../app/js/CompileManager'
|
|
|
|
)
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('CompileManager', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-30 07:56:13 -04:00
|
|
|
this.projectId = 'project-id-123'
|
|
|
|
this.userId = '1234'
|
|
|
|
this.resources = 'mock-resources'
|
|
|
|
this.outputFiles = [
|
|
|
|
{
|
|
|
|
path: 'output.log',
|
|
|
|
type: 'log',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'output.pdf',
|
|
|
|
type: 'pdf',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
this.buildFiles = [
|
|
|
|
{
|
|
|
|
path: 'output.log',
|
|
|
|
type: 'log',
|
|
|
|
build: 1234,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'output.pdf',
|
|
|
|
type: 'pdf',
|
|
|
|
build: 1234,
|
|
|
|
},
|
|
|
|
]
|
2024-05-24 05:38:12 -04:00
|
|
|
this.buildId = 'build-id-123'
|
2021-09-07 08:57:47 -04:00
|
|
|
this.commandOutput = 'Dummy output'
|
|
|
|
this.compileBaseDir = '/compile/dir'
|
|
|
|
this.outputBaseDir = '/output/dir'
|
|
|
|
this.compileDir = `${this.compileBaseDir}/${this.projectId}-${this.userId}`
|
|
|
|
this.outputDir = `${this.outputBaseDir}/${this.projectId}-${this.userId}`
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
this.LatexRunner = {
|
2022-07-07 08:27:20 -04:00
|
|
|
promises: {
|
|
|
|
runLatex: sinon.stub().resolves({}),
|
|
|
|
},
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
|
|
|
this.ResourceWriter = {
|
2022-07-07 08:27:20 -04:00
|
|
|
promises: {
|
|
|
|
syncResourcesToDisk: sinon.stub().resolves(this.resources),
|
|
|
|
},
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
|
|
|
this.OutputFileFinder = {
|
2022-07-07 08:27:20 -04:00
|
|
|
promises: {
|
2024-01-10 07:02:06 -05:00
|
|
|
findOutputFiles: sinon.stub().resolves({
|
|
|
|
outputFiles: this.outputFiles,
|
|
|
|
allEntries: this.outputFiles.map(f => f.path).concat(['main.tex']),
|
|
|
|
}),
|
2022-07-07 08:27:20 -04:00
|
|
|
},
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
|
|
|
this.OutputCacheManager = {
|
2022-07-07 08:27:20 -04:00
|
|
|
promises: {
|
2024-05-24 05:38:12 -04:00
|
|
|
saveOutputFiles: sinon
|
|
|
|
.stub()
|
|
|
|
.resolves({ outputFiles: this.buildFiles, buildId: this.buildId }),
|
2022-07-07 08:27:20 -04:00
|
|
|
},
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
|
|
|
this.Settings = {
|
|
|
|
path: {
|
2021-09-07 08:57:47 -04:00
|
|
|
compilesDir: this.compileBaseDir,
|
|
|
|
outputDir: this.outputBaseDir,
|
|
|
|
synctexBaseDir: sinon.stub(),
|
2021-08-30 07:56:13 -04:00
|
|
|
},
|
|
|
|
clsi: {
|
|
|
|
docker: {
|
|
|
|
image: 'SOMEIMAGE',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-09-07 08:57:47 -04:00
|
|
|
this.Settings.path.synctexBaseDir
|
|
|
|
.withArgs(`${this.projectId}-${this.userId}`)
|
|
|
|
.returns(this.compileDir)
|
2021-08-30 07:56:13 -04:00
|
|
|
this.child_process = {
|
|
|
|
exec: sinon.stub(),
|
2022-07-07 08:27:20 -04:00
|
|
|
execFile: sinon.stub().yields(),
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
|
|
|
this.CommandRunner = {
|
2022-07-07 08:27:20 -04:00
|
|
|
promises: {
|
2024-02-02 04:35:32 -05:00
|
|
|
run: sinon.stub().callsFake((_1, _2, _3, _4, _5, _6, compileGroup) => {
|
|
|
|
if (compileGroup === 'synctex') {
|
|
|
|
return Promise.resolve({ stdout: this.commandOutput })
|
|
|
|
} else {
|
|
|
|
return Promise.resolve({
|
|
|
|
stdout: 'Encoding: ascii\nWords in text: 2',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}),
|
2022-07-07 08:27:20 -04:00
|
|
|
},
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
|
|
|
this.DraftModeManager = {
|
2022-07-07 08:27:20 -04:00
|
|
|
promises: {
|
|
|
|
injectDraftMode: sinon.stub().resolves(),
|
|
|
|
},
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
|
|
|
this.TikzManager = {
|
2022-07-07 08:27:20 -04:00
|
|
|
promises: {
|
|
|
|
checkMainFile: sinon.stub().resolves(false),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
this.lock = {
|
2024-01-11 03:13:11 -05:00
|
|
|
release: sinon.stub(),
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
|
|
|
this.LockManager = {
|
2024-01-11 03:13:11 -05:00
|
|
|
acquire: sinon.stub().returns(this.lock),
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
2021-09-07 08:57:47 -04:00
|
|
|
this.SynctexOutputParser = {
|
|
|
|
parseViewOutput: sinon.stub(),
|
|
|
|
parseEditOutput: sinon.stub(),
|
|
|
|
}
|
|
|
|
|
2022-07-18 10:11:30 -04:00
|
|
|
this.dirStats = {
|
|
|
|
isDirectory: sinon.stub().returns(true),
|
|
|
|
}
|
|
|
|
this.fileStats = {
|
|
|
|
isFile: sinon.stub().returns(true),
|
|
|
|
}
|
2022-07-07 08:27:20 -04:00
|
|
|
this.fsPromises = {
|
2021-08-30 07:56:13 -04:00
|
|
|
lstat: sinon.stub(),
|
|
|
|
stat: sinon.stub(),
|
|
|
|
readFile: sinon.stub(),
|
2024-01-08 05:43:41 -05:00
|
|
|
mkdir: sinon.stub().resolves(),
|
2024-01-10 07:02:06 -05:00
|
|
|
rm: sinon.stub().resolves(),
|
|
|
|
unlink: sinon.stub().resolves(),
|
|
|
|
rmdir: sinon.stub().resolves(),
|
2021-08-30 07:56:13 -04:00
|
|
|
}
|
2022-07-18 10:11:30 -04:00
|
|
|
this.fsPromises.lstat.withArgs(this.compileDir).resolves(this.dirStats)
|
|
|
|
this.fsPromises.stat
|
|
|
|
.withArgs(Path.join(this.compileDir, 'output.synctex.gz'))
|
|
|
|
.resolves(this.fileStats)
|
2021-08-30 07:56:13 -04:00
|
|
|
|
2022-07-07 08:27:20 -04:00
|
|
|
this.CompileManager = SandboxedModule.require(MODULE_PATH, {
|
2020-02-19 06:15:37 -05:00
|
|
|
requires: {
|
2021-08-30 07:56:13 -04:00
|
|
|
'./LatexRunner': this.LatexRunner,
|
|
|
|
'./ResourceWriter': this.ResourceWriter,
|
|
|
|
'./OutputFileFinder': this.OutputFileFinder,
|
|
|
|
'./OutputCacheManager': this.OutputCacheManager,
|
|
|
|
'@overleaf/settings': this.Settings,
|
2023-05-23 04:10:44 -04:00
|
|
|
'@overleaf/metrics': {
|
|
|
|
inc: sinon.stub(),
|
|
|
|
timing: sinon.stub(),
|
|
|
|
gauge: sinon.stub(),
|
|
|
|
Timer: sinon.stub().returns({ done: sinon.stub() }),
|
|
|
|
},
|
2021-08-30 07:56:13 -04:00
|
|
|
child_process: this.child_process,
|
|
|
|
'./CommandRunner': this.CommandRunner,
|
|
|
|
'./DraftModeManager': this.DraftModeManager,
|
|
|
|
'./TikzManager': this.TikzManager,
|
|
|
|
'./LockManager': this.LockManager,
|
2021-09-07 08:57:47 -04:00
|
|
|
'./SynctexOutputParser': this.SynctexOutputParser,
|
2022-07-07 08:27:20 -04:00
|
|
|
'fs/promises': this.fsPromises,
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
2021-08-30 07:56:13 -04:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('doCompileWithLock', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.request = {
|
2021-08-30 07:56:13 -04:00
|
|
|
resources: this.resources,
|
|
|
|
rootResourcePath: (this.rootResourcePath = 'main.tex'),
|
|
|
|
project_id: this.projectId,
|
|
|
|
user_id: this.userId,
|
|
|
|
compiler: (this.compiler = 'pdflatex'),
|
|
|
|
timeout: (this.timeout = 42000),
|
|
|
|
imageName: (this.image = 'example.com/image'),
|
|
|
|
flags: (this.flags = ['-file-line-error']),
|
|
|
|
compileGroup: (this.compileGroup = 'compile-group'),
|
2022-06-06 07:41:36 -04:00
|
|
|
stopOnFirstError: false,
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
2024-04-11 06:49:47 -04:00
|
|
|
this.env = {
|
|
|
|
OVERLEAF_PROJECT_ID: this.projectId,
|
|
|
|
}
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
describe('when the project is locked', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
beforeEach(async function () {
|
|
|
|
const error = new Error('locked')
|
2024-01-11 03:13:11 -05:00
|
|
|
this.LockManager.acquire.throws(error)
|
2022-07-07 08:27:20 -04:00
|
|
|
await expect(
|
|
|
|
this.CompileManager.promises.doCompileWithLock(this.request)
|
|
|
|
).to.be.rejectedWith(error)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should ensure that the compile directory exists', function () {
|
2024-01-08 05:43:41 -05:00
|
|
|
expect(this.fsPromises.mkdir).to.have.been.calledWith(this.compileDir, {
|
|
|
|
recursive: true,
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
it('should not run LaTeX', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.LatexRunner.promises.runLatex).not.to.have.been.called
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
describe('normally', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
beforeEach(async function () {
|
|
|
|
this.result = await this.CompileManager.promises.doCompileWithLock(
|
|
|
|
this.request
|
|
|
|
)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should ensure that the compile directory exists', function () {
|
2024-01-08 05:43:41 -05:00
|
|
|
expect(this.fsPromises.mkdir).to.have.been.calledWith(this.compileDir, {
|
|
|
|
recursive: true,
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should write the resources to disk', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(
|
|
|
|
this.ResourceWriter.promises.syncResourcesToDisk
|
|
|
|
).to.have.been.calledWith(this.request, this.compileDir)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should run LaTeX', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.LatexRunner.promises.runLatex).to.have.been.calledWith(
|
|
|
|
`${this.projectId}-${this.userId}`,
|
|
|
|
{
|
2020-02-19 06:15:37 -05:00
|
|
|
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,
|
2022-06-06 07:41:36 -04:00
|
|
|
stopOnFirstError: this.request.stopOnFirstError,
|
2022-07-18 10:11:30 -04:00
|
|
|
stats: sinon.match.object,
|
|
|
|
timings: sinon.match.object,
|
2022-07-07 08:27:20 -04:00
|
|
|
}
|
|
|
|
)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should find the output files', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(
|
|
|
|
this.OutputFileFinder.promises.findOutputFiles
|
|
|
|
).to.have.been.calledWith(this.resources, this.compileDir)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should return the output files', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.result.outputFiles).to.equal(this.buildFiles)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
it('should not inject draft mode by default', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.DraftModeManager.promises.injectDraftMode).not.to.have.been
|
|
|
|
.called
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('with draft mode', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
beforeEach(async function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.request.draft = true
|
2022-07-07 08:27:20 -04:00
|
|
|
await this.CompileManager.promises.doCompileWithLock(this.request)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
it('should inject the draft mode header', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(
|
|
|
|
this.DraftModeManager.promises.injectDraftMode
|
|
|
|
).to.have.been.calledWith(this.compileDir + '/' + this.rootResourcePath)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('with a check option', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
beforeEach(async function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.request.check = 'error'
|
2022-07-07 08:27:20 -04:00
|
|
|
await this.CompileManager.promises.doCompileWithLock(this.request)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
it('should run chktex', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.LatexRunner.promises.runLatex).to.have.been.calledWith(
|
|
|
|
`${this.projectId}-${this.userId}`,
|
|
|
|
{
|
2020-02-19 06:15:37 -05:00
|
|
|
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',
|
2024-04-11 06:49:47 -04:00
|
|
|
OVERLEAF_PROJECT_ID: this.projectId,
|
2020-06-11 11:01:44 -04:00
|
|
|
},
|
2021-07-13 07:04:48 -04:00
|
|
|
compileGroup: this.compileGroup,
|
2022-06-06 07:41:36 -04:00
|
|
|
stopOnFirstError: this.request.stopOnFirstError,
|
2022-07-18 10:11:30 -04:00
|
|
|
stats: sinon.match.object,
|
|
|
|
timings: sinon.match.object,
|
2022-07-07 08:27:20 -04:00
|
|
|
}
|
|
|
|
)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
describe('with a knitr file and check options', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
beforeEach(async function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.request.rootResourcePath = 'main.Rtex'
|
|
|
|
this.request.check = 'error'
|
2022-07-07 08:27:20 -04:00
|
|
|
await this.CompileManager.promises.doCompileWithLock(this.request)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
it('should not run chktex', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.LatexRunner.promises.runLatex).to.have.been.calledWith(
|
|
|
|
`${this.projectId}-${this.userId}`,
|
|
|
|
{
|
2020-02-19 06:15:37 -05:00
|
|
|
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,
|
2022-06-06 07:41:36 -04:00
|
|
|
stopOnFirstError: this.request.stopOnFirstError,
|
2022-07-18 10:11:30 -04:00
|
|
|
stats: sinon.match.object,
|
|
|
|
timings: sinon.match.object,
|
2022-07-07 08:27:20 -04:00
|
|
|
}
|
|
|
|
)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
2022-07-18 10:11:30 -04:00
|
|
|
|
|
|
|
describe('when the compile times out', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
const error = new Error('timed out!')
|
|
|
|
error.timedout = true
|
|
|
|
this.LatexRunner.promises.runLatex.rejects(error)
|
|
|
|
await expect(
|
|
|
|
this.CompileManager.promises.doCompileWithLock(this.request)
|
|
|
|
).to.be.rejected
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should clear the compile directory', function () {
|
2024-01-10 07:02:06 -05:00
|
|
|
for (const { path } of this.buildFiles) {
|
|
|
|
expect(this.fsPromises.unlink).to.have.been.calledWith(
|
|
|
|
this.compileDir + '/' + path
|
|
|
|
)
|
|
|
|
}
|
|
|
|
expect(this.fsPromises.unlink).to.have.been.calledWith(
|
|
|
|
this.compileDir + '/main.tex'
|
|
|
|
)
|
|
|
|
expect(this.fsPromises.rmdir).to.have.been.calledWith(this.compileDir)
|
2022-07-18 10:11:30 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the compile is manually stopped', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
const error = new Error('terminated!')
|
|
|
|
error.terminated = true
|
|
|
|
this.LatexRunner.promises.runLatex.rejects(error)
|
|
|
|
await expect(
|
|
|
|
this.CompileManager.promises.doCompileWithLock(this.request)
|
|
|
|
).to.be.rejected
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should clear the compile directory', function () {
|
2024-01-10 07:02:06 -05:00
|
|
|
for (const { path } of this.buildFiles) {
|
|
|
|
expect(this.fsPromises.unlink).to.have.been.calledWith(
|
|
|
|
this.compileDir + '/' + path
|
|
|
|
)
|
|
|
|
}
|
|
|
|
expect(this.fsPromises.unlink).to.have.been.calledWith(
|
|
|
|
this.compileDir + '/main.tex'
|
|
|
|
)
|
|
|
|
expect(this.fsPromises.rmdir).to.have.been.calledWith(this.compileDir)
|
2022-07-18 10:11:30 -04:00
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('clearProject', function () {
|
2024-01-10 07:02:06 -05:00
|
|
|
it('should clear the compile directory', async function () {
|
|
|
|
await this.CompileManager.promises.clearProject(
|
|
|
|
this.projectId,
|
|
|
|
this.userId
|
|
|
|
)
|
2020-02-19 06:15:37 -05:00
|
|
|
|
2024-01-10 07:02:06 -05:00
|
|
|
expect(this.fsPromises.rm).to.have.been.calledWith(this.compileDir, {
|
|
|
|
force: true,
|
|
|
|
recursive: true,
|
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
|
2021-09-07 08:57:47 -04:00
|
|
|
this.filename = 'main.tex'
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('syncFromCode', function () {
|
|
|
|
beforeEach(function () {
|
2021-09-07 08:57:47 -04:00
|
|
|
this.records = [{ page: 1, h: 2, v: 3, width: 4, height: 5 }]
|
|
|
|
this.SynctexOutputParser.parseViewOutput
|
|
|
|
.withArgs(this.commandOutput)
|
|
|
|
.returns(this.records)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2022-07-07 08:27:20 -04:00
|
|
|
describe('normal case', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
this.result = await this.CompileManager.promises.syncFromCode(
|
|
|
|
this.projectId,
|
|
|
|
this.userId,
|
|
|
|
this.filename,
|
|
|
|
this.line,
|
|
|
|
this.column,
|
|
|
|
''
|
|
|
|
)
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
|
2022-07-07 08:27:20 -04:00
|
|
|
it('should execute the synctex binary', function () {
|
|
|
|
const outputFilePath = `${this.compileDir}/output.pdf`
|
|
|
|
const inputFilePath = `${this.compileDir}/${this.filename}`
|
|
|
|
expect(this.CommandRunner.promises.run).to.have.been.calledWith(
|
|
|
|
`${this.projectId}-${this.userId}`,
|
|
|
|
[
|
|
|
|
'synctex',
|
|
|
|
'view',
|
|
|
|
'-i',
|
|
|
|
`${this.line}:${this.column}:${inputFilePath}`,
|
|
|
|
'-o',
|
|
|
|
outputFilePath,
|
|
|
|
],
|
|
|
|
this.compileDir,
|
|
|
|
this.Settings.clsi.docker.image,
|
|
|
|
60000,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the parsed output', function () {
|
|
|
|
expect(this.result).to.deep.equal(this.records)
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2021-03-30 08:22:11 -04:00
|
|
|
|
|
|
|
describe('with a custom imageName', function () {
|
|
|
|
const customImageName = 'foo/bar:tag-0'
|
2022-07-07 08:27:20 -04:00
|
|
|
beforeEach(async function () {
|
|
|
|
await this.CompileManager.promises.syncFromCode(
|
2021-08-30 07:56:13 -04:00
|
|
|
this.projectId,
|
|
|
|
this.userId,
|
2021-09-07 08:57:47 -04:00
|
|
|
this.filename,
|
2021-03-30 08:22:11 -04:00
|
|
|
this.line,
|
|
|
|
this.column,
|
2022-07-07 08:27:20 -04:00
|
|
|
customImageName
|
2021-03-30 08:22:11 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should execute the synctex binary in a custom docker image', function () {
|
2021-09-07 08:57:47 -04:00
|
|
|
const outputFilePath = `${this.compileDir}/output.pdf`
|
|
|
|
const inputFilePath = `${this.compileDir}/${this.filename}`
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.CommandRunner.promises.run).to.have.been.calledWith(
|
2021-09-07 08:57:47 -04:00
|
|
|
`${this.projectId}-${this.userId}`,
|
|
|
|
[
|
|
|
|
'synctex',
|
|
|
|
'view',
|
|
|
|
'-i',
|
|
|
|
`${this.line}:${this.column}:${inputFilePath}`,
|
|
|
|
'-o',
|
|
|
|
outputFilePath,
|
|
|
|
],
|
|
|
|
this.compileDir,
|
|
|
|
customImageName,
|
|
|
|
60000,
|
|
|
|
{}
|
|
|
|
)
|
2021-03-30 08:22:11 -04:00
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
describe('syncFromPdf', function () {
|
2020-08-10 12:01:11 -04:00
|
|
|
beforeEach(function () {
|
2021-09-07 08:57:47 -04:00
|
|
|
this.records = [{ file: 'main.tex', line: 1, column: 1 }]
|
|
|
|
this.SynctexOutputParser.parseEditOutput
|
|
|
|
.withArgs(this.commandOutput, this.compileDir)
|
|
|
|
.returns(this.records)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2022-07-07 08:27:20 -04:00
|
|
|
describe('normal case', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
this.result = await this.CompileManager.promises.syncFromPdf(
|
|
|
|
this.projectId,
|
|
|
|
this.userId,
|
|
|
|
this.page,
|
|
|
|
this.h,
|
|
|
|
this.v,
|
|
|
|
''
|
|
|
|
)
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
|
2022-07-07 08:27:20 -04:00
|
|
|
it('should execute the synctex binary', function () {
|
|
|
|
const outputFilePath = `${this.compileDir}/output.pdf`
|
|
|
|
expect(this.CommandRunner.promises.run).to.have.been.calledWith(
|
|
|
|
`${this.projectId}-${this.userId}`,
|
|
|
|
[
|
|
|
|
'synctex',
|
|
|
|
'edit',
|
|
|
|
'-o',
|
|
|
|
`${this.page}:${this.h}:${this.v}:${outputFilePath}`,
|
|
|
|
],
|
|
|
|
this.compileDir,
|
|
|
|
this.Settings.clsi.docker.image,
|
|
|
|
60000,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the parsed output', function () {
|
|
|
|
expect(this.result).to.deep.equal(this.records)
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2021-03-30 08:22:11 -04:00
|
|
|
|
|
|
|
describe('with a custom imageName', function () {
|
|
|
|
const customImageName = 'foo/bar:tag-1'
|
2022-07-07 08:27:20 -04:00
|
|
|
beforeEach(async function () {
|
|
|
|
await this.CompileManager.promises.syncFromPdf(
|
2021-08-30 07:56:13 -04:00
|
|
|
this.projectId,
|
|
|
|
this.userId,
|
2021-03-30 08:22:11 -04:00
|
|
|
this.page,
|
|
|
|
this.h,
|
|
|
|
this.v,
|
2022-07-07 08:27:20 -04:00
|
|
|
customImageName
|
2021-03-30 08:22:11 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should execute the synctex binary in a custom docker image', function () {
|
2021-09-07 08:57:47 -04:00
|
|
|
const outputFilePath = `${this.compileDir}/output.pdf`
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.CommandRunner.promises.run).to.have.been.calledWith(
|
|
|
|
`${this.projectId}-${this.userId}`,
|
|
|
|
[
|
|
|
|
'synctex',
|
|
|
|
'edit',
|
|
|
|
'-o',
|
|
|
|
`${this.page}:${this.h}:${this.v}:${outputFilePath}`,
|
|
|
|
],
|
|
|
|
this.compileDir,
|
|
|
|
customImageName,
|
|
|
|
60000,
|
|
|
|
{}
|
|
|
|
)
|
2021-03-30 08:22:11 -04:00
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-30 07:56:13 -04:00
|
|
|
describe('wordcount', function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
beforeEach(async function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.timeout = 60 * 1000
|
2021-09-07 08:57:47 -04:00
|
|
|
this.filename = 'main.tex'
|
2020-02-19 06:15:37 -05:00
|
|
|
this.image = 'example.com/image'
|
|
|
|
|
2022-07-07 08:27:20 -04:00
|
|
|
this.result = await this.CompileManager.promises.wordcount(
|
2021-08-30 07:56:13 -04:00
|
|
|
this.projectId,
|
|
|
|
this.userId,
|
2021-09-07 08:57:47 -04:00
|
|
|
this.filename,
|
2022-07-07 08:27:20 -04:00
|
|
|
this.image
|
2020-02-19 06:15:37 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should run the texcount command', function () {
|
2021-09-07 08:57:47 -04:00
|
|
|
this.filePath = `$COMPILE_DIR/${this.filename}`
|
2024-02-02 04:35:32 -05:00
|
|
|
this.command = ['texcount', '-nocol', '-inc', this.filePath]
|
2020-02-19 06:15:37 -05:00
|
|
|
|
2022-07-07 08:27:20 -04:00
|
|
|
expect(this.CommandRunner.promises.run).to.have.been.calledWith(
|
|
|
|
`${this.projectId}-${this.userId}`,
|
|
|
|
this.command,
|
|
|
|
this.compileDir,
|
|
|
|
this.image,
|
|
|
|
this.timeout,
|
|
|
|
{}
|
|
|
|
)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2022-07-07 08:27:20 -04:00
|
|
|
it('should return the parsed output', function () {
|
|
|
|
expect(this.result).to.deep.equal({
|
|
|
|
encode: 'ascii',
|
|
|
|
textWords: 2,
|
|
|
|
headWords: 0,
|
|
|
|
outside: 0,
|
|
|
|
headers: 0,
|
|
|
|
elements: 0,
|
|
|
|
mathInline: 0,
|
|
|
|
mathDisplay: 0,
|
|
|
|
errors: 0,
|
|
|
|
messages: '',
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|