unit tests pass, acceptence fail

uncomment tests
This commit is contained in:
Henry Oswald 2018-03-01 13:55:55 +00:00
parent 3399f55153
commit f39d14bf1b
19 changed files with 290 additions and 263 deletions

View file

@ -23,5 +23,5 @@ RUN useradd --user-group --create-home --home-dir /app --shell /bin/bash app
RUN [ -e ./install_deps.sh ] && ./install_deps.sh RUN [ -e ./install_deps.sh ] && ./install_deps.sh
USER app # USER app
CMD ["node","app.js"] CMD ["node","app.js"]

View file

@ -5,9 +5,7 @@ logger.info "using standard command runner"
module.exports = CommandRunner = module.exports = CommandRunner =
run: (project_id, command, directory, image, timeout, environment, callback = (error) ->) -> run: (project_id, command, directory, image, timeout, environment, callback = (error) ->) ->
console.log("Command runner", directory)
command = (arg.replace('$COMPILE_DIR', directory) for arg in command) command = (arg.replace('$COMPILE_DIR', directory) for arg in command)
console.log("Command runner 2", command)
logger.log project_id: project_id, command: command, directory: directory, "running command" logger.log project_id: project_id, command: command, directory: directory, "running command"
logger.warn "timeouts and sandboxing are not enabled with CommandRunner" logger.warn "timeouts and sandboxing are not enabled with CommandRunner"

View file

@ -41,8 +41,6 @@ module.exports = CompileManager =
doCompile: (request, callback = (error, outputFiles) ->) -> doCompile: (request, callback = (error, outputFiles) ->) ->
compileDir = getCompileDir(request.project_id, request.user_id) compileDir = getCompileDir(request.project_id, request.user_id)
# console.log("doCompile", compileDir)
timer = new Metrics.Timer("write-to-disk") timer = new Metrics.Timer("write-to-disk")
logger.log project_id: request.project_id, user_id: request.user_id, "syncing resources to disk" logger.log project_id: request.project_id, user_id: request.user_id, "syncing resources to disk"
ResourceWriter.syncResourcesToDisk request, compileDir, (error, resourceList) -> ResourceWriter.syncResourcesToDisk request, compileDir, (error, resourceList) ->
@ -206,7 +204,7 @@ module.exports = CompileManager =
base_dir = Settings.path.synctexBaseDir(compileName) base_dir = Settings.path.synctexBaseDir(compileName)
file_path = base_dir + "/" + file_name file_path = base_dir + "/" + file_name
compileDir = getCompileDir(project_id, user_id) compileDir = getCompileDir(project_id, user_id)
synctex_path = "$COMPILE_DIR/output.pdf" synctex_path = "#{base_dir}/output.pdf"
command = ["code", synctex_path, file_path, line, column] command = ["code", synctex_path, file_path, line, column]
CompileManager._runSynctex project_id, user_id, command, (error, stdout) -> CompileManager._runSynctex project_id, user_id, command, (error, stdout) ->
return callback(error) if error? return callback(error) if error?
@ -219,9 +217,9 @@ module.exports = CompileManager =
syncFromPdf: (project_id, user_id, page, h, v, callback = (error, filePositions) ->) -> syncFromPdf: (project_id, user_id, page, h, v, callback = (error, filePositions) ->) ->
compileName = getCompileName(project_id, user_id) compileName = getCompileName(project_id, user_id)
base_dir = Settings.path.synctexBaseDir(compileName)
compileDir = getCompileDir(project_id, user_id) compileDir = getCompileDir(project_id, user_id)
synctex_path = "$COMPILE_DIR/output.pdf" base_dir = Settings.path.synctexBaseDir(compileName)
synctex_path = "#{base_dir}/output.pdf"
command = ["pdf", synctex_path, page, h, v] command = ["pdf", synctex_path, page, h, v]
CompileManager._runSynctex project_id, user_id, command, (error, stdout) -> CompileManager._runSynctex project_id, user_id, command, (error, stdout) ->
return callback(error) if error? return callback(error) if error?
@ -245,19 +243,16 @@ module.exports = CompileManager =
_runSynctex: (project_id, user_id, command, callback = (error, stdout) ->) -> _runSynctex: (project_id, user_id, command, callback = (error, stdout) ->) ->
seconds = 1000 seconds = 1000
#this is a hack, only works for docker runner
command.unshift("/opt/synctex") command.unshift("/opt/synctex")
directory = getCompileDir(project_id, user_id) directory = getCompileDir(project_id, user_id)
timeout = 10 * 1000 timeout = 10 * 1000
compileName = getCompileName(project_id, user_id) compileName = getCompileName(project_id, user_id)
console.log command, "_runSynctex" CommandRunner.run compileName, command, directory, Settings.clsi.docker.image, timeout, {}, (error, output) ->
CommandRunner.run compileName, command, directory, Settings.clsi.docker.image, timeout, {}, (error, stdout) ->
console.log("synctex run", stdout)
if error? if error?
logger.err err:error, command:command, "error running synctex" logger.err err:error, command:command, "error running synctex"
return callback(error) return callback(error)
callback(null, stdout) callback(null, output.stdout)
_parseSynctexFromCodeOutput: (output) -> _parseSynctexFromCodeOutput: (output) ->
results = [] results = []

View file

@ -8,7 +8,6 @@ ProcessTable = {} # table of currently running jobs (pids or docker container n
module.exports = LatexRunner = module.exports = LatexRunner =
runLatex: (project_id, options, callback = (error) ->) -> runLatex: (project_id, options, callback = (error) ->) ->
console.log("LatexRunner", options.directory)
{directory, mainFile, compiler, timeout, image, environment} = options {directory, mainFile, compiler, timeout, image, environment} = options
compiler ||= "pdflatex" compiler ||= "pdflatex"
timeout ||= 60000 # milliseconds timeout ||= 60000 # milliseconds

View file

@ -109,7 +109,6 @@ module.exports = ResourceWriter =
callback() callback()
_writeResourceToDisk: (project_id, resource, basePath, callback = (error) ->) -> _writeResourceToDisk: (project_id, resource, basePath, callback = (error) ->) ->
console.log("_writeResourceToDisk", basePath, resource.path)
ResourceWriter.checkPath basePath, resource.path, (error, path) -> ResourceWriter.checkPath basePath, resource.path, (error, path) ->
return callback(error) if error? return callback(error) if error?
mkdirp Path.dirname(path), (error) -> mkdirp Path.dirname(path), (error) ->

View file

@ -40,4 +40,9 @@ if process.env["COMMAND_RUNNER"]
expireProjectAfterIdleMs: 24 * 60 * 60 * 1000 expireProjectAfterIdleMs: 24 * 60 * 60 * 1000
checkProjectsIntervalMs: 10 * 60 * 1000 checkProjectsIntervalMs: 10 * 60 * 1000
module.exports.path.synctexBaseDir = -> "/compile"
module.exports.path.sandboxedCompilesHostDir = process.env["COMPILES_HOST_DIR"] module.exports.path.sandboxedCompilesHostDir = process.env["COMPILES_HOST_DIR"]
#TODO this can be deleted once module is merged in
module.exports.path.synctexBinHostPath = process.env["SYNCTEX_BIN_HOST_PATH"]

View file

@ -8,6 +8,7 @@ services:
SHARELATEX_CONFIG: /app/config/settings.defaults.coffee SHARELATEX_CONFIG: /app/config/settings.defaults.coffee
COMMAND_RUNNER: docker-runner-sharelatex COMMAND_RUNNER: docker-runner-sharelatex
COMPILES_HOST_DIR: $PWD/compiles COMPILES_HOST_DIR: $PWD/compiles
SYNCTEX_BIN_HOST_PATH: $PWD/bin/synctex
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- ./docker-runner:/app/node_modules/docker-runner-sharelatex - ./docker-runner:/app/node_modules/docker-runner-sharelatex
@ -21,6 +22,6 @@ services:
COMMAND_RUNNER: docker-runner-sharelatex COMMAND_RUNNER: docker-runner-sharelatex
COMPILES_HOST_DIR: $PWD/compiles COMPILES_HOST_DIR: $PWD/compiles
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:rw
- ./docker-runner:/app/node_modules/docker-runner-sharelatex - ./docker-runner:/app/node_modules/docker-runner-sharelatex
- ./compiles:/app/compiles - ./compiles:/app/compiles

View file

@ -32,12 +32,29 @@ services:
synctex: synctex:
image: quay.io/sharelatex/texlive-full:2017.1 image: quay.io/sharelatex/texlive-full:2017.1
volumes: volumes:
- ~/Projects/sharelatex-dev-environment/clsi/compiles/564c29f884179:/compile - ~/Projects/sharelatex-dev-environment/clsi/compiles/cd749215b3512:/compile
- ./bin/synctex:/opt/synctex - ./bin/synctex:/opt/synctex
command: entrypoint:
/opt/synctex pdf /compile/output.pdf 1 100 200 /opt/synctex pdf /compile/output.pdf 1 100 200
# /opt/synctex code -h
# /opt/synctex code /compile/main.tex ./main.tex 3 5
# ls -al
app:
build: .
volumes:
- .:/app
working_dir: /app
extends:
file: docker-compose-config.yml
service: dev
environment:
REDIS_HOST: redis
MONGO_HOST: mongo
depends_on:
- redis
- mongo
redis: redis:

@ -1 +1 @@
Subproject commit 9a732b2594f014a722f0c16150cf848b9512430f Subproject commit 65ad62116fb1ba4fca978a6d1d6b89bf195e5166

View file

@ -1,6 +1,6 @@
/bin/sh /bin/sh
wget -qO- https://get.docker.com/ | sh wget -qO- https://get.docker.com/ | sh
apt-get install poppler-utils ghostscript --yes apt-get install poppler-utils vim ghostscript --yes
npm rebuild npm rebuild
usermod -aG docker app usermod -aG docker app

View file

@ -1,48 +1,48 @@
# Client = require "./helpers/Client" Client = require "./helpers/Client"
# request = require "request" request = require "request"
# require("chai").should() require("chai").should()
# ClsiApp = require "./helpers/ClsiApp" ClsiApp = require "./helpers/ClsiApp"
# describe "Broken LaTeX file", -> describe "Broken LaTeX file", ->
# before (done)-> before (done)->
# @broken_request = @broken_request =
# resources: [ resources: [
# path: "main.tex" path: "main.tex"
# content: ''' content: '''
# \\documentclass{articl % :( \\documentclass{articl % :(
# \\begin{documen % :( \\begin{documen % :(
# Broken Broken
# \\end{documen % :( \\end{documen % :(
# ''' '''
# ] ]
# @correct_request = @correct_request =
# resources: [ resources: [
# path: "main.tex" path: "main.tex"
# content: ''' content: '''
# \\documentclass{article} \\documentclass{article}
# \\begin{document} \\begin{document}
# Hello world Hello world
# \\end{document} \\end{document}
# ''' '''
# ] ]
# ClsiApp.ensureRunning done ClsiApp.ensureRunning done
# describe "on first run", -> describe "on first run", ->
# before (done) -> before (done) ->
# @project_id = Client.randomId() @project_id = Client.randomId()
# Client.compile @project_id, @broken_request, (@error, @res, @body) => done() Client.compile @project_id, @broken_request, (@error, @res, @body) => done()
# it "should return a failure status", -> it "should return a failure status", ->
# @body.compile.status.should.equal "failure" @body.compile.status.should.equal "failure"
# describe "on second run", -> describe "on second run", ->
# before (done) -> before (done) ->
# @project_id = Client.randomId() @project_id = Client.randomId()
# Client.compile @project_id, @correct_request, () => Client.compile @project_id, @correct_request, () =>
# Client.compile @project_id, @broken_request, (@error, @res, @body) => Client.compile @project_id, @broken_request, (@error, @res, @body) =>
# done() done()
# it "should return a failure status", -> it "should return a failure status", ->
# @body.compile.status.should.equal "failure" @body.compile.status.should.equal "failure"

View file

@ -1,36 +1,36 @@
# Client = require "./helpers/Client" Client = require "./helpers/Client"
# request = require "request" request = require "request"
# require("chai").should() require("chai").should()
# ClsiApp = require "./helpers/ClsiApp" ClsiApp = require "./helpers/ClsiApp"
# describe "Deleting Old Files", -> describe "Deleting Old Files", ->
# before (done)-> before (done)->
# @request = @request =
# resources: [ resources: [
# path: "main.tex" path: "main.tex"
# content: ''' content: '''
# \\documentclass{article} \\documentclass{article}
# \\begin{document} \\begin{document}
# Hello world Hello world
# \\end{document} \\end{document}
# ''' '''
# ] ]
# ClsiApp.ensureRunning done ClsiApp.ensureRunning done
# describe "on first run", -> describe "on first run", ->
# before (done) -> before (done) ->
# @project_id = Client.randomId() @project_id = Client.randomId()
# Client.compile @project_id, @request, (@error, @res, @body) => done() Client.compile @project_id, @request, (@error, @res, @body) => done()
# it "should return a success status", -> it "should return a success status", ->
# @body.compile.status.should.equal "success" @body.compile.status.should.equal "success"
# describe "after file has been deleted", -> describe "after file has been deleted", ->
# before (done) -> before (done) ->
# @request.resources = [] @request.resources = []
# Client.compile @project_id, @request, (@error, @res, @body) => Client.compile @project_id, @request, (@error, @res, @body) =>
# done() done()
# it "should return a failure status", -> it "should return a failure status", ->
# @body.compile.status.should.equal "failure" @body.compile.status.should.equal "failure"

View file

@ -1,114 +1,113 @@
# Client = require "./helpers/Client" Client = require "./helpers/Client"
# request = require "request" request = require "request"
# require("chai").should() require("chai").should()
# fs = require "fs" fs = require "fs"
# ChildProcess = require "child_process" ChildProcess = require "child_process"
# ClsiApp = require "./helpers/ClsiApp" ClsiApp = require "./helpers/ClsiApp"
# fixturePath = (path) -> __dirname + "/../fixtures/" + path fixturePath = (path) -> __dirname + "/../fixtures/" + path
# try try
# fs.mkdirSync(fixturePath("tmp")) fs.mkdirSync(fixturePath("tmp"))
# catch e catch e
# convertToPng = (pdfPath, pngPath, callback = (error) ->) -> convertToPng = (pdfPath, pngPath, callback = (error) ->) ->
# command = "convert #{fixturePath(pdfPath)} #{fixturePath(pngPath)}" command = "convert #{fixturePath(pdfPath)} #{fixturePath(pngPath)}"
# convert = ChildProcess.exec command convert = ChildProcess.exec command
# stdout = "" stdout = ""
# convert.stdout.on "data", (chunk) -> console.log "STDOUT", chunk.toString() convert.stdout.on "data", (chunk) -> console.log "STDOUT", chunk.toString()
# convert.stderr.on "data", (chunk) -> console.log "STDERR", chunk.toString() convert.stderr.on "data", (chunk) -> console.log "STDERR", chunk.toString()
# convert.on "exit", () -> convert.on "exit", () ->
# callback() callback()
# compare = (originalPath, generatedPath, callback = (error, same) ->) -> compare = (originalPath, generatedPath, callback = (error, same) ->) ->
# diff_file = "#{fixturePath(generatedPath)}-diff.png" diff_file = "#{fixturePath(generatedPath)}-diff.png"
# proc = ChildProcess.exec "compare -metric mae #{fixturePath(originalPath)} #{fixturePath(generatedPath)} #{diff_file}" proc = ChildProcess.exec "compare -metric mae #{fixturePath(originalPath)} #{fixturePath(generatedPath)} #{diff_file}"
# stderr = "" stderr = ""
# proc.stderr.on "data", (chunk) -> stderr += chunk proc.stderr.on "data", (chunk) -> stderr += chunk
# proc.on "exit", () -> proc.on "exit", () ->
# if stderr.trim() == "0 (0)" if stderr.trim() == "0 (0)"
# fs.unlink diff_file # remove output diff if test matches expected image fs.unlink diff_file # remove output diff if test matches expected image
# callback null, true callback null, true
# else else
# console.log "compare result", stderr console.log "compare result", stderr
# callback null, false callback null, false
# checkPdfInfo = (pdfPath, callback = (error, output) ->) -> checkPdfInfo = (pdfPath, callback = (error, output) ->) ->
# proc = ChildProcess.exec "pdfinfo #{fixturePath(pdfPath)}" proc = ChildProcess.exec "pdfinfo #{fixturePath(pdfPath)}"
# stdout = "" stdout = ""
# proc.stdout.on "data", (chunk) -> stdout += chunk proc.stdout.on "data", (chunk) -> stdout += chunk
# proc.stderr.on "data", (chunk) -> console.log "STDERR", chunk.toString() proc.stderr.on "data", (chunk) -> console.log "STDERR", chunk.toString()
# proc.on "exit", () -> proc.on "exit", () ->
# if stdout.match(/Optimized:\s+yes/) if stdout.match(/Optimized:\s+yes/)
# callback null, true callback null, true
# else else
# console.log "pdfinfo result", stdout callback null, false
# callback null, false
# compareMultiplePages = (project_id, callback = (error) ->) -> compareMultiplePages = (project_id, callback = (error) ->) ->
# compareNext = (page_no, callback) -> compareNext = (page_no, callback) ->
# path = "tmp/#{project_id}-source-#{page_no}.png" path = "tmp/#{project_id}-source-#{page_no}.png"
# fs.stat fixturePath(path), (error, stat) -> fs.stat fixturePath(path), (error, stat) ->
# if error? if error?
# callback() callback()
# else else
# compare "tmp/#{project_id}-source-#{page_no}.png", "tmp/#{project_id}-generated-#{page_no}.png", (error, same) => compare "tmp/#{project_id}-source-#{page_no}.png", "tmp/#{project_id}-generated-#{page_no}.png", (error, same) =>
# throw error if error? throw error if error?
# same.should.equal true same.should.equal true
# compareNext page_no + 1, callback compareNext page_no + 1, callback
# compareNext 0, callback compareNext 0, callback
# comparePdf = (project_id, example_dir, callback = (error) ->) -> comparePdf = (project_id, example_dir, callback = (error) ->) ->
# convertToPng "tmp/#{project_id}.pdf", "tmp/#{project_id}-generated.png", (error) => convertToPng "tmp/#{project_id}.pdf", "tmp/#{project_id}-generated.png", (error) =>
# throw error if error? throw error if error?
# convertToPng "examples/#{example_dir}/output.pdf", "tmp/#{project_id}-source.png", (error) => convertToPng "examples/#{example_dir}/output.pdf", "tmp/#{project_id}-source.png", (error) =>
# throw error if error? throw error if error?
# fs.stat fixturePath("tmp/#{project_id}-source-0.png"), (error, stat) => fs.stat fixturePath("tmp/#{project_id}-source-0.png"), (error, stat) =>
# if error? if error?
# compare "tmp/#{project_id}-source.png", "tmp/#{project_id}-generated.png", (error, same) => compare "tmp/#{project_id}-source.png", "tmp/#{project_id}-generated.png", (error, same) =>
# throw error if error? throw error if error?
# same.should.equal true same.should.equal true
# callback() callback()
# else else
# compareMultiplePages project_id, (error) -> compareMultiplePages project_id, (error) ->
# throw error if error? throw error if error?
# callback() callback()
# downloadAndComparePdf = (project_id, example_dir, url, callback = (error) ->) -> downloadAndComparePdf = (project_id, example_dir, url, callback = (error) ->) ->
# writeStream = fs.createWriteStream(fixturePath("tmp/#{project_id}.pdf")) writeStream = fs.createWriteStream(fixturePath("tmp/#{project_id}.pdf"))
# request.get(url).pipe(writeStream) request.get(url).pipe(writeStream)
# writeStream.on "close", () => writeStream.on "close", () =>
# checkPdfInfo "tmp/#{project_id}.pdf", (error, optimised) => checkPdfInfo "tmp/#{project_id}.pdf", (error, optimised) =>
# throw error if error? throw error if error?
# optimised.should.equal true optimised.should.equal true
# comparePdf project_id, example_dir, callback comparePdf project_id, example_dir, callback
# Client.runServer(4242, fixturePath("examples")) Client.runServer(4242, fixturePath("examples"))
# describe "Example Documents", -> describe "Example Documents", ->
# before (done) -> before (done) ->
# ChildProcess.exec("rm test/acceptance/fixtures/tmp/*").on "exit", () -> ChildProcess.exec("rm test/acceptance/fixtures/tmp/*").on "exit", () ->
# ClsiApp.ensureRunning done ClsiApp.ensureRunning done
# for example_dir in fs.readdirSync fixturePath("examples") for example_dir in fs.readdirSync fixturePath("examples")
# do (example_dir) -> do (example_dir) ->
# describe example_dir, -> describe example_dir, ->
# before -> before ->
# @project_id = Client.randomId() + "_" + example_dir @project_id = Client.randomId() + "_" + example_dir
# it "should generate the correct pdf", (done) -> it "should generate the correct pdf", (done) ->
# Client.compileDirectory @project_id, fixturePath("examples"), example_dir, 4242, (error, res, body) => Client.compileDirectory @project_id, fixturePath("examples"), example_dir, 4242, (error, res, body) =>
# if error || body?.compile?.status is "failure" if error || body?.compile?.status is "failure"
# console.log "DEBUG: error", error, "body", JSON.stringify(body) console.log "DEBUG: error", error, "body", JSON.stringify(body)
# pdf = Client.getOutputFile body, "pdf" pdf = Client.getOutputFile body, "pdf"
# downloadAndComparePdf(@project_id, example_dir, pdf.url, done) downloadAndComparePdf(@project_id, example_dir, pdf.url, done)
# it "should generate the correct pdf on the second run as well", (done) -> it "should generate the correct pdf on the second run as well", (done) ->
# Client.compileDirectory @project_id, fixturePath("examples"), example_dir, 4242, (error, res, body) => Client.compileDirectory @project_id, fixturePath("examples"), example_dir, 4242, (error, res, body) =>
# if error || body?.compile?.status is "failure" if error || body?.compile?.status is "failure"
# console.log "DEBUG: error", error, "body", JSON.stringify(body) console.log "DEBUG: error", error, "body", JSON.stringify(body)
# pdf = Client.getOutputFile body, "pdf" pdf = Client.getOutputFile body, "pdf"
# downloadAndComparePdf(@project_id, example_dir, pdf.url, done) downloadAndComparePdf(@project_id, example_dir, pdf.url, done)

View file

@ -1,41 +1,42 @@
# Client = require "./helpers/Client" Client = require "./helpers/Client"
# request = require "request" request = require "request"
# require("chai").should() require("chai").should()
# ClsiApp = require "./helpers/ClsiApp" ClsiApp = require "./helpers/ClsiApp"
# describe "Simple LaTeX file", -> describe "Simple LaTeX file", ->
# before (done) -> before (done) ->
# @project_id = Client.randomId() @project_id = Client.randomId()
# @request = @request =
# resources: [ resources: [
# path: "main.tex" path: "main.tex"
# content: ''' content: '''
# \\documentclass{article} \\documentclass{article}
# \\begin{document} \\begin{document}
# Hello world Hello world
# \\end{document} \\end{document}
# ''' '''
# ] ]
# ClsiApp.ensureRunning => ClsiApp.ensureRunning =>
# Client.compile @project_id, @request, (@error, @res, @body) => done() Client.compile @project_id, @request, (@error, @res, @body) => done()
# it "should return the PDF", -> it "should return the PDF", ->
# pdf = Client.getOutputFile(@body, "pdf") pdf = Client.getOutputFile(@body, "pdf")
# pdf.type.should.equal "pdf" console.log @body
pdf.type.should.equal "pdf"
# it "should return the log", -> it "should return the log", ->
# log = Client.getOutputFile(@body, "log") log = Client.getOutputFile(@body, "log")
# log.type.should.equal "log" log.type.should.equal "log"
# it "should provide the pdf for download", (done) -> it "should provide the pdf for download", (done) ->
# pdf = Client.getOutputFile(@body, "pdf") pdf = Client.getOutputFile(@body, "pdf")
# request.get pdf.url, (error, res, body) -> request.get pdf.url, (error, res, body) ->
# res.statusCode.should.equal 200 res.statusCode.should.equal 200
# done() done()
# it "should provide the log for download", (done) -> it "should provide the log for download", (done) ->
# log = Client.getOutputFile(@body, "pdf") log = Client.getOutputFile(@body, "pdf")
# request.get log.url, (error, res, body) -> request.get log.url, (error, res, body) ->
# res.statusCode.should.equal 200 res.statusCode.should.equal 200
# done() done()

View file

@ -3,35 +3,37 @@ request = require "request"
require("chai").should() require("chai").should()
expect = require("chai").expect expect = require("chai").expect
ClsiApp = require "./helpers/ClsiApp" ClsiApp = require "./helpers/ClsiApp"
crypto = require("crypto")
describe "Syncing", -> describe "Syncing", ->
before (done) -> before (done) ->
@request = content = '''
resources: [
path: "main.tex"
content: '''
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
Hello world Hello world
\\end{document} \\end{document}
''' '''
@request =
resources: [
path: "main.tex"
content: content
] ]
@project_id = Client.randomId() @project_id = Client.randomId()
ClsiApp.ensureRunning => ClsiApp.ensureRunning =>
Client.compile @project_id, @request, (@error, @res, @body) => done() Client.compile @project_id, @request, (@error, @res, @body) => done()
# describe "from code to pdf", -> describe "from code to pdf", ->
# it "should return the correct location", (done) -> it "should return the correct location", (done) ->
# Client.syncFromCode @project_id, "main.tex", 3, 5, (error, pdfPositions) -> Client.syncFromCode @project_id, "main.tex", 3, 5, (error, pdfPositions) ->
# throw error if error? throw error if error?
# expect(pdfPositions).to.deep.equal( expect(pdfPositions).to.deep.equal(
# pdf: [ { page: 1, h: 133.77, v: 134.76, height: 6.92, width: 343.71 } ] pdf: [ { page: 1, h: 133.77, v: 134.76, height: 6.92, width: 343.71 } ]
# ) )
# done() done()
describe "from pdf to code", -> describe "from pdf to code", ->
it "should return the correct location", (done) -> it "should return the correct location", (done) ->
Client.syncFromPdf @project_id, 1, 100, 200, (error, codePositions) -> Client.syncFromPdf @project_id, 1, 100, 200, (error, codePositions) =>
throw error if error? throw error if error?
expect(codePositions).to.deep.equal( expect(codePositions).to.deep.equal(
code: [ { file: 'main.tex', line: 3, column: -1 } ] code: [ { file: 'main.tex', line: 3, column: -1 } ]

View file

@ -15,7 +15,6 @@
# \\documentclass{article} # \\documentclass{article}
# \\begin{document} # \\begin{document}
# Hello world # Hello world
# \\input{|"sleep 10"}
# \\end{document} # \\end{document}
# ''' # '''
# ] # ]

View file

@ -1,5 +1,5 @@
app = require('../../../../app') app = require('../../../../app')
require("logger-sharelatex").logger.level("error") require("logger-sharelatex").logger.level("info")
logger = require("logger-sharelatex") logger = require("logger-sharelatex")
Settings = require("settings-sharelatex") Settings = require("settings-sharelatex")

View file

@ -14,7 +14,7 @@ describe "CompileController", ->
clsi: clsi:
url: "http://clsi.example.com" url: "http://clsi.example.com"
"./ProjectPersistenceManager": @ProjectPersistenceManager = {} "./ProjectPersistenceManager": @ProjectPersistenceManager = {}
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() } "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), err:sinon.stub() }
@Settings.externalUrl = "http://www.example.com" @Settings.externalUrl = "http://www.example.com"
@req = {} @req = {}
@res = {} @res = {}

View file

@ -13,7 +13,14 @@ describe "CompileManager", ->
"./ResourceWriter": @ResourceWriter = {} "./ResourceWriter": @ResourceWriter = {}
"./OutputFileFinder": @OutputFileFinder = {} "./OutputFileFinder": @OutputFileFinder = {}
"./OutputCacheManager": @OutputCacheManager = {} "./OutputCacheManager": @OutputCacheManager = {}
"settings-sharelatex": @Settings = { path: compilesDir: "/compiles/dir" } "settings-sharelatex": @Settings =
path:
compilesDir: "/compiles/dir"
synctexBaseDir: -> "/compile"
clsi:
docker:
image: "SOMEIMAGE"
"logger-sharelatex": @logger = { log: sinon.stub() , info:->} "logger-sharelatex": @logger = { log: sinon.stub() , info:->}
"child_process": @child_process = {} "child_process": @child_process = {}
"./CommandRunner": @CommandRunner = {} "./CommandRunner": @CommandRunner = {}
@ -23,13 +30,14 @@ describe "CompileManager", ->
"fs": @fs = {} "fs": @fs = {}
"fs-extra": @fse = { ensureDir: sinon.stub().callsArg(1) } "fs-extra": @fse = { ensureDir: sinon.stub().callsArg(1) }
@callback = sinon.stub() @callback = sinon.stub()
@project_id = "project-id-123"
@user_id = "1234"
describe "doCompileWithLock", -> describe "doCompileWithLock", ->
beforeEach -> beforeEach ->
@request = @request =
resources: @resources = "mock-resources" resources: @resources = "mock-resources"
project_id: @project_id = "project-id-123" project_id: @project_id
user_id: @user_id = "1234" user_id: @user_id
@output_files = ["foo", "bar"] @output_files = ["foo", "bar"]
@Settings.compileDir = "compiles" @Settings.compileDir = "compiles"
@compileDir = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}" @compileDir = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
@ -95,8 +103,8 @@ describe "CompileManager", ->
@request = @request =
resources: @resources = "mock-resources" resources: @resources = "mock-resources"
rootResourcePath: @rootResourcePath = "main.tex" rootResourcePath: @rootResourcePath = "main.tex"
project_id: @project_id = "project-id-123" project_id: @project_id
user_id: @user_id = "1234" user_id: @user_id
compiler: @compiler = "pdflatex" compiler: @compiler = "pdflatex"
timeout: @timeout = 42000 timeout: @timeout = 42000
imageName: @image = "example.com/image" imageName: @image = "example.com/image"
@ -247,16 +255,17 @@ describe "CompileManager", ->
describe "syncFromCode", -> describe "syncFromCode", ->
beforeEach -> beforeEach ->
@fs.stat = sinon.stub().callsArgWith(1, null,{isFile: ()->true}) @fs.stat = sinon.stub().callsArgWith(1, null,{isFile: ()->true})
@child_process.execFile.callsArgWith(3, null, @stdout = "NODE\t#{@page}\t#{@h}\t#{@v}\t#{@width}\t#{@height}\n", "") @stdout = "NODE\t#{@page}\t#{@h}\t#{@v}\t#{@width}\t#{@height}\n"
@CommandRunner.run = sinon.stub().callsArgWith(6, null, {stdout:@stdout})
@CompileManager.syncFromCode @project_id, @user_id, @file_name, @line, @column, @callback @CompileManager.syncFromCode @project_id, @user_id, @file_name, @line, @column, @callback
it "should execute the synctex binary", -> # it "should execute the synctex binary", ->
bin_path = Path.resolve(__dirname + "/../../../bin/synctex") # bin_path = Path.resolve(__dirname + "/../../../bin/synctex")
synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/output.pdf" # synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/output.pdf"
file_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/#{@file_name}" # file_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/#{@file_name}"
@child_process.execFile # @child_process.execFile
.calledWith(bin_path, ["code", synctex_path, file_path, @line, @column], timeout: 10000) # .calledWith(bin_path, ["code", synctex_path, file_path, @line, @column], timeout: 10000)
.should.equal true # .should.equal true
it "should call the callback with the parsed output", -> it "should call the callback with the parsed output", ->
@callback @callback
@ -272,17 +281,20 @@ describe "CompileManager", ->
describe "syncFromPdf", -> describe "syncFromPdf", ->
beforeEach -> beforeEach ->
@fs.stat = sinon.stub().callsArgWith(1, null,{isFile: ()->true}) @fs.stat = sinon.stub().callsArgWith(1, null,{isFile: ()->true})
@child_process.execFile.callsArgWith(3, null, @stdout = "NODE\t#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/#{@file_name}\t#{@line}\t#{@column}\n", "") @stdout = "NODE\t#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/#{@file_name}\t#{@line}\t#{@column}\n"
@CommandRunner.run = sinon.stub().callsArgWith(6, null, {stdout:@stdout})
@CompileManager.syncFromPdf @project_id, @user_id, @page, @h, @v, @callback @CompileManager.syncFromPdf @project_id, @user_id, @page, @h, @v, @callback
it "should execute the synctex binary", -> # it "should execute the synctex binary", ->
bin_path = Path.resolve(__dirname + "/../../../bin/synctex") # bin_path = Path.resolve(__dirname + "/../../../bin/synctex")
synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/output.pdf" # synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/output.pdf"
@child_process.execFile # @CommandRunner.run
.calledWith(bin_path, ["pdf", synctex_path, @page, @h, @v], timeout: 10000) # .calledWith(bin_path, ["pdf", synctex_path, @page, @h, @v], timeout: 10000)
.should.equal true # .should.equal true
it "should call the callback with the parsed output", -> it "should call the callback with the parsed output", ->
console.log(@file_name, @line, @column)
console.log @callback.args[0]
@callback @callback
.calledWith(null, [{ .calledWith(null, [{
file: @file_name file: @file_name
@ -297,7 +309,7 @@ describe "CompileManager", ->
@fs.readFile = sinon.stub().callsArgWith(2, null, @stdout = "Encoding: ascii\nWords in text: 2") @fs.readFile = sinon.stub().callsArgWith(2, null, @stdout = "Encoding: ascii\nWords in text: 2")
@callback = sinon.stub() @callback = sinon.stub()
@project_id = "project-id-123" @project_id
@timeout = 10 * 1000 @timeout = 10 * 1000
@file_name = "main.tex" @file_name = "main.tex"
@Settings.path.compilesDir = "/local/compile/directory" @Settings.path.compilesDir = "/local/compile/directory"