[misc] bump the dev-env to 3.3.2
This commit is contained in:
@@ -19,8 +19,8 @@ const modulePath = require('path').join(
|
||||
)
|
||||
const tk = require('timekeeper')
|
||||
|
||||
describe('CompileController', function() {
|
||||
beforeEach(function() {
|
||||
describe('CompileController', function () {
|
||||
beforeEach(function () {
|
||||
this.CompileController = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./CompileManager': (this.CompileManager = {}),
|
||||
@@ -47,8 +47,8 @@ describe('CompileController', function() {
|
||||
return (this.next = sinon.stub())
|
||||
})
|
||||
|
||||
describe('compile', function() {
|
||||
beforeEach(function() {
|
||||
describe('compile', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body = {
|
||||
compile: 'mock-body'
|
||||
}
|
||||
@@ -82,40 +82,40 @@ describe('CompileController', function() {
|
||||
return (this.res.send = sinon.stub())
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
describe('successfully', function () {
|
||||
beforeEach(function () {
|
||||
this.CompileManager.doCompileWithLock = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.output_files)
|
||||
return this.CompileController.compile(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should parse the request', function() {
|
||||
it('should parse the request', function () {
|
||||
return this.RequestParser.parse
|
||||
.calledWith(this.req.body)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should run the compile for the specified project', function() {
|
||||
it('should run the compile for the specified project', function () {
|
||||
return this.CompileManager.doCompileWithLock
|
||||
.calledWith(this.request_with_project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should mark the project as accessed', function() {
|
||||
it('should mark the project as accessed', function () {
|
||||
return this.ProjectPersistenceManager.markProjectAsJustAccessed
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the JSON response', function() {
|
||||
return it('should return the JSON response', function () {
|
||||
this.res.status.calledWith(200).should.equal(true)
|
||||
return this.res.send
|
||||
.calledWith({
|
||||
compile: {
|
||||
status: 'success',
|
||||
error: null,
|
||||
outputFiles: this.output_files.map(file => {
|
||||
outputFiles: this.output_files.map((file) => {
|
||||
return {
|
||||
url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`,
|
||||
path: file.path,
|
||||
@@ -129,15 +129,15 @@ describe('CompileController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('with an error', function () {
|
||||
beforeEach(function () {
|
||||
this.CompileManager.doCompileWithLock = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, new Error((this.message = 'error message')), null)
|
||||
return this.CompileController.compile(this.req, this.res)
|
||||
})
|
||||
|
||||
return it('should return the JSON response with the error', function() {
|
||||
return it('should return the JSON response with the error', function () {
|
||||
this.res.status.calledWith(500).should.equal(true)
|
||||
return this.res.send
|
||||
.calledWith({
|
||||
@@ -151,8 +151,8 @@ describe('CompileController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the request times out', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the request times out', function () {
|
||||
beforeEach(function () {
|
||||
this.error = new Error((this.message = 'container timed out'))
|
||||
this.error.timedout = true
|
||||
this.CompileManager.doCompileWithLock = sinon
|
||||
@@ -161,7 +161,7 @@ describe('CompileController', function() {
|
||||
return this.CompileController.compile(this.req, this.res)
|
||||
})
|
||||
|
||||
return it('should return the JSON response with the timeout status', function() {
|
||||
return it('should return the JSON response with the timeout status', function () {
|
||||
this.res.status.calledWith(200).should.equal(true)
|
||||
return this.res.send
|
||||
.calledWith({
|
||||
@@ -175,15 +175,15 @@ describe('CompileController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the request returns no output files', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when the request returns no output files', function () {
|
||||
beforeEach(function () {
|
||||
this.CompileManager.doCompileWithLock = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, [])
|
||||
return this.CompileController.compile(this.req, this.res)
|
||||
})
|
||||
|
||||
return it('should return the JSON response with the failure status', function() {
|
||||
return it('should return the JSON response with the failure status', function () {
|
||||
this.res.status.calledWith(200).should.equal(true)
|
||||
return this.res.send
|
||||
.calledWith({
|
||||
@@ -198,8 +198,8 @@ describe('CompileController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('syncFromCode', function() {
|
||||
beforeEach(function() {
|
||||
describe('syncFromCode', function () {
|
||||
beforeEach(function () {
|
||||
this.file = 'main.tex'
|
||||
this.line = 42
|
||||
this.column = 5
|
||||
@@ -218,7 +218,7 @@ describe('CompileController', function() {
|
||||
return this.CompileController.syncFromCode(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should find the corresponding location in the PDF', function() {
|
||||
it('should find the corresponding location in the PDF', function () {
|
||||
return this.CompileManager.syncFromCode
|
||||
.calledWith(
|
||||
this.project_id,
|
||||
@@ -230,7 +230,7 @@ describe('CompileController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the positions', function() {
|
||||
return it('should return the positions', function () {
|
||||
return this.res.json
|
||||
.calledWith({
|
||||
pdf: this.pdfPositions
|
||||
@@ -239,8 +239,8 @@ describe('CompileController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('syncFromPdf', function() {
|
||||
beforeEach(function() {
|
||||
describe('syncFromPdf', function () {
|
||||
beforeEach(function () {
|
||||
this.page = 5
|
||||
this.h = 100.23
|
||||
this.v = 45.67
|
||||
@@ -259,13 +259,13 @@ describe('CompileController', function() {
|
||||
return this.CompileController.syncFromPdf(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should find the corresponding location in the code', function() {
|
||||
it('should find the corresponding location in the code', function () {
|
||||
return this.CompileManager.syncFromPdf
|
||||
.calledWith(this.project_id, undefined, this.page, this.h, this.v)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the positions', function() {
|
||||
return it('should return the positions', function () {
|
||||
return this.res.json
|
||||
.calledWith({
|
||||
code: this.codePositions
|
||||
@@ -274,8 +274,8 @@ describe('CompileController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('wordcount', function() {
|
||||
beforeEach(function() {
|
||||
return describe('wordcount', function () {
|
||||
beforeEach(function () {
|
||||
this.file = 'main.tex'
|
||||
this.project_id = 'mock-project-id'
|
||||
this.req.params = { project_id: this.project_id }
|
||||
@@ -290,14 +290,14 @@ describe('CompileController', function() {
|
||||
.callsArgWith(4, null, (this.texcount = ['mock-texcount']))
|
||||
})
|
||||
|
||||
it('should return the word count of a file', function() {
|
||||
it('should return the word count of a file', function () {
|
||||
this.CompileController.wordcount(this.req, this.res, this.next)
|
||||
return this.CompileManager.wordcount
|
||||
.calledWith(this.project_id, undefined, this.file, this.image)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return the texcount info', function() {
|
||||
it('should return the texcount info', function () {
|
||||
this.CompileController.wordcount(this.req, this.res, this.next)
|
||||
return this.res.json
|
||||
.calledWith({
|
||||
@@ -306,8 +306,8 @@ describe('CompileController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
describe('when allowedImages is set', function() {
|
||||
beforeEach(function() {
|
||||
describe('when allowedImages is set', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.clsi = { docker: {} }
|
||||
this.Settings.clsi.docker.allowedImages = [
|
||||
'repo/image:tag1',
|
||||
@@ -317,28 +317,28 @@ describe('CompileController', function() {
|
||||
this.res.status = sinon.stub().returns({ send: this.res.send })
|
||||
})
|
||||
|
||||
describe('with an invalid image', function() {
|
||||
beforeEach(function() {
|
||||
describe('with an invalid image', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query.image = 'something/evil:1337'
|
||||
this.CompileController.wordcount(this.req, this.res, this.next)
|
||||
})
|
||||
it('should return a 400', function() {
|
||||
it('should return a 400', function () {
|
||||
expect(this.res.status.calledWith(400)).to.equal(true)
|
||||
})
|
||||
it('should not run the query', function() {
|
||||
it('should not run the query', function () {
|
||||
expect(this.CompileManager.wordcount.called).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a valid image', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a valid image', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query.image = 'repo/image:tag1'
|
||||
this.CompileController.wordcount(this.req, this.res, this.next)
|
||||
})
|
||||
it('should not return a 400', function() {
|
||||
it('should not return a 400', function () {
|
||||
expect(this.res.status.calledWith(400)).to.equal(false)
|
||||
})
|
||||
it('should run the query', function() {
|
||||
it('should run the query', function () {
|
||||
expect(this.CompileManager.wordcount.called).to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -24,8 +24,8 @@ const tk = require('timekeeper')
|
||||
const { EventEmitter } = require('events')
|
||||
const Path = require('path')
|
||||
|
||||
describe('CompileManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('CompileManager', function () {
|
||||
beforeEach(function () {
|
||||
this.CompileManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./LatexRunner': (this.LatexRunner = {}),
|
||||
@@ -60,8 +60,8 @@ describe('CompileManager', function() {
|
||||
this.project_id = 'project-id-123'
|
||||
return (this.user_id = '1234')
|
||||
})
|
||||
describe('doCompileWithLock', function() {
|
||||
beforeEach(function() {
|
||||
describe('doCompileWithLock', function () {
|
||||
beforeEach(function () {
|
||||
this.request = {
|
||||
resources: (this.resources = 'mock-resources'),
|
||||
project_id: this.project_id,
|
||||
@@ -77,33 +77,33 @@ describe('CompileManager', function() {
|
||||
runner((err, ...result) => callback(err, ...Array.from(result))))
|
||||
})
|
||||
|
||||
describe('when the project is not locked', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the project is not locked', function () {
|
||||
beforeEach(function () {
|
||||
return this.CompileManager.doCompileWithLock(
|
||||
this.request,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should ensure that the compile directory exists', function() {
|
||||
it('should ensure that the compile directory exists', function () {
|
||||
return this.fse.ensureDir.calledWith(this.compileDir).should.equal(true)
|
||||
})
|
||||
|
||||
it('should call doCompile with the request', function() {
|
||||
it('should call doCompile with the request', function () {
|
||||
return this.CompileManager.doCompile
|
||||
.calledWith(this.request)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with the output files', function() {
|
||||
return it('should call the callback with the output files', function () {
|
||||
return this.callback
|
||||
.calledWithExactly(null, this.output_files)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the project is locked', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when the project is locked', function () {
|
||||
beforeEach(function () {
|
||||
this.error = new Error('locked')
|
||||
this.LockManager.runWithLock = (lockFile, runner, callback) => {
|
||||
return callback(this.error)
|
||||
@@ -114,22 +114,22 @@ describe('CompileManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should ensure that the compile directory exists', function() {
|
||||
it('should ensure that the compile directory exists', function () {
|
||||
return this.fse.ensureDir.calledWith(this.compileDir).should.equal(true)
|
||||
})
|
||||
|
||||
it('should not call doCompile with the request', function() {
|
||||
it('should not call doCompile with the request', function () {
|
||||
return this.CompileManager.doCompile.called.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should call the callback with the error', function() {
|
||||
return it('should call the callback with the error', function () {
|
||||
return this.callback.calledWithExactly(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('doCompile', function() {
|
||||
beforeEach(function() {
|
||||
describe('doCompile', function () {
|
||||
beforeEach(function () {
|
||||
this.output_files = [
|
||||
{
|
||||
path: 'output.log',
|
||||
@@ -180,18 +180,18 @@ describe('CompileManager', function() {
|
||||
return (this.TikzManager.checkMainFile = sinon.stub().callsArg(3, false))
|
||||
})
|
||||
|
||||
describe('normally', function() {
|
||||
beforeEach(function() {
|
||||
describe('normally', function () {
|
||||
beforeEach(function () {
|
||||
return this.CompileManager.doCompile(this.request, this.callback)
|
||||
})
|
||||
|
||||
it('should write the resources to disk', function() {
|
||||
it('should write the resources to disk', function () {
|
||||
return this.ResourceWriter.syncResourcesToDisk
|
||||
.calledWith(this.request, this.compileDir)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should run LaTeX', function() {
|
||||
it('should run LaTeX', function () {
|
||||
return this.LatexRunner.runLatex
|
||||
.calledWith(`${this.project_id}-${this.user_id}`, {
|
||||
directory: this.compileDir,
|
||||
@@ -206,43 +206,43 @@ describe('CompileManager', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should find the output files', function() {
|
||||
it('should find the output files', function () {
|
||||
return this.OutputFileFinder.findOutputFiles
|
||||
.calledWith(this.resources, this.compileDir)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return the output files', function() {
|
||||
it('should return the output files', function () {
|
||||
return this.callback
|
||||
.calledWith(null, this.build_files)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should not inject draft mode by default', function() {
|
||||
return it('should not inject draft mode by default', function () {
|
||||
return this.DraftModeManager.injectDraftMode.called.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with draft mode', function() {
|
||||
beforeEach(function() {
|
||||
describe('with draft mode', function () {
|
||||
beforeEach(function () {
|
||||
this.request.draft = true
|
||||
return this.CompileManager.doCompile(this.request, this.callback)
|
||||
})
|
||||
|
||||
return it('should inject the draft mode header', function() {
|
||||
return it('should inject the draft mode header', function () {
|
||||
return this.DraftModeManager.injectDraftMode
|
||||
.calledWith(this.compileDir + '/' + this.rootResourcePath)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a check option', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a check option', function () {
|
||||
beforeEach(function () {
|
||||
this.request.check = 'error'
|
||||
return this.CompileManager.doCompile(this.request, this.callback)
|
||||
})
|
||||
|
||||
return it('should run chktex', function() {
|
||||
return it('should run chktex', function () {
|
||||
return this.LatexRunner.runLatex
|
||||
.calledWith(`${this.project_id}-${this.user_id}`, {
|
||||
directory: this.compileDir,
|
||||
@@ -262,14 +262,14 @@ describe('CompileManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with a knitr file and check options', function() {
|
||||
beforeEach(function() {
|
||||
return describe('with a knitr file and check options', function () {
|
||||
beforeEach(function () {
|
||||
this.request.rootResourcePath = 'main.Rtex'
|
||||
this.request.check = 'error'
|
||||
return this.CompileManager.doCompile(this.request, this.callback)
|
||||
})
|
||||
|
||||
return it('should not run chktex', function() {
|
||||
return it('should not run chktex', function () {
|
||||
return this.LatexRunner.runLatex
|
||||
.calledWith(`${this.project_id}-${this.user_id}`, {
|
||||
directory: this.compileDir,
|
||||
@@ -286,9 +286,9 @@ describe('CompileManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('clearProject', function() {
|
||||
describe('succesfully', function() {
|
||||
beforeEach(function() {
|
||||
describe('clearProject', function () {
|
||||
describe('succesfully', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.compileDir = 'compiles'
|
||||
this.fs.lstat = sinon.stub().callsArgWith(1, null, {
|
||||
isDirectory() {
|
||||
@@ -308,7 +308,7 @@ describe('CompileManager', function() {
|
||||
return this.proc.emit('close', 0)
|
||||
})
|
||||
|
||||
it('should remove the project directory', function() {
|
||||
it('should remove the project directory', function () {
|
||||
return this.child_process.spawn
|
||||
.calledWith('rm', [
|
||||
'-r',
|
||||
@@ -317,13 +317,13 @@ describe('CompileManager', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with a non-success status code', function() {
|
||||
beforeEach(function() {
|
||||
return describe('with a non-success status code', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.compileDir = 'compiles'
|
||||
this.fs.lstat = sinon.stub().callsArgWith(1, null, {
|
||||
isDirectory() {
|
||||
@@ -344,7 +344,7 @@ describe('CompileManager', function() {
|
||||
return this.proc.emit('close', 1)
|
||||
})
|
||||
|
||||
it('should remove the project directory', function() {
|
||||
it('should remove the project directory', function () {
|
||||
return this.child_process.spawn
|
||||
.calledWith('rm', [
|
||||
'-r',
|
||||
@@ -353,7 +353,7 @@ describe('CompileManager', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with an error from the stderr', function() {
|
||||
it('should call the callback with an error from the stderr', function () {
|
||||
this.callback.calledWithExactly(sinon.match(Error)).should.equal(true)
|
||||
|
||||
this.callback.args[0][0].message.should.equal(
|
||||
@@ -363,8 +363,8 @@ describe('CompileManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('syncing', function() {
|
||||
beforeEach(function() {
|
||||
describe('syncing', function () {
|
||||
beforeEach(function () {
|
||||
this.page = 1
|
||||
this.h = 42.23
|
||||
this.v = 87.56
|
||||
@@ -374,12 +374,12 @@ describe('CompileManager', function() {
|
||||
this.column = 3
|
||||
this.file_name = 'main.tex'
|
||||
this.child_process.execFile = sinon.stub()
|
||||
return (this.Settings.path.synctexBaseDir = project_id =>
|
||||
return (this.Settings.path.synctexBaseDir = (project_id) =>
|
||||
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`)
|
||||
})
|
||||
|
||||
describe('syncFromCode', function() {
|
||||
beforeEach(function() {
|
||||
describe('syncFromCode', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.stat = sinon.stub().callsArgWith(1, null, {
|
||||
isFile() {
|
||||
return true
|
||||
@@ -399,7 +399,7 @@ describe('CompileManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should execute the synctex binary', function() {
|
||||
it('should execute the synctex binary', function () {
|
||||
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}`
|
||||
@@ -422,7 +422,7 @@ describe('CompileManager', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with the parsed output', function() {
|
||||
return it('should call the callback with the parsed output', function () {
|
||||
return this.callback
|
||||
.calledWith(null, [
|
||||
{
|
||||
@@ -437,8 +437,8 @@ describe('CompileManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('syncFromPdf', function() {
|
||||
beforeEach(function() {
|
||||
return describe('syncFromPdf', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.stat = sinon.stub().callsArgWith(1, null, {
|
||||
isFile() {
|
||||
return true
|
||||
@@ -458,7 +458,7 @@ describe('CompileManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should execute the synctex binary', function() {
|
||||
it('should execute the synctex binary', function () {
|
||||
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
|
||||
@@ -473,7 +473,7 @@ describe('CompileManager', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with the parsed output', function() {
|
||||
return it('should call the callback with the parsed output', function () {
|
||||
return this.callback
|
||||
.calledWith(null, [
|
||||
{
|
||||
@@ -487,8 +487,8 @@ describe('CompileManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('wordcount', function() {
|
||||
beforeEach(function() {
|
||||
return describe('wordcount', function () {
|
||||
beforeEach(function () {
|
||||
this.CommandRunner.run = sinon.stub().callsArg(7)
|
||||
this.fs.readFile = sinon
|
||||
.stub()
|
||||
@@ -514,7 +514,7 @@ describe('CompileManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should run the texcount command', function() {
|
||||
it('should run the texcount command', function () {
|
||||
this.directory = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`
|
||||
this.file_path = `$COMPILE_DIR/${this.file_name}`
|
||||
this.command = [
|
||||
@@ -537,7 +537,7 @@ describe('CompileManager', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with the parsed output', function() {
|
||||
return it('should call the callback with the parsed output', function () {
|
||||
return this.callback
|
||||
.calledWith(null, {
|
||||
encode: 'ascii',
|
||||
|
||||
@@ -18,61 +18,61 @@ const modulePath = require('path').join(
|
||||
'../../../app/js/ContentTypeMapper'
|
||||
)
|
||||
|
||||
describe('ContentTypeMapper', function() {
|
||||
beforeEach(function() {
|
||||
describe('ContentTypeMapper', function () {
|
||||
beforeEach(function () {
|
||||
return (this.ContentTypeMapper = SandboxedModule.require(modulePath))
|
||||
})
|
||||
|
||||
return describe('map', function() {
|
||||
it('should map .txt to text/plain', function() {
|
||||
return describe('map', function () {
|
||||
it('should map .txt to text/plain', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.txt')
|
||||
return content_type.should.equal('text/plain')
|
||||
})
|
||||
|
||||
it('should map .csv to text/csv', function() {
|
||||
it('should map .csv to text/csv', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.csv')
|
||||
return content_type.should.equal('text/csv')
|
||||
})
|
||||
|
||||
it('should map .pdf to application/pdf', function() {
|
||||
it('should map .pdf to application/pdf', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.pdf')
|
||||
return content_type.should.equal('application/pdf')
|
||||
})
|
||||
|
||||
it('should fall back to octet-stream', function() {
|
||||
it('should fall back to octet-stream', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.unknown')
|
||||
return content_type.should.equal('application/octet-stream')
|
||||
})
|
||||
|
||||
describe('coercing web files to plain text', function() {
|
||||
it('should map .js to plain text', function() {
|
||||
describe('coercing web files to plain text', function () {
|
||||
it('should map .js to plain text', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.js')
|
||||
return content_type.should.equal('text/plain')
|
||||
})
|
||||
|
||||
it('should map .html to plain text', function() {
|
||||
it('should map .html to plain text', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.html')
|
||||
return content_type.should.equal('text/plain')
|
||||
})
|
||||
|
||||
return it('should map .css to plain text', function() {
|
||||
return it('should map .css to plain text', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.css')
|
||||
return content_type.should.equal('text/plain')
|
||||
})
|
||||
})
|
||||
|
||||
return describe('image files', function() {
|
||||
it('should map .png to image/png', function() {
|
||||
return describe('image files', function () {
|
||||
it('should map .png to image/png', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.png')
|
||||
return content_type.should.equal('image/png')
|
||||
})
|
||||
|
||||
it('should map .jpeg to image/jpeg', function() {
|
||||
it('should map .jpeg to image/jpeg', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.jpeg')
|
||||
return content_type.should.equal('image/jpeg')
|
||||
})
|
||||
|
||||
return it('should map .svg to text/plain to protect against XSS (SVG can execute JS)', function() {
|
||||
return it('should map .svg to text/plain to protect against XSS (SVG can execute JS)', function () {
|
||||
const content_type = this.ContentTypeMapper.map('example.svg')
|
||||
return content_type.should.equal('text/plain')
|
||||
})
|
||||
|
||||
@@ -17,8 +17,8 @@ const modulePath = require('path').join(
|
||||
'../../../app/js/DockerLockManager'
|
||||
)
|
||||
|
||||
describe('LockManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('LockManager', function () {
|
||||
beforeEach(function () {
|
||||
return (this.LockManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'settings-sharelatex': (this.Settings = { clsi: { docker: {} } }),
|
||||
@@ -30,13 +30,13 @@ describe('LockManager', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
return describe('runWithLock', function() {
|
||||
describe('with a single lock', function() {
|
||||
beforeEach(function(done) {
|
||||
return describe('runWithLock', function () {
|
||||
describe('with a single lock', function () {
|
||||
beforeEach(function (done) {
|
||||
this.callback = sinon.stub()
|
||||
return this.LockManager.runWithLock(
|
||||
'lock-one',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(() => releaseLock(null, 'hello', 'world'), 100),
|
||||
|
||||
(err, ...args) => {
|
||||
@@ -46,20 +46,20 @@ describe('LockManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback
|
||||
.calledWith(null, 'hello', 'world')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with two locks', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('with two locks', function () {
|
||||
beforeEach(function (done) {
|
||||
this.callback1 = sinon.stub()
|
||||
this.callback2 = sinon.stub()
|
||||
this.LockManager.runWithLock(
|
||||
'lock-one',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(() => releaseLock(null, 'hello', 'world', 'one'), 100),
|
||||
|
||||
(err, ...args) => {
|
||||
@@ -68,7 +68,7 @@ describe('LockManager', function() {
|
||||
)
|
||||
return this.LockManager.runWithLock(
|
||||
'lock-two',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(() => releaseLock(null, 'hello', 'world', 'two'), 200),
|
||||
|
||||
(err, ...args) => {
|
||||
@@ -78,29 +78,29 @@ describe('LockManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the first callback', function() {
|
||||
it('should call the first callback', function () {
|
||||
return this.callback1
|
||||
.calledWith(null, 'hello', 'world', 'one')
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the second callback', function() {
|
||||
return it('should call the second callback', function () {
|
||||
return this.callback2
|
||||
.calledWith(null, 'hello', 'world', 'two')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with lock contention', function() {
|
||||
describe('where the first lock is released quickly', function() {
|
||||
beforeEach(function(done) {
|
||||
return describe('with lock contention', function () {
|
||||
describe('where the first lock is released quickly', function () {
|
||||
beforeEach(function (done) {
|
||||
this.LockManager.MAX_LOCK_WAIT_TIME = 1000
|
||||
this.LockManager.LOCK_TEST_INTERVAL = 100
|
||||
this.callback1 = sinon.stub()
|
||||
this.callback2 = sinon.stub()
|
||||
this.LockManager.runWithLock(
|
||||
'lock',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(() => releaseLock(null, 'hello', 'world', 'one'), 100),
|
||||
|
||||
(err, ...args) => {
|
||||
@@ -109,7 +109,7 @@ describe('LockManager', function() {
|
||||
)
|
||||
return this.LockManager.runWithLock(
|
||||
'lock',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(() => releaseLock(null, 'hello', 'world', 'two'), 200),
|
||||
|
||||
(err, ...args) => {
|
||||
@@ -119,21 +119,21 @@ describe('LockManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the first callback', function() {
|
||||
it('should call the first callback', function () {
|
||||
return this.callback1
|
||||
.calledWith(null, 'hello', 'world', 'one')
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the second callback', function() {
|
||||
return it('should call the second callback', function () {
|
||||
return this.callback2
|
||||
.calledWith(null, 'hello', 'world', 'two')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('where the first lock is held longer than the waiting time', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('where the first lock is held longer than the waiting time', function () {
|
||||
beforeEach(function (done) {
|
||||
let doneTwo
|
||||
this.LockManager.MAX_LOCK_HOLD_TIME = 10000
|
||||
this.LockManager.MAX_LOCK_WAIT_TIME = 1000
|
||||
@@ -141,7 +141,7 @@ describe('LockManager', function() {
|
||||
this.callback1 = sinon.stub()
|
||||
this.callback2 = sinon.stub()
|
||||
let doneOne = (doneTwo = false)
|
||||
const finish = function(key) {
|
||||
const finish = function (key) {
|
||||
if (key === 1) {
|
||||
doneOne = true
|
||||
}
|
||||
@@ -154,7 +154,7 @@ describe('LockManager', function() {
|
||||
}
|
||||
this.LockManager.runWithLock(
|
||||
'lock',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(
|
||||
() => releaseLock(null, 'hello', 'world', 'one'),
|
||||
1100
|
||||
@@ -167,7 +167,7 @@ describe('LockManager', function() {
|
||||
)
|
||||
return this.LockManager.runWithLock(
|
||||
'lock',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(() => releaseLock(null, 'hello', 'world', 'two'), 100),
|
||||
|
||||
(err, ...args) => {
|
||||
@@ -177,20 +177,20 @@ describe('LockManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the first callback', function() {
|
||||
it('should call the first callback', function () {
|
||||
return this.callback1
|
||||
.calledWith(null, 'hello', 'world', 'one')
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the second callback with an error', function() {
|
||||
return it('should call the second callback with an error', function () {
|
||||
const error = sinon.match.instanceOf(Error)
|
||||
return this.callback2.calledWith(error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('where the first lock is held longer than the max holding time', function() {
|
||||
beforeEach(function(done) {
|
||||
return describe('where the first lock is held longer than the max holding time', function () {
|
||||
beforeEach(function (done) {
|
||||
let doneTwo
|
||||
this.LockManager.MAX_LOCK_HOLD_TIME = 1000
|
||||
this.LockManager.MAX_LOCK_WAIT_TIME = 2000
|
||||
@@ -198,7 +198,7 @@ describe('LockManager', function() {
|
||||
this.callback1 = sinon.stub()
|
||||
this.callback2 = sinon.stub()
|
||||
let doneOne = (doneTwo = false)
|
||||
const finish = function(key) {
|
||||
const finish = function (key) {
|
||||
if (key === 1) {
|
||||
doneOne = true
|
||||
}
|
||||
@@ -211,7 +211,7 @@ describe('LockManager', function() {
|
||||
}
|
||||
this.LockManager.runWithLock(
|
||||
'lock',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(
|
||||
() => releaseLock(null, 'hello', 'world', 'one'),
|
||||
1500
|
||||
@@ -224,7 +224,7 @@ describe('LockManager', function() {
|
||||
)
|
||||
return this.LockManager.runWithLock(
|
||||
'lock',
|
||||
releaseLock =>
|
||||
(releaseLock) =>
|
||||
setTimeout(() => releaseLock(null, 'hello', 'world', 'two'), 100),
|
||||
|
||||
(err, ...args) => {
|
||||
@@ -234,13 +234,13 @@ describe('LockManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the first callback', function() {
|
||||
it('should call the first callback', function () {
|
||||
return this.callback1
|
||||
.calledWith(null, 'hello', 'world', 'one')
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the second callback', function() {
|
||||
return it('should call the second callback', function () {
|
||||
return this.callback2
|
||||
.calledWith(null, 'hello', 'world', 'two')
|
||||
.should.equal(true)
|
||||
|
||||
@@ -23,8 +23,8 @@ const modulePath = require('path').join(
|
||||
)
|
||||
const Path = require('path')
|
||||
|
||||
describe('DockerRunner', function() {
|
||||
beforeEach(function() {
|
||||
describe('DockerRunner', function () {
|
||||
beforeEach(function () {
|
||||
let container, Docker, Timer
|
||||
this.container = container = {}
|
||||
this.DockerRunner = SandboxedModule.require(modulePath, {
|
||||
@@ -39,7 +39,7 @@ describe('DockerRunner', function() {
|
||||
info: sinon.stub(),
|
||||
warn: sinon.stub()
|
||||
}),
|
||||
dockerode: (Docker = (function() {
|
||||
dockerode: (Docker = (function () {
|
||||
Docker = class Docker {
|
||||
static initClass() {
|
||||
this.prototype.getContainer = sinon.stub().returns(container)
|
||||
@@ -90,12 +90,12 @@ describe('DockerRunner', function() {
|
||||
return (this.Settings.clsi.docker.env = { PATH: 'mock-path' })
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
this.DockerRunner.stopContainerMonitor()
|
||||
})
|
||||
|
||||
describe('run', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('run', function () {
|
||||
beforeEach(function (done) {
|
||||
this.DockerRunner._getContainerOptions = sinon
|
||||
.stub()
|
||||
.returns((this.options = { mockoptions: 'foo' }))
|
||||
@@ -111,8 +111,8 @@ describe('DockerRunner', function() {
|
||||
return done()
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('successfully', function () {
|
||||
beforeEach(function (done) {
|
||||
this.DockerRunner._runAndWaitForContainer = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, (this.output = 'mock-output'))
|
||||
@@ -131,7 +131,7 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should generate the options for the container', function() {
|
||||
it('should generate the options for the container', function () {
|
||||
return this.DockerRunner._getContainerOptions
|
||||
.calledWith(
|
||||
this.command_with_dir,
|
||||
@@ -142,25 +142,25 @@ describe('DockerRunner', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should generate the fingerprint from the returned options', function() {
|
||||
it('should generate the fingerprint from the returned options', function () {
|
||||
return this.DockerRunner._fingerprintContainer
|
||||
.calledWith(this.options)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should do the run', function() {
|
||||
it('should do the run', function () {
|
||||
return this.DockerRunner._runAndWaitForContainer
|
||||
.calledWith(this.options, this.volumes, this.timeout)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.calledWith(null, this.output).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when path.sandboxedCompilesHostDir is set', function() {
|
||||
beforeEach(function() {
|
||||
describe('when path.sandboxedCompilesHostDir is set', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.path.sandboxedCompilesHostDir = '/some/host/dir/compiles'
|
||||
this.directory = '/var/lib/sharelatex/data/compiles/xyz'
|
||||
this.DockerRunner._runAndWaitForContainer = sinon
|
||||
@@ -178,7 +178,7 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should re-write the bind directory', function() {
|
||||
it('should re-write the bind directory', function () {
|
||||
const volumes = this.DockerRunner._runAndWaitForContainer.lastCall
|
||||
.args[1]
|
||||
return expect(volumes).to.deep.equal({
|
||||
@@ -186,13 +186,13 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.calledWith(null, this.output).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the run throws an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the run throws an error', function () {
|
||||
beforeEach(function () {
|
||||
let firstTime = true
|
||||
this.output = 'mock-output'
|
||||
this.DockerRunner._runAndWaitForContainer = (
|
||||
@@ -202,7 +202,7 @@ describe('DockerRunner', function() {
|
||||
callback
|
||||
) => {
|
||||
if (callback == null) {
|
||||
callback = function(error, output) {}
|
||||
callback = function (error, output) {}
|
||||
}
|
||||
if (firstTime) {
|
||||
firstTime = false
|
||||
@@ -227,25 +227,25 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should do the run twice', function() {
|
||||
it('should do the run twice', function () {
|
||||
return this.DockerRunner._runAndWaitForContainer.calledTwice.should.equal(
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
it('should destroy the container in between', function() {
|
||||
it('should destroy the container in between', function () {
|
||||
return this.DockerRunner.destroyContainer
|
||||
.calledWith(this.name, null)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.calledWith(null, this.output).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with no image', function() {
|
||||
beforeEach(function() {
|
||||
describe('with no image', function () {
|
||||
beforeEach(function () {
|
||||
this.DockerRunner._runAndWaitForContainer = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, (this.output = 'mock-output'))
|
||||
@@ -261,7 +261,7 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should use the default image', function() {
|
||||
return it('should use the default image', function () {
|
||||
return this.DockerRunner._getContainerOptions
|
||||
.calledWith(
|
||||
this.command_with_dir,
|
||||
@@ -273,8 +273,8 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with image override', function() {
|
||||
beforeEach(function() {
|
||||
describe('with image override', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.texliveImageNameOveride = 'overrideimage.com/something'
|
||||
this.DockerRunner._runAndWaitForContainer = sinon
|
||||
.stub()
|
||||
@@ -291,14 +291,14 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should use the override and keep the tag', function() {
|
||||
return it('should use the override and keep the tag', function () {
|
||||
const image = this.DockerRunner._getContainerOptions.args[0][1]
|
||||
return image.should.equal('overrideimage.com/something/image:2016.2')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with image restriction', function() {
|
||||
beforeEach(function() {
|
||||
describe('with image restriction', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.clsi.docker.allowedImages = [
|
||||
'repo/image:tag1',
|
||||
'repo/image:tag2'
|
||||
@@ -308,8 +308,8 @@ describe('DockerRunner', function() {
|
||||
.callsArgWith(3, null, (this.output = 'mock-output'))
|
||||
})
|
||||
|
||||
describe('with a valid image', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a valid image', function () {
|
||||
beforeEach(function () {
|
||||
this.DockerRunner.run(
|
||||
this.project_id,
|
||||
this.command,
|
||||
@@ -322,13 +322,13 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should setup the container', function() {
|
||||
it('should setup the container', function () {
|
||||
this.DockerRunner._getContainerOptions.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a invalid image', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a invalid image', function () {
|
||||
beforeEach(function () {
|
||||
this.DockerRunner.run(
|
||||
this.project_id,
|
||||
this.command,
|
||||
@@ -341,21 +341,21 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
const err = new Error('image not allowed')
|
||||
this.callback.called.should.equal(true)
|
||||
this.callback.args[0][0].message.should.equal(err.message)
|
||||
})
|
||||
|
||||
it('should not setup the container', function() {
|
||||
it('should not setup the container', function () {
|
||||
this.DockerRunner._getContainerOptions.called.should.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('run with _getOptions', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('run with _getOptions', function () {
|
||||
beforeEach(function (done) {
|
||||
// this.DockerRunner._getContainerOptions = sinon
|
||||
// .stub()
|
||||
// .returns((this.options = { mockoptions: 'foo' }))
|
||||
@@ -371,8 +371,8 @@ describe('DockerRunner', function() {
|
||||
return done()
|
||||
})
|
||||
|
||||
describe('when a compile group config is set', function() {
|
||||
beforeEach(function() {
|
||||
describe('when a compile group config is set', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.clsi.docker.compileGroupConfig = {
|
||||
'compile-group': {
|
||||
'HostConfig.newProperty': 'new-property'
|
||||
@@ -394,7 +394,7 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the docker options for the compile group', function() {
|
||||
it('should set the docker options for the compile group', function () {
|
||||
const options = this.DockerRunner._runAndWaitForContainer.lastCall
|
||||
.args[0]
|
||||
return expect(options.HostConfig).to.deep.include({
|
||||
@@ -406,14 +406,14 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.calledWith(null, this.output).should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('_runAndWaitForContainer', function() {
|
||||
beforeEach(function() {
|
||||
describe('_runAndWaitForContainer', function () {
|
||||
beforeEach(function () {
|
||||
this.options = { mockoptions: 'foo', name: (this.name = 'mock-name') }
|
||||
this.DockerRunner.startContainer = (
|
||||
options,
|
||||
@@ -436,25 +436,25 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should create/start the container', function() {
|
||||
it('should create/start the container', function () {
|
||||
return this.DockerRunner.startContainer
|
||||
.calledWith(this.options, this.volumes)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should wait for the container to finish', function() {
|
||||
it('should wait for the container to finish', function () {
|
||||
return this.DockerRunner.waitForContainer
|
||||
.calledWith(this.name, this.timeout)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with the output', function() {
|
||||
return it('should call the callback with the output', function () {
|
||||
return this.callback.calledWith(null, this.output).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('startContainer', function() {
|
||||
beforeEach(function() {
|
||||
describe('startContainer', function () {
|
||||
beforeEach(function () {
|
||||
this.attachStreamHandler = sinon.stub()
|
||||
this.attachStreamHandler.cock = true
|
||||
this.options = { mockoptions: 'foo', name: 'mock-name' }
|
||||
@@ -470,8 +470,8 @@ describe('DockerRunner', function() {
|
||||
return sinon.spy(this.DockerRunner, 'attachToContainer')
|
||||
})
|
||||
|
||||
describe('when the container exists', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the container exists', function () {
|
||||
beforeEach(function () {
|
||||
this.container.inspect = sinon.stub().callsArgWith(0)
|
||||
this.container.start = sinon.stub().yields()
|
||||
|
||||
@@ -483,24 +483,24 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should start the container with the given name', function() {
|
||||
it('should start the container with the given name', function () {
|
||||
this.getContainer.calledWith(this.options.name).should.equal(true)
|
||||
return this.container.start.called.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not try to create the container', function() {
|
||||
it('should not try to create the container', function () {
|
||||
return this.createContainer.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('should attach to the container', function() {
|
||||
it('should attach to the container', function () {
|
||||
return this.DockerRunner.attachToContainer.called.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should attach before the container starts', function() {
|
||||
return it('should attach before the container starts', function () {
|
||||
return sinon.assert.callOrder(
|
||||
this.DockerRunner.attachToContainer,
|
||||
this.container.start
|
||||
@@ -508,8 +508,8 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the container does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the container does not exist', function () {
|
||||
beforeEach(function () {
|
||||
const exists = false
|
||||
this.container.start = sinon.stub().yields()
|
||||
this.container.inspect = sinon
|
||||
@@ -523,20 +523,20 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should create the container', function() {
|
||||
it('should create the container', function () {
|
||||
return this.createContainer.calledWith(this.options).should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback and stream handler', function() {
|
||||
it('should call the callback and stream handler', function () {
|
||||
this.attachStreamHandler.called.should.equal(true)
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
|
||||
it('should attach to the container', function() {
|
||||
it('should attach to the container', function () {
|
||||
return this.DockerRunner.attachToContainer.called.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should attach before the container starts', function() {
|
||||
return it('should attach before the container starts', function () {
|
||||
return sinon.assert.callOrder(
|
||||
this.DockerRunner.attachToContainer,
|
||||
this.container.start
|
||||
@@ -544,8 +544,8 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the container is already running', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the container is already running', function () {
|
||||
beforeEach(function () {
|
||||
const error = new Error(
|
||||
`HTTP code is 304 which indicates error: server error - start: Cannot start container ${this.name}: The container MOCKID is already running.`
|
||||
)
|
||||
@@ -560,18 +560,18 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not try to create the container', function() {
|
||||
it('should not try to create the container', function () {
|
||||
return this.createContainer.called.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should call the callback and stream handler without an error', function() {
|
||||
return it('should call the callback and stream handler without an error', function () {
|
||||
this.attachStreamHandler.called.should.equal(true)
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a volume does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when a volume does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.stat = sinon.stub().yields(new Error('no such path'))
|
||||
return this.DockerRunner.startContainer(
|
||||
this.options,
|
||||
@@ -581,17 +581,17 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not try to create the container', function() {
|
||||
it('should not try to create the container', function () {
|
||||
return this.createContainer.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
this.callback.calledWith(sinon.match(Error)).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a volume exists but is not a directory', function() {
|
||||
beforeEach(function() {
|
||||
describe('when a volume exists but is not a directory', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.stat = sinon.stub().yields(null, {
|
||||
isDirectory() {
|
||||
return false
|
||||
@@ -605,17 +605,17 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not try to create the container', function() {
|
||||
it('should not try to create the container', function () {
|
||||
return this.createContainer.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
this.callback.calledWith(sinon.match(Error)).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a volume does not exist, but sibling-containers are used', function() {
|
||||
beforeEach(function() {
|
||||
describe('when a volume does not exist, but sibling-containers are used', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.stat = sinon.stub().yields(new Error('no such path'))
|
||||
this.Settings.path.sandboxedCompilesHostDir = '/some/path'
|
||||
this.container.start = sinon.stub().yields()
|
||||
@@ -626,30 +626,30 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return delete this.Settings.path.sandboxedCompilesHostDir
|
||||
})
|
||||
|
||||
it('should start the container with the given name', function() {
|
||||
it('should start the container with the given name', function () {
|
||||
this.getContainer.calledWith(this.options.name).should.equal(true)
|
||||
return this.container.start.called.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not try to create the container', function() {
|
||||
it('should not try to create the container', function () {
|
||||
return this.createContainer.called.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
this.callback.called.should.equal(true)
|
||||
return this.callback.calledWith(new Error()).should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the container tries to be created, but already has been (race condition)', function() {})
|
||||
return describe('when the container tries to be created, but already has been (race condition)', function () {})
|
||||
})
|
||||
|
||||
describe('waitForContainer', function() {
|
||||
beforeEach(function() {
|
||||
describe('waitForContainer', function () {
|
||||
beforeEach(function () {
|
||||
this.containerId = 'container-id'
|
||||
this.timeout = 5000
|
||||
this.container.wait = sinon
|
||||
@@ -658,8 +658,8 @@ describe('DockerRunner', function() {
|
||||
return (this.container.kill = sinon.stub().yields())
|
||||
})
|
||||
|
||||
describe('when the container returns in time', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the container returns in time', function () {
|
||||
beforeEach(function () {
|
||||
return this.DockerRunner.waitForContainer(
|
||||
this.containerId,
|
||||
this.timeout,
|
||||
@@ -667,23 +667,23 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should wait for the container', function() {
|
||||
it('should wait for the container', function () {
|
||||
this.getContainer.calledWith(this.containerId).should.equal(true)
|
||||
return this.container.wait.called.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with the exit', function() {
|
||||
return it('should call the callback with the exit', function () {
|
||||
return this.callback
|
||||
.calledWith(null, this.statusCode)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the container does not return before the timeout', function() {
|
||||
beforeEach(function(done) {
|
||||
this.container.wait = function(callback) {
|
||||
return describe('when the container does not return before the timeout', function () {
|
||||
beforeEach(function (done) {
|
||||
this.container.wait = function (callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, exitCode) {}
|
||||
callback = function (error, exitCode) {}
|
||||
}
|
||||
return setTimeout(() => callback(null, { StatusCode: 42 }), 100)
|
||||
}
|
||||
@@ -698,12 +698,12 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call kill on the container', function() {
|
||||
it('should call kill on the container', function () {
|
||||
this.getContainer.calledWith(this.containerId).should.equal(true)
|
||||
return this.container.kill.called.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
this.callback.calledWith(sinon.match(Error)).should.equal(true)
|
||||
|
||||
const errorObj = this.callback.args[0][0]
|
||||
@@ -713,8 +713,8 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('destroyOldContainers', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('destroyOldContainers', function () {
|
||||
beforeEach(function (done) {
|
||||
const oneHourInSeconds = 60 * 60
|
||||
const oneHourInMilliseconds = oneHourInSeconds * 1000
|
||||
const nowInSeconds = Date.now() / 1000
|
||||
@@ -738,42 +738,42 @@ describe('DockerRunner', function() {
|
||||
this.DockerRunner.MAX_CONTAINER_AGE = oneHourInMilliseconds
|
||||
this.listContainers.callsArgWith(1, null, this.containers)
|
||||
this.DockerRunner.destroyContainer = sinon.stub().callsArg(3)
|
||||
return this.DockerRunner.destroyOldContainers(error => {
|
||||
return this.DockerRunner.destroyOldContainers((error) => {
|
||||
this.callback(error)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should list all containers', function() {
|
||||
it('should list all containers', function () {
|
||||
return this.listContainers.calledWith({ all: true }).should.equal(true)
|
||||
})
|
||||
|
||||
it('should destroy old containers', function() {
|
||||
it('should destroy old containers', function () {
|
||||
this.DockerRunner.destroyContainer.callCount.should.equal(1)
|
||||
return this.DockerRunner.destroyContainer
|
||||
.calledWith('project-old-container-name', 'old-container-id')
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not destroy new containers', function() {
|
||||
it('should not destroy new containers', function () {
|
||||
return this.DockerRunner.destroyContainer
|
||||
.calledWith('project-new-container-name', 'new-container-id')
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not destroy non-project containers', function() {
|
||||
it('should not destroy non-project containers', function () {
|
||||
return this.DockerRunner.destroyContainer
|
||||
.calledWith('totally-not-a-project-container', 'some-random-id')
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should callback the callback', function() {
|
||||
return it('should callback the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('_destroyContainer', function() {
|
||||
beforeEach(function() {
|
||||
describe('_destroyContainer', function () {
|
||||
beforeEach(function () {
|
||||
this.containerId = 'some_id'
|
||||
this.fakeContainer = { remove: sinon.stub().callsArgWith(1, null) }
|
||||
return (this.Docker.prototype.getContainer = sinon
|
||||
@@ -781,11 +781,11 @@ describe('DockerRunner', function() {
|
||||
.returns(this.fakeContainer))
|
||||
})
|
||||
|
||||
it('should get the container', function(done) {
|
||||
it('should get the container', function (done) {
|
||||
return this.DockerRunner._destroyContainer(
|
||||
this.containerId,
|
||||
false,
|
||||
err => {
|
||||
(err) => {
|
||||
this.Docker.prototype.getContainer.callCount.should.equal(1)
|
||||
this.Docker.prototype.getContainer
|
||||
.calledWith(this.containerId)
|
||||
@@ -795,11 +795,11 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should try to force-destroy the container when shouldForce=true', function(done) {
|
||||
it('should try to force-destroy the container when shouldForce=true', function (done) {
|
||||
return this.DockerRunner._destroyContainer(
|
||||
this.containerId,
|
||||
true,
|
||||
err => {
|
||||
(err) => {
|
||||
this.fakeContainer.remove.callCount.should.equal(1)
|
||||
this.fakeContainer.remove
|
||||
.calledWith({ force: true })
|
||||
@@ -809,11 +809,11 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not try to force-destroy the container when shouldForce=false', function(done) {
|
||||
it('should not try to force-destroy the container when shouldForce=false', function (done) {
|
||||
return this.DockerRunner._destroyContainer(
|
||||
this.containerId,
|
||||
false,
|
||||
err => {
|
||||
(err) => {
|
||||
this.fakeContainer.remove.callCount.should.equal(1)
|
||||
this.fakeContainer.remove
|
||||
.calledWith({ force: false })
|
||||
@@ -823,19 +823,19 @@ describe('DockerRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.DockerRunner._destroyContainer(
|
||||
this.containerId,
|
||||
false,
|
||||
err => {
|
||||
(err) => {
|
||||
expect(err).to.equal(null)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
describe('when the container is already gone', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the container is already gone', function () {
|
||||
beforeEach(function () {
|
||||
this.fakeError = new Error('woops')
|
||||
this.fakeError.statusCode = 404
|
||||
this.fakeContainer = {
|
||||
@@ -846,11 +846,11 @@ describe('DockerRunner', function() {
|
||||
.returns(this.fakeContainer))
|
||||
})
|
||||
|
||||
return it('should not produce an error', function(done) {
|
||||
return it('should not produce an error', function (done) {
|
||||
return this.DockerRunner._destroyContainer(
|
||||
this.containerId,
|
||||
false,
|
||||
err => {
|
||||
(err) => {
|
||||
expect(err).to.equal(null)
|
||||
return done()
|
||||
}
|
||||
@@ -858,8 +858,8 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when container.destroy produces an error', function(done) {
|
||||
beforeEach(function() {
|
||||
return describe('when container.destroy produces an error', function (done) {
|
||||
beforeEach(function () {
|
||||
this.fakeError = new Error('woops')
|
||||
this.fakeError.statusCode = 500
|
||||
this.fakeContainer = {
|
||||
@@ -870,11 +870,11 @@ describe('DockerRunner', function() {
|
||||
.returns(this.fakeContainer))
|
||||
})
|
||||
|
||||
return it('should produce an error', function(done) {
|
||||
return it('should produce an error', function (done) {
|
||||
return this.DockerRunner._destroyContainer(
|
||||
this.containerId,
|
||||
false,
|
||||
err => {
|
||||
(err) => {
|
||||
expect(err).to.not.equal(null)
|
||||
expect(err).to.equal(this.fakeError)
|
||||
return done()
|
||||
@@ -884,8 +884,8 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('kill', function() {
|
||||
beforeEach(function() {
|
||||
return describe('kill', function () {
|
||||
beforeEach(function () {
|
||||
this.containerId = 'some_id'
|
||||
this.fakeContainer = { kill: sinon.stub().callsArgWith(0, null) }
|
||||
return (this.Docker.prototype.getContainer = sinon
|
||||
@@ -893,8 +893,8 @@ describe('DockerRunner', function() {
|
||||
.returns(this.fakeContainer))
|
||||
})
|
||||
|
||||
it('should get the container', function(done) {
|
||||
return this.DockerRunner.kill(this.containerId, err => {
|
||||
it('should get the container', function (done) {
|
||||
return this.DockerRunner.kill(this.containerId, (err) => {
|
||||
this.Docker.prototype.getContainer.callCount.should.equal(1)
|
||||
this.Docker.prototype.getContainer
|
||||
.calledWith(this.containerId)
|
||||
@@ -903,22 +903,22 @@ describe('DockerRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should try to force-destroy the container', function(done) {
|
||||
return this.DockerRunner.kill(this.containerId, err => {
|
||||
it('should try to force-destroy the container', function (done) {
|
||||
return this.DockerRunner.kill(this.containerId, (err) => {
|
||||
this.fakeContainer.kill.callCount.should.equal(1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
return this.DockerRunner.kill(this.containerId, err => {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.DockerRunner.kill(this.containerId, (err) => {
|
||||
expect(err).to.equal(undefined)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the container is not actually running', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the container is not actually running', function () {
|
||||
beforeEach(function () {
|
||||
this.fakeError = new Error('woops')
|
||||
this.fakeError.statusCode = 500
|
||||
this.fakeError.message =
|
||||
@@ -931,16 +931,16 @@ describe('DockerRunner', function() {
|
||||
.returns(this.fakeContainer))
|
||||
})
|
||||
|
||||
return it('should not produce an error', function(done) {
|
||||
return this.DockerRunner.kill(this.containerId, err => {
|
||||
return it('should not produce an error', function (done) {
|
||||
return this.DockerRunner.kill(this.containerId, (err) => {
|
||||
expect(err).to.equal(undefined)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when container.kill produces a legitimate error', function(done) {
|
||||
beforeEach(function() {
|
||||
return describe('when container.kill produces a legitimate error', function (done) {
|
||||
beforeEach(function () {
|
||||
this.fakeError = new Error('woops')
|
||||
this.fakeError.statusCode = 500
|
||||
this.fakeError.message = 'Totally legitimate reason to throw an error'
|
||||
@@ -952,8 +952,8 @@ describe('DockerRunner', function() {
|
||||
.returns(this.fakeContainer))
|
||||
})
|
||||
|
||||
return it('should produce an error', function(done) {
|
||||
return this.DockerRunner.kill(this.containerId, err => {
|
||||
return it('should produce an error', function (done) {
|
||||
return this.DockerRunner.kill(this.containerId, (err) => {
|
||||
expect(err).to.not.equal(undefined)
|
||||
expect(err).to.equal(this.fakeError)
|
||||
return done()
|
||||
|
||||
@@ -16,8 +16,8 @@ const modulePath = require('path').join(
|
||||
'../../../app/js/DraftModeManager'
|
||||
)
|
||||
|
||||
describe('DraftModeManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('DraftModeManager', function () {
|
||||
beforeEach(function () {
|
||||
return (this.DraftModeManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
fs: (this.fs = {}),
|
||||
@@ -26,8 +26,8 @@ describe('DraftModeManager', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
describe('_injectDraftOption', function() {
|
||||
it('should add draft option into documentclass with existing options', function() {
|
||||
describe('_injectDraftOption', function () {
|
||||
it('should add draft option into documentclass with existing options', function () {
|
||||
return this.DraftModeManager._injectDraftOption(`\
|
||||
\\documentclass[a4paper,foo=bar]{article}\
|
||||
`).should.equal(`\
|
||||
@@ -35,7 +35,7 @@ describe('DraftModeManager', function() {
|
||||
`)
|
||||
})
|
||||
|
||||
return it('should add draft option into documentclass with no options', function() {
|
||||
return it('should add draft option into documentclass with no options', function () {
|
||||
return this.DraftModeManager._injectDraftOption(`\
|
||||
\\documentclass{article}\
|
||||
`).should.equal(`\
|
||||
@@ -44,8 +44,8 @@ describe('DraftModeManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('injectDraftMode', function() {
|
||||
beforeEach(function() {
|
||||
return describe('injectDraftMode', function () {
|
||||
beforeEach(function () {
|
||||
this.filename = '/mock/filename.tex'
|
||||
this.callback = sinon.stub()
|
||||
const content = `\
|
||||
@@ -59,13 +59,13 @@ Hello world
|
||||
return this.DraftModeManager.injectDraftMode(this.filename, this.callback)
|
||||
})
|
||||
|
||||
it('should read the file', function() {
|
||||
it('should read the file', function () {
|
||||
return this.fs.readFile
|
||||
.calledWith(this.filename, 'utf8')
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should write the modified file', function() {
|
||||
it('should write the modified file', function () {
|
||||
return this.fs.writeFile
|
||||
.calledWith(
|
||||
this.filename,
|
||||
@@ -79,7 +79,7 @@ Hello world
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -18,8 +18,8 @@ const modulePath = require('path').join(
|
||||
)
|
||||
const Path = require('path')
|
||||
|
||||
describe('LatexRunner', function() {
|
||||
beforeEach(function() {
|
||||
describe('LatexRunner', function () {
|
||||
beforeEach(function () {
|
||||
let Timer
|
||||
this.LatexRunner = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
@@ -54,16 +54,16 @@ describe('LatexRunner', function() {
|
||||
return (this.env = { foo: '123' })
|
||||
})
|
||||
|
||||
return describe('runLatex', function() {
|
||||
beforeEach(function() {
|
||||
return describe('runLatex', function () {
|
||||
beforeEach(function () {
|
||||
return (this.CommandRunner.run = sinon.stub().callsArgWith(7, null, {
|
||||
stdout: 'this is stdout',
|
||||
stderr: 'this is stderr'
|
||||
}))
|
||||
})
|
||||
|
||||
describe('normally', function() {
|
||||
beforeEach(function() {
|
||||
describe('normally', function () {
|
||||
beforeEach(function () {
|
||||
return this.LatexRunner.runLatex(
|
||||
this.project_id,
|
||||
{
|
||||
@@ -79,7 +79,7 @@ describe('LatexRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should run the latex command', function() {
|
||||
it('should run the latex command', function () {
|
||||
return this.CommandRunner.run
|
||||
.calledWith(
|
||||
this.project_id,
|
||||
@@ -93,7 +93,7 @@ describe('LatexRunner', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should record the stdout and stderr', function() {
|
||||
it('should record the stdout and stderr', function () {
|
||||
this.fs.writeFile
|
||||
.calledWith(this.directory + '/' + 'output.stdout', 'this is stdout')
|
||||
.should.equal(true)
|
||||
@@ -103,8 +103,8 @@ describe('LatexRunner', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an .Rtex main file', function() {
|
||||
beforeEach(function() {
|
||||
describe('with an .Rtex main file', function () {
|
||||
beforeEach(function () {
|
||||
return this.LatexRunner.runLatex(
|
||||
this.project_id,
|
||||
{
|
||||
@@ -118,15 +118,15 @@ describe('LatexRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should run the latex command on the equivalent .tex file', function() {
|
||||
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')
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with a flags option', function() {
|
||||
beforeEach(function() {
|
||||
return describe('with a flags option', function () {
|
||||
beforeEach(function () {
|
||||
return this.LatexRunner.runLatex(
|
||||
this.project_id,
|
||||
{
|
||||
@@ -141,10 +141,10 @@ describe('LatexRunner', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should include the flags in the command', function() {
|
||||
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'
|
||||
(arg) => arg === '-file-line-error' || arg === '-halt-on-error'
|
||||
)
|
||||
flags.length.should.equal(2)
|
||||
flags[0].should.equal('-file-line-error')
|
||||
|
||||
@@ -19,8 +19,8 @@ const modulePath = require('path').join(
|
||||
const Path = require('path')
|
||||
const Errors = require('../../../app/js/Errors')
|
||||
|
||||
describe('DockerLockManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('DockerLockManager', function () {
|
||||
beforeEach(function () {
|
||||
this.LockManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'settings-sharelatex': {},
|
||||
@@ -39,14 +39,14 @@ describe('DockerLockManager', function() {
|
||||
return (this.lockFile = '/local/compile/directory/.project-lock')
|
||||
})
|
||||
|
||||
return describe('runWithLock', function() {
|
||||
beforeEach(function() {
|
||||
return describe('runWithLock', function () {
|
||||
beforeEach(function () {
|
||||
this.runner = sinon.stub().callsArgWith(0, null, 'foo', 'bar')
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('normally', function() {
|
||||
beforeEach(function() {
|
||||
describe('normally', function () {
|
||||
beforeEach(function () {
|
||||
this.Lockfile.lock = sinon.stub().callsArgWith(2, null)
|
||||
this.Lockfile.unlock = sinon.stub().callsArgWith(1, null)
|
||||
return this.LockManager.runWithLock(
|
||||
@@ -56,19 +56,19 @@ describe('DockerLockManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should run the compile', function() {
|
||||
it('should run the compile', function () {
|
||||
return this.runner.calledWith().should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with the response from the compile', function() {
|
||||
return it('should call the callback with the response from the compile', function () {
|
||||
return this.callback
|
||||
.calledWithExactly(null, 'foo', 'bar')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the project is locked', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when the project is locked', function () {
|
||||
beforeEach(function () {
|
||||
this.error = new Error()
|
||||
this.error.code = 'EEXIST'
|
||||
this.Lockfile.lock = sinon.stub().callsArgWith(2, this.error)
|
||||
@@ -80,11 +80,11 @@ describe('DockerLockManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not run the compile', function() {
|
||||
it('should not run the compile', function () {
|
||||
return this.runner.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('should return an error', function() {
|
||||
it('should return an error', function () {
|
||||
this.callback
|
||||
.calledWithExactly(sinon.match(Errors.AlreadyCompilingError))
|
||||
.should.equal(true)
|
||||
|
||||
@@ -21,8 +21,8 @@ const path = require('path')
|
||||
const { expect } = require('chai')
|
||||
const { EventEmitter } = require('events')
|
||||
|
||||
describe('OutputFileFinder', function() {
|
||||
beforeEach(function() {
|
||||
describe('OutputFileFinder', function () {
|
||||
beforeEach(function () {
|
||||
this.OutputFileFinder = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
fs: (this.fs = {}),
|
||||
@@ -34,8 +34,8 @@ describe('OutputFileFinder', function() {
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('findOutputFiles', function() {
|
||||
beforeEach(function() {
|
||||
describe('findOutputFiles', function () {
|
||||
beforeEach(function () {
|
||||
this.resource_path = 'resource/path.tex'
|
||||
this.output_paths = ['output.pdf', 'extra/file.tex']
|
||||
this.all_paths = this.output_paths.concat([this.resource_path])
|
||||
@@ -52,7 +52,7 @@ describe('OutputFileFinder', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should only return the output files, not directories or resource paths', function() {
|
||||
return it('should only return the output files, not directories or resource paths', function () {
|
||||
return expect(this.outputFiles).to.deep.equal([
|
||||
{
|
||||
path: 'output.pdf',
|
||||
@@ -66,8 +66,8 @@ describe('OutputFileFinder', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('_getAllFiles', function() {
|
||||
beforeEach(function() {
|
||||
return describe('_getAllFiles', function () {
|
||||
beforeEach(function () {
|
||||
this.proc = new EventEmitter()
|
||||
this.proc.stdout = new EventEmitter()
|
||||
this.proc.stdout.setEncoding = sinon.stub().returns(this.proc.stdout)
|
||||
@@ -76,8 +76,8 @@ describe('OutputFileFinder', function() {
|
||||
return this.OutputFileFinder._getAllFiles(this.directory, this.callback)
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
describe('successfully', function () {
|
||||
beforeEach(function () {
|
||||
this.proc.stdout.emit(
|
||||
'data',
|
||||
['/base/dir/main.tex', '/base/dir/chapters/chapter1.tex'].join('\n') +
|
||||
@@ -86,19 +86,19 @@ describe('OutputFileFinder', function() {
|
||||
return this.proc.emit('close', 0)
|
||||
})
|
||||
|
||||
return it('should call the callback with the relative file paths', function() {
|
||||
return it('should call the callback with the relative file paths', function () {
|
||||
return this.callback
|
||||
.calledWith(null, ['main.tex', 'chapters/chapter1.tex'])
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe("when the directory doesn't exist", function() {
|
||||
beforeEach(function() {
|
||||
return describe("when the directory doesn't exist", function () {
|
||||
beforeEach(function () {
|
||||
return this.proc.emit('close', 1)
|
||||
})
|
||||
|
||||
return it('should call the callback with a blank array', function() {
|
||||
return it('should call the callback with a blank array', function () {
|
||||
return this.callback.calledWith(null, []).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21,8 +21,8 @@ const path = require('path')
|
||||
const { expect } = require('chai')
|
||||
const { EventEmitter } = require('events')
|
||||
|
||||
describe('OutputFileOptimiser', function() {
|
||||
beforeEach(function() {
|
||||
describe('OutputFileOptimiser', function () {
|
||||
beforeEach(function () {
|
||||
this.OutputFileOptimiser = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
fs: (this.fs = {}),
|
||||
@@ -37,14 +37,14 @@ describe('OutputFileOptimiser', function() {
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('optimiseFile', function() {
|
||||
beforeEach(function() {
|
||||
describe('optimiseFile', function () {
|
||||
beforeEach(function () {
|
||||
this.src = './output.pdf'
|
||||
return (this.dst = './output.pdf')
|
||||
})
|
||||
|
||||
describe('when the file is not a pdf file', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when the file is not a pdf file', function () {
|
||||
beforeEach(function (done) {
|
||||
this.src = './output.log'
|
||||
this.OutputFileOptimiser.checkIfPDFIsOptimised = sinon
|
||||
.stub()
|
||||
@@ -55,21 +55,21 @@ describe('OutputFileOptimiser', function() {
|
||||
return this.OutputFileOptimiser.optimiseFile(this.src, this.dst, done)
|
||||
})
|
||||
|
||||
it('should not check if the file is optimised', function() {
|
||||
it('should not check if the file is optimised', function () {
|
||||
return this.OutputFileOptimiser.checkIfPDFIsOptimised
|
||||
.calledWith(this.src)
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should not optimise the file', function() {
|
||||
return it('should not optimise the file', function () {
|
||||
return this.OutputFileOptimiser.optimisePDF
|
||||
.calledWith(this.src, this.dst)
|
||||
.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the pdf file is not optimised', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when the pdf file is not optimised', function () {
|
||||
beforeEach(function (done) {
|
||||
this.OutputFileOptimiser.checkIfPDFIsOptimised = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, false)
|
||||
@@ -79,21 +79,21 @@ describe('OutputFileOptimiser', function() {
|
||||
return this.OutputFileOptimiser.optimiseFile(this.src, this.dst, done)
|
||||
})
|
||||
|
||||
it('should check if the pdf is optimised', function() {
|
||||
it('should check if the pdf is optimised', function () {
|
||||
return this.OutputFileOptimiser.checkIfPDFIsOptimised
|
||||
.calledWith(this.src)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should optimise the pdf', function() {
|
||||
return it('should optimise the pdf', function () {
|
||||
return this.OutputFileOptimiser.optimisePDF
|
||||
.calledWith(this.src, this.dst)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the pdf file is optimised', function() {
|
||||
beforeEach(function(done) {
|
||||
return describe('when the pdf file is optimised', function () {
|
||||
beforeEach(function (done) {
|
||||
this.OutputFileOptimiser.checkIfPDFIsOptimised = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, true)
|
||||
@@ -103,13 +103,13 @@ describe('OutputFileOptimiser', function() {
|
||||
return this.OutputFileOptimiser.optimiseFile(this.src, this.dst, done)
|
||||
})
|
||||
|
||||
it('should check if the pdf is optimised', function() {
|
||||
it('should check if the pdf is optimised', function () {
|
||||
return this.OutputFileOptimiser.checkIfPDFIsOptimised
|
||||
.calledWith(this.src)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should not optimise the pdf', function() {
|
||||
return it('should not optimise the pdf', function () {
|
||||
return this.OutputFileOptimiser.optimisePDF
|
||||
.calledWith(this.src, this.dst)
|
||||
.should.equal(false)
|
||||
@@ -117,8 +117,8 @@ describe('OutputFileOptimiser', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('checkIfPDFISOptimised', function() {
|
||||
beforeEach(function() {
|
||||
return describe('checkIfPDFISOptimised', function () {
|
||||
beforeEach(function () {
|
||||
this.callback = sinon.stub()
|
||||
this.fd = 1234
|
||||
this.fs.open = sinon.stub().yields(null, this.fd)
|
||||
@@ -126,18 +126,15 @@ describe('OutputFileOptimiser', function() {
|
||||
.stub()
|
||||
.withArgs(this.fd)
|
||||
.yields(null, 100, Buffer.from('hello /Linearized 1'))
|
||||
this.fs.close = sinon
|
||||
.stub()
|
||||
.withArgs(this.fd)
|
||||
.yields(null)
|
||||
this.fs.close = sinon.stub().withArgs(this.fd).yields(null)
|
||||
return this.OutputFileOptimiser.checkIfPDFIsOptimised(
|
||||
this.src,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
describe('for a linearised file', function() {
|
||||
beforeEach(function() {
|
||||
describe('for a linearised file', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.read = sinon
|
||||
.stub()
|
||||
.withArgs(this.fd)
|
||||
@@ -148,25 +145,25 @@ describe('OutputFileOptimiser', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should open the file', function() {
|
||||
it('should open the file', function () {
|
||||
return this.fs.open.calledWith(this.src, 'r').should.equal(true)
|
||||
})
|
||||
|
||||
it('should read the header', function() {
|
||||
it('should read the header', function () {
|
||||
return this.fs.read.calledWith(this.fd).should.equal(true)
|
||||
})
|
||||
|
||||
it('should close the file', function() {
|
||||
it('should close the file', function () {
|
||||
return this.fs.close.calledWith(this.fd).should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with a true result', function() {
|
||||
return it('should call the callback with a true result', function () {
|
||||
return this.callback.calledWith(null, true).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('for an unlinearised file', function() {
|
||||
beforeEach(function() {
|
||||
return describe('for an unlinearised file', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.read = sinon
|
||||
.stub()
|
||||
.withArgs(this.fd)
|
||||
@@ -177,19 +174,19 @@ describe('OutputFileOptimiser', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should open the file', function() {
|
||||
it('should open the file', function () {
|
||||
return this.fs.open.calledWith(this.src, 'r').should.equal(true)
|
||||
})
|
||||
|
||||
it('should read the header', function() {
|
||||
it('should read the header', function () {
|
||||
return this.fs.read.calledWith(this.fd).should.equal(true)
|
||||
})
|
||||
|
||||
it('should close the file', function() {
|
||||
it('should close the file', function () {
|
||||
return this.fs.close.calledWith(this.fd).should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with a false result', function() {
|
||||
return it('should call the callback with a false result', function () {
|
||||
return this.callback.calledWith(null, false).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21,8 +21,8 @@ const modulePath = require('path').join(
|
||||
)
|
||||
const tk = require('timekeeper')
|
||||
|
||||
describe('ProjectPersistenceManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectPersistenceManager', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectPersistenceManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./UrlCache': (this.UrlCache = {}),
|
||||
@@ -44,8 +44,8 @@ describe('ProjectPersistenceManager', function() {
|
||||
return (this.user_id = '1234')
|
||||
})
|
||||
|
||||
describe('refreshExpiryTimeout', function() {
|
||||
it('should leave expiry alone if plenty of disk', function(done) {
|
||||
describe('refreshExpiryTimeout', function () {
|
||||
it('should leave expiry alone if plenty of disk', function (done) {
|
||||
this.diskusage.check.callsArgWith(1, null, {
|
||||
available: 40,
|
||||
total: 100
|
||||
@@ -59,7 +59,7 @@ describe('ProjectPersistenceManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should drop EXPIRY_TIMEOUT 10% if low disk usage', function(done) {
|
||||
it('should drop EXPIRY_TIMEOUT 10% if low disk usage', function (done) {
|
||||
this.diskusage.check.callsArgWith(1, null, {
|
||||
available: 5,
|
||||
total: 100
|
||||
@@ -71,7 +71,7 @@ describe('ProjectPersistenceManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not drop EXPIRY_TIMEOUT to below 50% of project_cache_length_ms', function(done) {
|
||||
it('should not drop EXPIRY_TIMEOUT to below 50% of project_cache_length_ms', function (done) {
|
||||
this.diskusage.check.callsArgWith(1, null, {
|
||||
available: 5,
|
||||
total: 100
|
||||
@@ -83,7 +83,7 @@ describe('ProjectPersistenceManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not modify EXPIRY_TIMEOUT if there is an error getting disk values', function(done) {
|
||||
it('should not modify EXPIRY_TIMEOUT if there is an error getting disk values', function (done) {
|
||||
this.diskusage.check.callsArgWith(1, 'Error', {
|
||||
available: 5,
|
||||
total: 100
|
||||
@@ -95,8 +95,8 @@ describe('ProjectPersistenceManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('clearExpiredProjects', function() {
|
||||
beforeEach(function() {
|
||||
describe('clearExpiredProjects', function () {
|
||||
beforeEach(function () {
|
||||
this.project_ids = ['project-id-1', 'project-id-2']
|
||||
this.ProjectPersistenceManager._findExpiredProjectIds = sinon
|
||||
.stub()
|
||||
@@ -108,21 +108,21 @@ describe('ProjectPersistenceManager', function() {
|
||||
return this.ProjectPersistenceManager.clearExpiredProjects(this.callback)
|
||||
})
|
||||
|
||||
it('should clear each expired project', function() {
|
||||
return Array.from(this.project_ids).map(project_id =>
|
||||
it('should clear each expired project', function () {
|
||||
return Array.from(this.project_ids).map((project_id) =>
|
||||
this.ProjectPersistenceManager.clearProjectFromCache
|
||||
.calledWith(project_id)
|
||||
.should.equal(true)
|
||||
)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('clearProject', function() {
|
||||
beforeEach(function() {
|
||||
return describe('clearProject', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectPersistenceManager._clearProjectFromDatabase = sinon
|
||||
.stub()
|
||||
.callsArg(1)
|
||||
@@ -135,25 +135,25 @@ describe('ProjectPersistenceManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should clear the project from the database', function() {
|
||||
it('should clear the project from the database', function () {
|
||||
return this.ProjectPersistenceManager._clearProjectFromDatabase
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should clear all the cached Urls for the project', function() {
|
||||
it('should clear all the cached Urls for the project', function () {
|
||||
return this.UrlCache.clearProject
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should clear the project compile folder', function() {
|
||||
it('should clear the project compile folder', function () {
|
||||
return this.CompileManager.clearProject
|
||||
.calledWith(this.project_id, this.user_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -19,8 +19,8 @@ const modulePath = require('path').join(
|
||||
)
|
||||
const tk = require('timekeeper')
|
||||
|
||||
describe('RequestParser', function() {
|
||||
beforeEach(function() {
|
||||
describe('RequestParser', function () {
|
||||
beforeEach(function () {
|
||||
tk.freeze()
|
||||
this.callback = sinon.stub()
|
||||
this.validResource = {
|
||||
@@ -46,41 +46,41 @@ describe('RequestParser', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return tk.reset()
|
||||
})
|
||||
|
||||
describe('without a top level object', function() {
|
||||
beforeEach(function() {
|
||||
describe('without a top level object', function () {
|
||||
beforeEach(function () {
|
||||
return this.RequestParser.parse([], this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('top level object should have a compile attribute')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('without a compile attribute', function() {
|
||||
beforeEach(function() {
|
||||
describe('without a compile attribute', function () {
|
||||
beforeEach(function () {
|
||||
return this.RequestParser.parse({}, this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('top level object should have a compile attribute')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('without a valid compiler', function() {
|
||||
beforeEach(function() {
|
||||
describe('without a valid compiler', function () {
|
||||
beforeEach(function () {
|
||||
this.validRequest.compile.options.compiler = 'not-a-compiler'
|
||||
return this.RequestParser.parse(this.validRequest, this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith(
|
||||
'compiler attribute should be one of: pdflatex, latex, xelatex, lualatex'
|
||||
@@ -89,33 +89,33 @@ describe('RequestParser', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('without a compiler specified', function() {
|
||||
beforeEach(function() {
|
||||
describe('without a compiler specified', function () {
|
||||
beforeEach(function () {
|
||||
delete this.validRequest.compile.options.compiler
|
||||
return this.RequestParser.parse(this.validRequest, (error, data) => {
|
||||
this.data = data
|
||||
})
|
||||
})
|
||||
|
||||
return it('should set the compiler to pdflatex by default', function() {
|
||||
return it('should set the compiler to pdflatex by default', function () {
|
||||
return this.data.compiler.should.equal('pdflatex')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with imageName set', function() {
|
||||
beforeEach(function() {
|
||||
describe('with imageName set', function () {
|
||||
beforeEach(function () {
|
||||
return this.RequestParser.parse(this.validRequest, (error, data) => {
|
||||
this.data = data
|
||||
})
|
||||
})
|
||||
|
||||
return it('should set the imageName', function() {
|
||||
return it('should set the imageName', function () {
|
||||
return this.data.imageName.should.equal('basicImageName/here:2017-1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('when image restrictions are present', function() {
|
||||
beforeEach(function() {
|
||||
describe('when image restrictions are present', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.clsi = { docker: {} }
|
||||
this.settings.clsi.docker.allowedImages = [
|
||||
'repo/name:tag1',
|
||||
@@ -123,8 +123,8 @@ describe('RequestParser', function() {
|
||||
]
|
||||
})
|
||||
|
||||
describe('with imageName set to something invalid', function() {
|
||||
beforeEach(function() {
|
||||
describe('with imageName set to something invalid', function () {
|
||||
beforeEach(function () {
|
||||
const request = this.validRequest
|
||||
request.compile.options.imageName = 'something/different:latest'
|
||||
this.RequestParser.parse(request, (error, data) => {
|
||||
@@ -133,15 +133,15 @@ describe('RequestParser', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw an error for imageName', function() {
|
||||
it('should throw an error for imageName', function () {
|
||||
expect(String(this.error)).to.include(
|
||||
'imageName attribute should be one of'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with imageName set to something valid', function() {
|
||||
beforeEach(function() {
|
||||
describe('with imageName set to something valid', function () {
|
||||
beforeEach(function () {
|
||||
const request = this.validRequest
|
||||
request.compile.options.imageName = 'repo/name:tag1'
|
||||
this.RequestParser.parse(request, (error, data) => {
|
||||
@@ -150,54 +150,54 @@ describe('RequestParser', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should set the imageName', function() {
|
||||
it('should set the imageName', function () {
|
||||
this.data.imageName.should.equal('repo/name:tag1')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with flags set', function() {
|
||||
beforeEach(function() {
|
||||
describe('with flags set', function () {
|
||||
beforeEach(function () {
|
||||
this.validRequest.compile.options.flags = ['-file-line-error']
|
||||
return this.RequestParser.parse(this.validRequest, (error, data) => {
|
||||
this.data = data
|
||||
})
|
||||
})
|
||||
|
||||
return it('should set the flags attribute', function() {
|
||||
return it('should set the flags attribute', function () {
|
||||
return expect(this.data.flags).to.deep.equal(['-file-line-error'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('with flags not specified', function() {
|
||||
beforeEach(function() {
|
||||
describe('with flags not specified', function () {
|
||||
beforeEach(function () {
|
||||
return this.RequestParser.parse(this.validRequest, (error, data) => {
|
||||
this.data = data
|
||||
})
|
||||
})
|
||||
|
||||
return it('it should have an empty flags list', function() {
|
||||
return it('it should have an empty flags list', function () {
|
||||
return expect(this.data.flags).to.deep.equal([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('without a timeout specified', function() {
|
||||
beforeEach(function() {
|
||||
describe('without a timeout specified', function () {
|
||||
beforeEach(function () {
|
||||
delete this.validRequest.compile.options.timeout
|
||||
return this.RequestParser.parse(this.validRequest, (error, data) => {
|
||||
this.data = data
|
||||
})
|
||||
})
|
||||
|
||||
return it('should set the timeout to MAX_TIMEOUT', function() {
|
||||
return it('should set the timeout to MAX_TIMEOUT', function () {
|
||||
return this.data.timeout.should.equal(
|
||||
this.RequestParser.MAX_TIMEOUT * 1000
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a timeout larger than the maximum', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a timeout larger than the maximum', function () {
|
||||
beforeEach(function () {
|
||||
this.validRequest.compile.options.timeout =
|
||||
this.RequestParser.MAX_TIMEOUT + 1
|
||||
return this.RequestParser.parse(this.validRequest, (error, data) => {
|
||||
@@ -205,62 +205,62 @@ describe('RequestParser', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return it('should set the timeout to MAX_TIMEOUT', function() {
|
||||
return it('should set the timeout to MAX_TIMEOUT', function () {
|
||||
return this.data.timeout.should.equal(
|
||||
this.RequestParser.MAX_TIMEOUT * 1000
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a timeout', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a timeout', function () {
|
||||
beforeEach(function () {
|
||||
return this.RequestParser.parse(this.validRequest, (error, data) => {
|
||||
this.data = data
|
||||
})
|
||||
})
|
||||
|
||||
return it('should set the timeout (in milliseconds)', function() {
|
||||
return it('should set the timeout (in milliseconds)', function () {
|
||||
return this.data.timeout.should.equal(
|
||||
this.validRequest.compile.options.timeout * 1000
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource without a path', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource without a path', function () {
|
||||
beforeEach(function () {
|
||||
delete this.validResource.path
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
return this.RequestParser.parse(this.validRequest, this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('all resources should have a path attribute')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource with a path', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource with a path', function () {
|
||||
beforeEach(function () {
|
||||
this.validResource.path = this.path = 'test.tex'
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
this.RequestParser.parse(this.validRequest, this.callback)
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it('should return the path in the parsed response', function() {
|
||||
return it('should return the path in the parsed response', function () {
|
||||
return this.data.resources[0].path.should.equal(this.path)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource with a malformed modified date', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource with a malformed modified date', function () {
|
||||
beforeEach(function () {
|
||||
this.validResource.modified = 'not-a-date'
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
return this.RequestParser.parse(this.validRequest, this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith(
|
||||
'resource modified date could not be understood: ' +
|
||||
@@ -270,8 +270,8 @@ describe('RequestParser', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource with a valid date', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource with a valid date', function () {
|
||||
beforeEach(function () {
|
||||
this.date = '12:00 01/02/03'
|
||||
this.validResource.modified = this.date
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
@@ -279,7 +279,7 @@ describe('RequestParser', function() {
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it('should return the date as a Javascript Date object', function() {
|
||||
return it('should return the date as a Javascript Date object', function () {
|
||||
;(this.data.resources[0].modified instanceof Date).should.equal(true)
|
||||
return this.data.resources[0].modified
|
||||
.getTime()
|
||||
@@ -287,15 +287,15 @@ describe('RequestParser', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource without either a content or URL attribute', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource without either a content or URL attribute', function () {
|
||||
beforeEach(function () {
|
||||
delete this.validResource.url
|
||||
delete this.validResource.content
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
return this.RequestParser.parse(this.validRequest, this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith(
|
||||
'all resources should have either a url or content attribute'
|
||||
@@ -304,99 +304,99 @@ describe('RequestParser', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource where the content is not a string', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource where the content is not a string', function () {
|
||||
beforeEach(function () {
|
||||
this.validResource.content = []
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
return this.RequestParser.parse(this.validRequest, this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('content attribute should be a string')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource where the url is not a string', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource where the url is not a string', function () {
|
||||
beforeEach(function () {
|
||||
this.validResource.url = []
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
return this.RequestParser.parse(this.validRequest, this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('url attribute should be a string')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource with a url', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource with a url', function () {
|
||||
beforeEach(function () {
|
||||
this.validResource.url = this.url = 'www.example.com'
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
this.RequestParser.parse(this.validRequest, this.callback)
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it('should return the url in the parsed response', function() {
|
||||
return it('should return the url in the parsed response', function () {
|
||||
return this.data.resources[0].url.should.equal(this.url)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a resource with a content attribute', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a resource with a content attribute', function () {
|
||||
beforeEach(function () {
|
||||
this.validResource.content = this.content = 'Hello world'
|
||||
this.validRequest.compile.resources.push(this.validResource)
|
||||
this.RequestParser.parse(this.validRequest, this.callback)
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it('should return the content in the parsed response', function() {
|
||||
return it('should return the content in the parsed response', function () {
|
||||
return this.data.resources[0].content.should.equal(this.content)
|
||||
})
|
||||
})
|
||||
|
||||
describe('without a root resource path', function() {
|
||||
beforeEach(function() {
|
||||
describe('without a root resource path', function () {
|
||||
beforeEach(function () {
|
||||
delete this.validRequest.compile.rootResourcePath
|
||||
this.RequestParser.parse(this.validRequest, this.callback)
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it("should set the root resource path to 'main.tex' by default", function() {
|
||||
return it("should set the root resource path to 'main.tex' by default", function () {
|
||||
return this.data.rootResourcePath.should.equal('main.tex')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a root resource path', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a root resource path', function () {
|
||||
beforeEach(function () {
|
||||
this.validRequest.compile.rootResourcePath = this.path = 'test.tex'
|
||||
this.RequestParser.parse(this.validRequest, this.callback)
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it('should return the root resource path in the parsed response', function() {
|
||||
return it('should return the root resource path in the parsed response', function () {
|
||||
return this.data.rootResourcePath.should.equal(this.path)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a root resource path that is not a string', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a root resource path that is not a string', function () {
|
||||
beforeEach(function () {
|
||||
this.validRequest.compile.rootResourcePath = []
|
||||
return this.RequestParser.parse(this.validRequest, this.callback)
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('rootResourcePath attribute should be a string')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a root resource path that needs escaping', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a root resource path that needs escaping', function () {
|
||||
beforeEach(function () {
|
||||
this.badPath = '`rm -rf foo`.tex'
|
||||
this.goodPath = 'rm -rf foo.tex'
|
||||
this.validRequest.compile.rootResourcePath = this.badPath
|
||||
@@ -409,51 +409,51 @@ describe('RequestParser', function() {
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
it('should return the escaped resource', function() {
|
||||
it('should return the escaped resource', function () {
|
||||
return this.data.rootResourcePath.should.equal(this.goodPath)
|
||||
})
|
||||
|
||||
return it('should also escape the resource path', function() {
|
||||
return it('should also escape the resource path', function () {
|
||||
return this.data.resources[0].path.should.equal(this.goodPath)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a root resource path that has a relative path', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a root resource path that has a relative path', function () {
|
||||
beforeEach(function () {
|
||||
this.validRequest.compile.rootResourcePath = 'foo/../../bar.tex'
|
||||
this.RequestParser.parse(this.validRequest, this.callback)
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('relative path in root resource')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a root resource path that has unescaped + relative path', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a root resource path that has unescaped + relative path', function () {
|
||||
beforeEach(function () {
|
||||
this.validRequest.compile.rootResourcePath = 'foo/#../bar.tex'
|
||||
this.RequestParser.parse(this.validRequest, this.callback)
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('relative path in root resource')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with an unknown syncType', function() {
|
||||
beforeEach(function() {
|
||||
return describe('with an unknown syncType', function () {
|
||||
beforeEach(function () {
|
||||
this.validRequest.compile.options.syncType = 'unexpected'
|
||||
this.RequestParser.parse(this.validRequest, this.callback)
|
||||
return (this.data = this.callback.args[0][1])
|
||||
})
|
||||
|
||||
return it('should return an error', function() {
|
||||
return it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith('syncType attribute should be one of: full, incremental')
|
||||
.should.equal(true)
|
||||
|
||||
@@ -20,8 +20,8 @@ const modulePath = require('path').join(
|
||||
const Path = require('path')
|
||||
const Errors = require('../../../app/js/Errors')
|
||||
|
||||
describe('ResourceStateManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('ResourceStateManager', function () {
|
||||
beforeEach(function () {
|
||||
this.ResourceStateManager = SandboxedModule.require(modulePath, {
|
||||
singleOnly: true,
|
||||
requires: {
|
||||
@@ -42,13 +42,13 @@ describe('ResourceStateManager', function() {
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('saveProjectState', function() {
|
||||
beforeEach(function() {
|
||||
describe('saveProjectState', function () {
|
||||
beforeEach(function () {
|
||||
return (this.fs.writeFile = sinon.stub().callsArg(2))
|
||||
})
|
||||
|
||||
describe('when the state is specified', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the state is specified', function () {
|
||||
beforeEach(function () {
|
||||
return this.ResourceStateManager.saveProjectState(
|
||||
this.state,
|
||||
this.resources,
|
||||
@@ -57,19 +57,19 @@ describe('ResourceStateManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should write the resource list to disk', function() {
|
||||
it('should write the resource list to disk', function () {
|
||||
return this.fs.writeFile
|
||||
.calledWith(this.resourceFileName, this.resourceFileContents)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the state is undefined', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when the state is undefined', function () {
|
||||
beforeEach(function () {
|
||||
this.state = undefined
|
||||
this.fs.unlink = sinon.stub().callsArg(1)
|
||||
return this.ResourceStateManager.saveProjectState(
|
||||
@@ -80,25 +80,25 @@ describe('ResourceStateManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should unlink the resource file', function() {
|
||||
it('should unlink the resource file', function () {
|
||||
return this.fs.unlink
|
||||
.calledWith(this.resourceFileName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not write the resource list to disk', function() {
|
||||
it('should not write the resource list to disk', function () {
|
||||
return this.fs.writeFile.called.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('checkProjectStateMatches', function() {
|
||||
describe('when the state matches', function() {
|
||||
beforeEach(function() {
|
||||
describe('checkProjectStateMatches', function () {
|
||||
describe('when the state matches', function () {
|
||||
beforeEach(function () {
|
||||
this.SafeReader.readFile = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, this.resourceFileContents)
|
||||
@@ -109,21 +109,21 @@ describe('ResourceStateManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should read the resource file', function() {
|
||||
it('should read the resource file', function () {
|
||||
return this.SafeReader.readFile
|
||||
.calledWith(this.resourceFileName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with the results', function() {
|
||||
return it('should call the callback with the results', function () {
|
||||
return this.callback
|
||||
.calledWithMatch(null, this.resources)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the state does not match', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when the state does not match', function () {
|
||||
beforeEach(function () {
|
||||
this.SafeReader.readFile = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, this.resourceFileContents)
|
||||
@@ -134,7 +134,7 @@ describe('ResourceStateManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
this.callback
|
||||
.calledWith(sinon.match(Errors.FilesOutOfSyncError))
|
||||
.should.equal(true)
|
||||
@@ -145,9 +145,9 @@ describe('ResourceStateManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('checkResourceFiles', function() {
|
||||
describe('when all the files are present', function() {
|
||||
beforeEach(function() {
|
||||
return describe('checkResourceFiles', function () {
|
||||
describe('when all the files are present', function () {
|
||||
beforeEach(function () {
|
||||
this.allFiles = [
|
||||
this.resources[0].path,
|
||||
this.resources[1].path,
|
||||
@@ -161,13 +161,13 @@ describe('ResourceStateManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.calledWithExactly().should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is a missing file', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there is a missing file', function () {
|
||||
beforeEach(function () {
|
||||
this.allFiles = [this.resources[0].path, this.resources[1].path]
|
||||
this.fs.stat = sinon.stub().callsArgWith(1, new Error())
|
||||
return this.ResourceStateManager.checkResourceFiles(
|
||||
@@ -178,7 +178,7 @@ describe('ResourceStateManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
this.callback
|
||||
.calledWith(sinon.match(Errors.FilesOutOfSyncError))
|
||||
.should.equal(true)
|
||||
@@ -190,8 +190,8 @@ describe('ResourceStateManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when a resource contains a relative path', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when a resource contains a relative path', function () {
|
||||
beforeEach(function () {
|
||||
this.resources[0].path = '../foo/bar.tex'
|
||||
this.allFiles = [
|
||||
this.resources[0].path,
|
||||
@@ -206,7 +206,7 @@ describe('ResourceStateManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
this.callback.calledWith(sinon.match(Error)).should.equal(true)
|
||||
|
||||
const message = this.callback.args[0][0].message
|
||||
|
||||
@@ -20,8 +20,8 @@ const modulePath = require('path').join(
|
||||
)
|
||||
const path = require('path')
|
||||
|
||||
describe('ResourceWriter', function() {
|
||||
beforeEach(function() {
|
||||
describe('ResourceWriter', function () {
|
||||
beforeEach(function () {
|
||||
let Timer
|
||||
this.ResourceWriter = SandboxedModule.require(modulePath, {
|
||||
singleOnly: true,
|
||||
@@ -37,7 +37,7 @@ describe('ResourceWriter', function() {
|
||||
'logger-sharelatex': { log: sinon.stub(), err: sinon.stub() },
|
||||
'./Metrics': (this.Metrics = {
|
||||
inc: sinon.stub(),
|
||||
Timer: (Timer = (function() {
|
||||
Timer: (Timer = (function () {
|
||||
Timer = class Timer {
|
||||
static initClass() {
|
||||
this.prototype.done = sinon.stub()
|
||||
@@ -54,8 +54,8 @@ describe('ResourceWriter', function() {
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('syncResourcesToDisk on a full request', function() {
|
||||
beforeEach(function() {
|
||||
describe('syncResourcesToDisk on a full request', function () {
|
||||
beforeEach(function () {
|
||||
this.resources = ['resource-1-mock', 'resource-2-mock', 'resource-3-mock']
|
||||
this.ResourceWriter._writeResourceToDisk = sinon.stub().callsArg(3)
|
||||
this.ResourceWriter._removeExtraneousFiles = sinon.stub().callsArg(2)
|
||||
@@ -71,33 +71,33 @@ describe('ResourceWriter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should remove old files', function() {
|
||||
it('should remove old files', function () {
|
||||
return this.ResourceWriter._removeExtraneousFiles
|
||||
.calledWith(this.resources, this.basePath)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should write each resource to disk', function() {
|
||||
return Array.from(this.resources).map(resource =>
|
||||
it('should write each resource to disk', function () {
|
||||
return Array.from(this.resources).map((resource) =>
|
||||
this.ResourceWriter._writeResourceToDisk
|
||||
.calledWith(this.project_id, resource, this.basePath)
|
||||
.should.equal(true)
|
||||
)
|
||||
})
|
||||
|
||||
it('should store the sync state and resource list', function() {
|
||||
it('should store the sync state and resource list', function () {
|
||||
return this.ResourceStateManager.saveProjectState
|
||||
.calledWith(this.syncState, this.resources, this.basePath)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('syncResourcesToDisk on an incremental update', function() {
|
||||
beforeEach(function() {
|
||||
describe('syncResourcesToDisk on an incremental update', function () {
|
||||
beforeEach(function () {
|
||||
this.resources = ['resource-1-mock']
|
||||
this.ResourceWriter._writeResourceToDisk = sinon.stub().callsArg(3)
|
||||
this.ResourceWriter._removeExtraneousFiles = sinon
|
||||
@@ -120,39 +120,39 @@ describe('ResourceWriter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should check the sync state matches', function() {
|
||||
it('should check the sync state matches', function () {
|
||||
return this.ResourceStateManager.checkProjectStateMatches
|
||||
.calledWith(this.syncState, this.basePath)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should remove old files', function() {
|
||||
it('should remove old files', function () {
|
||||
return this.ResourceWriter._removeExtraneousFiles
|
||||
.calledWith(this.resources, this.basePath)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should check each resource exists', function() {
|
||||
it('should check each resource exists', function () {
|
||||
return this.ResourceStateManager.checkResourceFiles
|
||||
.calledWith(this.resources, this.allFiles, this.basePath)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should write each resource to disk', function() {
|
||||
return Array.from(this.resources).map(resource =>
|
||||
it('should write each resource to disk', function () {
|
||||
return Array.from(this.resources).map((resource) =>
|
||||
this.ResourceWriter._writeResourceToDisk
|
||||
.calledWith(this.project_id, resource, this.basePath)
|
||||
.should.equal(true)
|
||||
)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('syncResourcesToDisk on an incremental update when the state does not match', function() {
|
||||
beforeEach(function() {
|
||||
describe('syncResourcesToDisk on an incremental update when the state does not match', function () {
|
||||
beforeEach(function () {
|
||||
this.resources = ['resource-1-mock']
|
||||
this.ResourceStateManager.checkProjectStateMatches = sinon
|
||||
.stub()
|
||||
@@ -169,19 +169,19 @@ describe('ResourceWriter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should check whether the sync state matches', function() {
|
||||
it('should check whether the sync state matches', function () {
|
||||
return this.ResourceStateManager.checkProjectStateMatches
|
||||
.calledWith(this.syncState, this.basePath)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with an error', function() {
|
||||
return it('should call the callback with an error', function () {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('_removeExtraneousFiles', function() {
|
||||
beforeEach(function() {
|
||||
describe('_removeExtraneousFiles', function () {
|
||||
beforeEach(function () {
|
||||
this.output_files = [
|
||||
{
|
||||
path: 'output.pdf',
|
||||
@@ -250,49 +250,49 @@ describe('ResourceWriter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should find the existing output files', function() {
|
||||
it('should find the existing output files', function () {
|
||||
return this.OutputFileFinder.findOutputFiles
|
||||
.calledWith(this.resources, this.basePath)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should delete the output files', function() {
|
||||
it('should delete the output files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'output.pdf'))
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should delete the stdout log file', function() {
|
||||
it('should delete the stdout log file', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'output.stdout'))
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should delete the stderr log file', function() {
|
||||
it('should delete the stderr log file', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'output.stderr'))
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should delete the extra files', function() {
|
||||
it('should delete the extra files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'extra/file.tex'))
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not delete the extra aux files', function() {
|
||||
it('should not delete the extra aux files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'extra.aux'))
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the knitr cache file', function() {
|
||||
it('should not delete the knitr cache file', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'cache/_chunk1'))
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the epstopdf converted files', function() {
|
||||
it('should not delete the epstopdf converted files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(
|
||||
path.join(this.basePath, 'figures/image-eps-converted-to.pdf')
|
||||
@@ -300,25 +300,25 @@ describe('ResourceWriter', function() {
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the tikz md5 files', function() {
|
||||
it('should not delete the tikz md5 files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'foo/main-figure0.md5'))
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the tikz dpth files', function() {
|
||||
it('should not delete the tikz dpth files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'foo/main-figure0.dpth'))
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the tikz pdf files', function() {
|
||||
it('should not delete the tikz pdf files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, 'foo/main-figure0.pdf'))
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the minted pygstyle files', function() {
|
||||
it('should not delete the minted pygstyle files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(
|
||||
path.join(this.basePath, '_minted-main/default-pyg-prefix.pygstyle')
|
||||
@@ -326,13 +326,13 @@ describe('ResourceWriter', function() {
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the minted default pygstyle files', function() {
|
||||
it('should not delete the minted default pygstyle files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(path.join(this.basePath, '_minted-main/default.pygstyle'))
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the minted default pygtex files', function() {
|
||||
it('should not delete the minted default pygtex files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(
|
||||
path.join(
|
||||
@@ -343,7 +343,7 @@ describe('ResourceWriter', function() {
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not delete the markdown md.tex files', function() {
|
||||
it('should not delete the markdown md.tex files', function () {
|
||||
return this.ResourceWriter._deleteFileIfNotDirectory
|
||||
.calledWith(
|
||||
path.join(
|
||||
@@ -354,18 +354,18 @@ describe('ResourceWriter', function() {
|
||||
.should.equal(false)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should time the request', function() {
|
||||
return it('should time the request', function () {
|
||||
return this.Metrics.Timer.prototype.done.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('_writeResourceToDisk', function() {
|
||||
describe('with a url based resource', function() {
|
||||
beforeEach(function() {
|
||||
describe('_writeResourceToDisk', function () {
|
||||
describe('with a url based resource', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.mkdir = sinon.stub().callsArg(2)
|
||||
this.resource = {
|
||||
path: 'main.tex',
|
||||
@@ -383,7 +383,7 @@ describe('ResourceWriter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should ensure the directory exists', function() {
|
||||
it('should ensure the directory exists', function () {
|
||||
this.fs.mkdir
|
||||
.calledWith(
|
||||
path.dirname(path.join(this.basePath, this.resource.path))
|
||||
@@ -391,7 +391,7 @@ describe('ResourceWriter', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should write the URL from the cache', function() {
|
||||
it('should write the URL from the cache', function () {
|
||||
return this.UrlCache.downloadUrlToFile
|
||||
.calledWith(
|
||||
this.project_id,
|
||||
@@ -402,17 +402,17 @@ describe('ResourceWriter', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should not return an error if the resource writer errored', function() {
|
||||
return it('should not return an error if the resource writer errored', function () {
|
||||
return should.not.exist(this.callback.args[0][0])
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a content based resource', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a content based resource', function () {
|
||||
beforeEach(function () {
|
||||
this.resource = {
|
||||
path: 'main.tex',
|
||||
content: 'Hello world'
|
||||
@@ -427,7 +427,7 @@ describe('ResourceWriter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should ensure the directory exists', function() {
|
||||
it('should ensure the directory exists', function () {
|
||||
return this.fs.mkdir
|
||||
.calledWith(
|
||||
path.dirname(path.join(this.basePath, this.resource.path))
|
||||
@@ -435,7 +435,7 @@ describe('ResourceWriter', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should write the contents to disk', function() {
|
||||
it('should write the contents to disk', function () {
|
||||
return this.fs.writeFile
|
||||
.calledWith(
|
||||
path.join(this.basePath, this.resource.path),
|
||||
@@ -444,13 +444,13 @@ describe('ResourceWriter', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with a file path that breaks out of the root folder', function() {
|
||||
beforeEach(function() {
|
||||
return describe('with a file path that breaks out of the root folder', function () {
|
||||
beforeEach(function () {
|
||||
this.resource = {
|
||||
path: '../../main.tex',
|
||||
content: 'Hello world'
|
||||
@@ -464,11 +464,11 @@ describe('ResourceWriter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not write to disk', function() {
|
||||
it('should not write to disk', function () {
|
||||
return this.fs.writeFile.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('should return an error', function() {
|
||||
it('should return an error', function () {
|
||||
this.callback.calledWith(sinon.match(Error)).should.equal(true)
|
||||
|
||||
const message = this.callback.args[0][0].message
|
||||
@@ -477,23 +477,23 @@ describe('ResourceWriter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('checkPath', function() {
|
||||
describe('with a valid path', function() {
|
||||
beforeEach(function() {
|
||||
return describe('checkPath', function () {
|
||||
describe('with a valid path', function () {
|
||||
beforeEach(function () {
|
||||
return this.ResourceWriter.checkPath('foo', 'bar', this.callback)
|
||||
})
|
||||
|
||||
return it('should return the joined path', function() {
|
||||
return it('should return the joined path', function () {
|
||||
return this.callback.calledWith(null, 'foo/bar').should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an invalid path', function() {
|
||||
beforeEach(function() {
|
||||
describe('with an invalid path', function () {
|
||||
beforeEach(function () {
|
||||
this.ResourceWriter.checkPath('foo', 'baz/../../bar', this.callback)
|
||||
})
|
||||
|
||||
it('should return an error', function() {
|
||||
it('should return an error', function () {
|
||||
this.callback.calledWith(sinon.match(Error)).should.equal(true)
|
||||
|
||||
const message = this.callback.args[0][0].message
|
||||
@@ -501,8 +501,8 @@ describe('ResourceWriter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with another invalid path matching on a prefix', function() {
|
||||
beforeEach(function() {
|
||||
describe('with another invalid path matching on a prefix', function () {
|
||||
beforeEach(function () {
|
||||
return this.ResourceWriter.checkPath(
|
||||
'foo',
|
||||
'../foobar/baz',
|
||||
@@ -510,7 +510,7 @@ describe('ResourceWriter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an error', function() {
|
||||
it('should return an error', function () {
|
||||
this.callback.calledWith(sinon.match(Error)).should.equal(true)
|
||||
|
||||
const message = this.callback.args[0][0].message
|
||||
|
||||
@@ -20,8 +20,8 @@ const modulePath = path.join(
|
||||
)
|
||||
const { expect } = require('chai')
|
||||
|
||||
describe('StaticServerForbidSymlinks', function() {
|
||||
beforeEach(function() {
|
||||
describe('StaticServerForbidSymlinks', function () {
|
||||
beforeEach(function () {
|
||||
this.settings = {
|
||||
path: {
|
||||
compilesDir: '/compiles/here'
|
||||
@@ -60,8 +60,8 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
return (this.req.url = '/12345/output.pdf')
|
||||
})
|
||||
|
||||
describe('sending a normal file through', function() {
|
||||
beforeEach(function() {
|
||||
describe('sending a normal file through', function () {
|
||||
beforeEach(function () {
|
||||
return (this.fs.realpath = sinon
|
||||
.stub()
|
||||
.callsArgWith(
|
||||
@@ -71,8 +71,8 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
))
|
||||
})
|
||||
|
||||
return it('should call next', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should call next', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(200)
|
||||
return done()
|
||||
}
|
||||
@@ -80,8 +80,8 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a missing file', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a missing file', function () {
|
||||
beforeEach(function () {
|
||||
return (this.fs.realpath = sinon
|
||||
.stub()
|
||||
.callsArgWith(
|
||||
@@ -91,8 +91,8 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
))
|
||||
})
|
||||
|
||||
return it('should send a 404', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 404', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
@@ -100,15 +100,15 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a symlink file', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a symlink file', function () {
|
||||
beforeEach(function () {
|
||||
return (this.fs.realpath = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, `/etc/${this.req.params.project_id}/output.pdf`))
|
||||
})
|
||||
|
||||
return it('should send a 404', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 404', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
@@ -116,13 +116,13 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a relative file', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a relative file', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.url = '/12345/../67890/output.pdf')
|
||||
})
|
||||
|
||||
return it('should send a 404', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 404', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
@@ -130,13 +130,13 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a unnormalized file containing .', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a unnormalized file containing .', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.url = '/12345/foo/./output.pdf')
|
||||
})
|
||||
|
||||
return it('should send a 404', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 404', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
@@ -144,13 +144,13 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a file containing an empty path', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a file containing an empty path', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.url = '/12345/foo//output.pdf')
|
||||
})
|
||||
|
||||
return it('should send a 404', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 404', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
@@ -158,13 +158,13 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a non-project file', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a non-project file', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.url = '/.foo/output.pdf')
|
||||
})
|
||||
|
||||
return it('should send a 404', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 404', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
@@ -172,13 +172,13 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a file outside the compiledir', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a file outside the compiledir', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.url = '/../bar/output.pdf')
|
||||
})
|
||||
|
||||
return it('should send a 404', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 404', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
@@ -186,13 +186,13 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a file with no leading /', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a file with no leading /', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.url = './../bar/output.pdf')
|
||||
})
|
||||
|
||||
return it('should send a 404', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 404', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
@@ -200,8 +200,8 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a github style path', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a github style path', function () {
|
||||
beforeEach(function () {
|
||||
this.req.url = '/henryoswald-latex_example/output/output.log'
|
||||
return (this.fs.realpath = sinon
|
||||
.stub()
|
||||
@@ -212,8 +212,8 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
))
|
||||
})
|
||||
|
||||
return it('should call next', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should call next', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(200)
|
||||
return done()
|
||||
}
|
||||
@@ -221,13 +221,13 @@ describe('StaticServerForbidSymlinks', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with an error from fs.realpath', function() {
|
||||
beforeEach(function() {
|
||||
return describe('with an error from fs.realpath', function () {
|
||||
beforeEach(function () {
|
||||
return (this.fs.realpath = sinon.stub().callsArgWith(1, 'error'))
|
||||
})
|
||||
|
||||
return it('should send a 500', function(done) {
|
||||
this.res.sendStatus = function(resCode) {
|
||||
return it('should send a 500', function (done) {
|
||||
this.res.sendStatus = function (resCode) {
|
||||
resCode.should.equal(500)
|
||||
return done()
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ const modulePath = require('path').join(
|
||||
'../../../app/js/TikzManager'
|
||||
)
|
||||
|
||||
describe('TikzManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('TikzManager', function () {
|
||||
beforeEach(function () {
|
||||
return (this.TikzManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./ResourceWriter': (this.ResourceWriter = {}),
|
||||
@@ -28,15 +28,15 @@ describe('TikzManager', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
describe('checkMainFile', function() {
|
||||
beforeEach(function() {
|
||||
describe('checkMainFile', function () {
|
||||
beforeEach(function () {
|
||||
this.compileDir = 'compile-dir'
|
||||
this.mainFile = 'main.tex'
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('if there is already an output.tex file in the resources', function() {
|
||||
beforeEach(function() {
|
||||
describe('if there is already an output.tex file in the resources', function () {
|
||||
beforeEach(function () {
|
||||
this.resources = [{ path: 'main.tex' }, { path: 'output.tex' }]
|
||||
return this.TikzManager.checkMainFile(
|
||||
this.compileDir,
|
||||
@@ -46,13 +46,13 @@ describe('TikzManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should call the callback with false ', function() {
|
||||
return it('should call the callback with false ', function () {
|
||||
return this.callback.calledWithExactly(null, false).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('if there is no output.tex file in the resources', function() {
|
||||
beforeEach(function() {
|
||||
return describe('if there is no output.tex file in the resources', function () {
|
||||
beforeEach(function () {
|
||||
this.resources = [{ path: 'main.tex' }]
|
||||
return (this.ResourceWriter.checkPath = sinon
|
||||
.stub()
|
||||
@@ -60,8 +60,8 @@ describe('TikzManager', function() {
|
||||
.callsArgWith(2, null, `${this.compileDir}/${this.mainFile}`))
|
||||
})
|
||||
|
||||
describe('and the main file contains tikzexternalize', function() {
|
||||
beforeEach(function() {
|
||||
describe('and the main file contains tikzexternalize', function () {
|
||||
beforeEach(function () {
|
||||
this.SafeReader.readFile = sinon
|
||||
.stub()
|
||||
.withArgs(`${this.compileDir}/${this.mainFile}`)
|
||||
@@ -74,19 +74,19 @@ describe('TikzManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should look at the file on disk', function() {
|
||||
it('should look at the file on disk', function () {
|
||||
return this.SafeReader.readFile
|
||||
.calledWith(`${this.compileDir}/${this.mainFile}`)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with true ', function() {
|
||||
return it('should call the callback with true ', function () {
|
||||
return this.callback.calledWithExactly(null, true).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('and the main file does not contain tikzexternalize', function() {
|
||||
beforeEach(function() {
|
||||
describe('and the main file does not contain tikzexternalize', function () {
|
||||
beforeEach(function () {
|
||||
this.SafeReader.readFile = sinon
|
||||
.stub()
|
||||
.withArgs(`${this.compileDir}/${this.mainFile}`)
|
||||
@@ -99,19 +99,19 @@ describe('TikzManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should look at the file on disk', function() {
|
||||
it('should look at the file on disk', function () {
|
||||
return this.SafeReader.readFile
|
||||
.calledWith(`${this.compileDir}/${this.mainFile}`)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with false', function() {
|
||||
return it('should call the callback with false', function () {
|
||||
return this.callback.calledWithExactly(null, false).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('and the main file contains \\usepackage{pstool}', function() {
|
||||
beforeEach(function() {
|
||||
return describe('and the main file contains \\usepackage{pstool}', function () {
|
||||
beforeEach(function () {
|
||||
this.SafeReader.readFile = sinon
|
||||
.stub()
|
||||
.withArgs(`${this.compileDir}/${this.mainFile}`)
|
||||
@@ -124,21 +124,21 @@ describe('TikzManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should look at the file on disk', function() {
|
||||
it('should look at the file on disk', function () {
|
||||
return this.SafeReader.readFile
|
||||
.calledWith(`${this.compileDir}/${this.mainFile}`)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback with true ', function() {
|
||||
return it('should call the callback with true ', function () {
|
||||
return this.callback.calledWithExactly(null, true).should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return describe('injectOutputFile', function() {
|
||||
beforeEach(function() {
|
||||
return describe('injectOutputFile', function () {
|
||||
beforeEach(function () {
|
||||
this.rootDir = '/mock'
|
||||
this.filename = 'filename.tex'
|
||||
this.callback = sinon.stub()
|
||||
@@ -162,25 +162,25 @@ Hello world
|
||||
)
|
||||
})
|
||||
|
||||
it('sould check the path', function() {
|
||||
it('sould check the path', function () {
|
||||
return this.ResourceWriter.checkPath
|
||||
.calledWith(this.rootDir, this.filename)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should read the file', function() {
|
||||
it('should read the file', function () {
|
||||
return this.fs.readFile
|
||||
.calledWith(`${this.rootDir}/${this.filename}`, 'utf8')
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should write out the same file as output.tex', function() {
|
||||
it('should write out the same file as output.tex', function () {
|
||||
return this.fs.writeFile
|
||||
.calledWith(`${this.rootDir}/output.tex`, this.content, { flag: 'wx' })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -16,8 +16,8 @@ require('chai').should()
|
||||
const modulePath = require('path').join(__dirname, '../../../app/js/UrlCache')
|
||||
const { EventEmitter } = require('events')
|
||||
|
||||
describe('UrlCache', function() {
|
||||
beforeEach(function() {
|
||||
describe('UrlCache', function () {
|
||||
beforeEach(function () {
|
||||
this.callback = sinon.stub()
|
||||
this.url = 'www.example.com/file'
|
||||
this.project_id = 'project-id-123'
|
||||
@@ -34,16 +34,16 @@ describe('UrlCache', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
describe('_doesUrlNeedDownloading', function() {
|
||||
beforeEach(function() {
|
||||
describe('_doesUrlNeedDownloading', function () {
|
||||
beforeEach(function () {
|
||||
this.lastModified = new Date()
|
||||
return (this.lastModifiedRoundedToSeconds = new Date(
|
||||
Math.floor(this.lastModified.getTime() / 1000) * 1000
|
||||
))
|
||||
})
|
||||
|
||||
describe('when URL does not exist in cache', function() {
|
||||
beforeEach(function() {
|
||||
describe('when URL does not exist in cache', function () {
|
||||
beforeEach(function () {
|
||||
this.UrlCache._findUrlDetails = sinon.stub().callsArgWith(2, null, null)
|
||||
return this.UrlCache._doesUrlNeedDownloading(
|
||||
this.project_id,
|
||||
@@ -53,21 +53,21 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should return the callback with true', function() {
|
||||
return it('should return the callback with true', function () {
|
||||
return this.callback.calledWith(null, true).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when URL does exist in cache', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when URL does exist in cache', function () {
|
||||
beforeEach(function () {
|
||||
this.urlDetails = {}
|
||||
return (this.UrlCache._findUrlDetails = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, this.urlDetails))
|
||||
})
|
||||
|
||||
describe('when the modified date is more recent than the cached modified date', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the modified date is more recent than the cached modified date', function () {
|
||||
beforeEach(function () {
|
||||
this.urlDetails.lastModified = new Date(
|
||||
this.lastModified.getTime() - 1000
|
||||
)
|
||||
@@ -79,19 +79,19 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should get the url details', function() {
|
||||
it('should get the url details', function () {
|
||||
return this.UrlCache._findUrlDetails
|
||||
.calledWith(this.project_id, this.url)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the callback with true', function() {
|
||||
return it('should return the callback with true', function () {
|
||||
return this.callback.calledWith(null, true).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the cached modified date is more recent than the modified date', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the cached modified date is more recent than the modified date', function () {
|
||||
beforeEach(function () {
|
||||
this.urlDetails.lastModified = new Date(
|
||||
this.lastModified.getTime() + 1000
|
||||
)
|
||||
@@ -103,13 +103,13 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should return the callback with false', function() {
|
||||
return it('should return the callback with false', function () {
|
||||
return this.callback.calledWith(null, false).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the cached modified date is equal to the modified date', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the cached modified date is equal to the modified date', function () {
|
||||
beforeEach(function () {
|
||||
this.urlDetails.lastModified = this.lastModified
|
||||
return this.UrlCache._doesUrlNeedDownloading(
|
||||
this.project_id,
|
||||
@@ -119,13 +119,13 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should return the callback with false', function() {
|
||||
return it('should return the callback with false', function () {
|
||||
return this.callback.calledWith(null, false).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the provided modified date does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the provided modified date does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.lastModified = null
|
||||
return this.UrlCache._doesUrlNeedDownloading(
|
||||
this.project_id,
|
||||
@@ -135,13 +135,13 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should return the callback with true', function() {
|
||||
return it('should return the callback with true', function () {
|
||||
return this.callback.calledWith(null, true).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the URL does not have a modified date', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when the URL does not have a modified date', function () {
|
||||
beforeEach(function () {
|
||||
this.urlDetails.lastModified = null
|
||||
return this.UrlCache._doesUrlNeedDownloading(
|
||||
this.project_id,
|
||||
@@ -151,23 +151,23 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
return it('should return the callback with true', function() {
|
||||
return it('should return the callback with true', function () {
|
||||
return this.callback.calledWith(null, true).should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('_ensureUrlIsInCache', function() {
|
||||
beforeEach(function() {
|
||||
describe('_ensureUrlIsInCache', function () {
|
||||
beforeEach(function () {
|
||||
this.UrlFetcher.pipeUrlToFileWithRetry = sinon.stub().callsArg(2)
|
||||
return (this.UrlCache._updateOrCreateUrlDetails = sinon
|
||||
.stub()
|
||||
.callsArg(3))
|
||||
})
|
||||
|
||||
describe('when the URL needs updating', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the URL needs updating', function () {
|
||||
beforeEach(function () {
|
||||
this.UrlCache._doesUrlNeedDownloading = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, true)
|
||||
@@ -179,7 +179,7 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should check that the url needs downloading', function() {
|
||||
it('should check that the url needs downloading', function () {
|
||||
return this.UrlCache._doesUrlNeedDownloading
|
||||
.calledWith(
|
||||
this.project_id,
|
||||
@@ -189,7 +189,7 @@ describe('UrlCache', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should download the URL to the cache file', function() {
|
||||
it('should download the URL to the cache file', function () {
|
||||
return this.UrlFetcher.pipeUrlToFileWithRetry
|
||||
.calledWith(
|
||||
this.url,
|
||||
@@ -198,7 +198,7 @@ describe('UrlCache', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should update the database entry', function() {
|
||||
it('should update the database entry', function () {
|
||||
return this.UrlCache._updateOrCreateUrlDetails
|
||||
.calledWith(
|
||||
this.project_id,
|
||||
@@ -208,7 +208,7 @@ describe('UrlCache', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the callback with the cache file path', function() {
|
||||
return it('should return the callback with the cache file path', function () {
|
||||
return this.callback
|
||||
.calledWith(
|
||||
null,
|
||||
@@ -218,8 +218,8 @@ describe('UrlCache', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the URL does not need updating', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when the URL does not need updating', function () {
|
||||
beforeEach(function () {
|
||||
this.UrlCache._doesUrlNeedDownloading = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, false)
|
||||
@@ -231,11 +231,11 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not download the URL to the cache file', function() {
|
||||
it('should not download the URL to the cache file', function () {
|
||||
return this.UrlFetcher.pipeUrlToFileWithRetry.called.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should return the callback with the cache file path', function() {
|
||||
return it('should return the callback with the cache file path', function () {
|
||||
return this.callback
|
||||
.calledWith(
|
||||
null,
|
||||
@@ -246,8 +246,8 @@ describe('UrlCache', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('downloadUrlToFile', function() {
|
||||
beforeEach(function() {
|
||||
describe('downloadUrlToFile', function () {
|
||||
beforeEach(function () {
|
||||
this.cachePath = 'path/to/cached/url'
|
||||
this.destPath = 'path/to/destination'
|
||||
this.UrlCache._copyFile = sinon.stub().callsArg(2)
|
||||
@@ -263,25 +263,25 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should ensure the URL is downloaded and updated in the cache', function() {
|
||||
it('should ensure the URL is downloaded and updated in the cache', function () {
|
||||
return this.UrlCache._ensureUrlIsInCache
|
||||
.calledWith(this.project_id, this.url, this.lastModified)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should copy the file to the new location', function() {
|
||||
it('should copy the file to the new location', function () {
|
||||
return this.UrlCache._copyFile
|
||||
.calledWith(this.cachePath, this.destPath)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('_deleteUrlCacheFromDisk', function() {
|
||||
beforeEach(function() {
|
||||
describe('_deleteUrlCacheFromDisk', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.unlink = sinon.stub().callsArg(1)
|
||||
return this.UrlCache._deleteUrlCacheFromDisk(
|
||||
this.project_id,
|
||||
@@ -290,7 +290,7 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should delete the cache file', function() {
|
||||
it('should delete the cache file', function () {
|
||||
return this.fs.unlink
|
||||
.calledWith(
|
||||
this.UrlCache._cacheFilePathForUrl(this.project_id, this.url)
|
||||
@@ -298,13 +298,13 @@ describe('UrlCache', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('_clearUrlFromCache', function() {
|
||||
beforeEach(function() {
|
||||
describe('_clearUrlFromCache', function () {
|
||||
beforeEach(function () {
|
||||
this.UrlCache._deleteUrlCacheFromDisk = sinon.stub().callsArg(2)
|
||||
this.UrlCache._clearUrlDetails = sinon.stub().callsArg(2)
|
||||
return this.UrlCache._clearUrlFromCache(
|
||||
@@ -314,25 +314,25 @@ describe('UrlCache', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should delete the file on disk', function() {
|
||||
it('should delete the file on disk', function () {
|
||||
return this.UrlCache._deleteUrlCacheFromDisk
|
||||
.calledWith(this.project_id, this.url)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should clear the entry in the database', function() {
|
||||
it('should clear the entry in the database', function () {
|
||||
return this.UrlCache._clearUrlDetails
|
||||
.calledWith(this.project_id, this.url)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('clearProject', function() {
|
||||
beforeEach(function() {
|
||||
return describe('clearProject', function () {
|
||||
beforeEach(function () {
|
||||
this.urls = ['www.example.com/file1', 'www.example.com/file2']
|
||||
this.UrlCache._findAllUrlsInProject = sinon
|
||||
.stub()
|
||||
@@ -341,15 +341,15 @@ describe('UrlCache', function() {
|
||||
return this.UrlCache.clearProject(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should clear the cache for each url in the project', function() {
|
||||
return Array.from(this.urls).map(url =>
|
||||
it('should clear the cache for each url in the project', function () {
|
||||
return Array.from(this.urls).map((url) =>
|
||||
this.UrlCache._clearUrlFromCache
|
||||
.calledWith(this.project_id, url)
|
||||
.should.equal(true)
|
||||
)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -15,8 +15,8 @@ require('chai').should()
|
||||
const modulePath = require('path').join(__dirname, '../../../app/js/UrlFetcher')
|
||||
const { EventEmitter } = require('events')
|
||||
|
||||
describe('UrlFetcher', function() {
|
||||
beforeEach(function() {
|
||||
describe('UrlFetcher', function () {
|
||||
beforeEach(function () {
|
||||
this.callback = sinon.stub()
|
||||
this.url = 'https://www.example.com/file/here?query=string'
|
||||
return (this.UrlFetcher = SandboxedModule.require(modulePath, {
|
||||
@@ -33,34 +33,34 @@ describe('UrlFetcher', function() {
|
||||
}
|
||||
}))
|
||||
})
|
||||
describe('pipeUrlToFileWithRetry', function() {
|
||||
this.beforeEach(function() {
|
||||
describe('pipeUrlToFileWithRetry', function () {
|
||||
this.beforeEach(function () {
|
||||
this.UrlFetcher.pipeUrlToFile = sinon.stub()
|
||||
})
|
||||
|
||||
it('should call pipeUrlToFile', function(done) {
|
||||
it('should call pipeUrlToFile', function (done) {
|
||||
this.UrlFetcher.pipeUrlToFile.callsArgWith(2)
|
||||
this.UrlFetcher.pipeUrlToFileWithRetry(this.url, this.path, err => {
|
||||
this.UrlFetcher.pipeUrlToFileWithRetry(this.url, this.path, (err) => {
|
||||
expect(err).to.equal(undefined)
|
||||
this.UrlFetcher.pipeUrlToFile.called.should.equal(true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should call pipeUrlToFile multiple times on error', function(done) {
|
||||
it('should call pipeUrlToFile multiple times on error', function (done) {
|
||||
const error = new Error("couldn't download file")
|
||||
this.UrlFetcher.pipeUrlToFile.callsArgWith(2, error)
|
||||
this.UrlFetcher.pipeUrlToFileWithRetry(this.url, this.path, err => {
|
||||
this.UrlFetcher.pipeUrlToFileWithRetry(this.url, this.path, (err) => {
|
||||
expect(err).to.equal(error)
|
||||
this.UrlFetcher.pipeUrlToFile.callCount.should.equal(3)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should call pipeUrlToFile twice if only 1 error', function(done) {
|
||||
it('should call pipeUrlToFile twice if only 1 error', function (done) {
|
||||
this.UrlFetcher.pipeUrlToFile.onCall(0).callsArgWith(2, 'error')
|
||||
this.UrlFetcher.pipeUrlToFile.onCall(1).callsArgWith(2)
|
||||
this.UrlFetcher.pipeUrlToFileWithRetry(this.url, this.path, err => {
|
||||
this.UrlFetcher.pipeUrlToFileWithRetry(this.url, this.path, (err) => {
|
||||
expect(err).to.equal(undefined)
|
||||
this.UrlFetcher.pipeUrlToFile.callCount.should.equal(2)
|
||||
done()
|
||||
@@ -68,13 +68,13 @@ describe('UrlFetcher', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('pipeUrlToFile', function() {
|
||||
it('should turn off the cookie jar in request', function() {
|
||||
describe('pipeUrlToFile', function () {
|
||||
it('should turn off the cookie jar in request', function () {
|
||||
return this.defaults.calledWith({ jar: false }).should.equal(true)
|
||||
})
|
||||
|
||||
describe('rewrite url domain if filestoreDomainOveride is set', function() {
|
||||
beforeEach(function() {
|
||||
describe('rewrite url domain if filestoreDomainOveride is set', function () {
|
||||
beforeEach(function () {
|
||||
this.path = '/path/to/file/on/disk'
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
@@ -88,7 +88,7 @@ describe('UrlFetcher', function() {
|
||||
return (this.fs.unlink = (file, callback) => callback())
|
||||
})
|
||||
|
||||
it('should use the normal domain when override not set', function(done) {
|
||||
it('should use the normal domain when override not set', function (done) {
|
||||
this.UrlFetcher.pipeUrlToFile(this.url, this.path, () => {
|
||||
this.request.get.args[0][0].url.should.equal(this.url)
|
||||
return done()
|
||||
@@ -99,7 +99,7 @@ describe('UrlFetcher', function() {
|
||||
return this.fileStream.emit('finish')
|
||||
})
|
||||
|
||||
return it('should use override domain when filestoreDomainOveride is set', function(done) {
|
||||
return it('should use override domain when filestoreDomainOveride is set', function (done) {
|
||||
this.settings.filestoreDomainOveride = '192.11.11.11'
|
||||
this.UrlFetcher.pipeUrlToFile(this.url, this.path, () => {
|
||||
this.request.get.args[0][0].url.should.equal(
|
||||
@@ -114,8 +114,8 @@ describe('UrlFetcher', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('pipeUrlToFile', function() {
|
||||
beforeEach(function(done) {
|
||||
return describe('pipeUrlToFile', function () {
|
||||
beforeEach(function (done) {
|
||||
this.path = '/path/to/file/on/disk'
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
@@ -130,8 +130,8 @@ describe('UrlFetcher', function() {
|
||||
return done()
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('successfully', function () {
|
||||
beforeEach(function (done) {
|
||||
this.UrlFetcher.pipeUrlToFile(this.url, this.path, () => {
|
||||
this.callback()
|
||||
return done()
|
||||
@@ -142,32 +142,32 @@ describe('UrlFetcher', function() {
|
||||
return this.fileStream.emit('finish')
|
||||
})
|
||||
|
||||
it('should request the URL', function() {
|
||||
it('should request the URL', function () {
|
||||
return this.request.get
|
||||
.calledWith(sinon.match({ url: this.url }))
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should open the file for writing', function() {
|
||||
it('should open the file for writing', function () {
|
||||
return this.fs.createWriteStream
|
||||
.calledWith(this.path)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should pipe the URL to the file', function() {
|
||||
it('should pipe the URL to the file', function () {
|
||||
return this.urlStream.pipe
|
||||
.calledWith(this.fileStream)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should call the callback', function() {
|
||||
return it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with non success status code', function() {
|
||||
beforeEach(function(done) {
|
||||
this.UrlFetcher.pipeUrlToFile(this.url, this.path, err => {
|
||||
describe('with non success status code', function () {
|
||||
beforeEach(function (done) {
|
||||
this.UrlFetcher.pipeUrlToFile(this.url, this.path, (err) => {
|
||||
this.callback(err)
|
||||
return done()
|
||||
})
|
||||
@@ -176,7 +176,7 @@ describe('UrlFetcher', function() {
|
||||
return this.urlStream.emit('end')
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
this.callback.calledWith(sinon.match(Error)).should.equal(true)
|
||||
|
||||
const message = this.callback.args[0][0].message
|
||||
@@ -186,9 +186,9 @@ describe('UrlFetcher', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with error', function() {
|
||||
beforeEach(function(done) {
|
||||
this.UrlFetcher.pipeUrlToFile(this.url, this.path, err => {
|
||||
return describe('with error', function () {
|
||||
beforeEach(function (done) {
|
||||
this.UrlFetcher.pipeUrlToFile(this.url, this.path, (err) => {
|
||||
this.callback(err)
|
||||
return done()
|
||||
})
|
||||
@@ -198,11 +198,11 @@ describe('UrlFetcher', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with the error', function() {
|
||||
it('should call the callback with the error', function () {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
|
||||
return it('should only call the callback once, even if end is called', function() {
|
||||
return it('should only call the callback once, even if end is called', function () {
|
||||
this.urlStream.emit('end')
|
||||
return this.callback.calledOnce.should.equal(true)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user