wip, docker container is correctly created
This commit is contained in:
@@ -41,7 +41,7 @@ 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 )
|
# 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"
|
||||||
@@ -206,9 +206,9 @@ 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 = Path.join(compileDir, "output.pdf")
|
synctex_path = "$COMPILE_DIR/output.pdf"
|
||||||
command = ["code", synctex_path, file_path, line, column]
|
command = ["code", synctex_path, file_path, line, column]
|
||||||
CompileManager._runSynctex command, (error, stdout) ->
|
CompileManager._runSynctex project_id, user_id, command, (error, stdout) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
if stdout.toLowerCase().indexOf("warning") == -1
|
if stdout.toLowerCase().indexOf("warning") == -1
|
||||||
logType = "log"
|
logType = "log"
|
||||||
@@ -221,9 +221,9 @@ module.exports = CompileManager =
|
|||||||
compileName = getCompileName(project_id, user_id)
|
compileName = getCompileName(project_id, user_id)
|
||||||
base_dir = Settings.path.synctexBaseDir(compileName)
|
base_dir = Settings.path.synctexBaseDir(compileName)
|
||||||
compileDir = getCompileDir(project_id, user_id)
|
compileDir = getCompileDir(project_id, user_id)
|
||||||
synctex_path = Path.join(compileDir, "output.pdf")
|
synctex_path = "$COMPILE_DIR/output.pdf"
|
||||||
logger.log({base_dir, project_id, synctex_path}, "base diiir")
|
command = ["pdf", synctex_path, page, h, v]
|
||||||
CompileManager._runSynctex ["pdf", synctex_path, page, h, v], (error, stdout) ->
|
CompileManager._runSynctex project_id, user_id, command, (error, stdout) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
logger.log project_id: project_id, user_id:user_id, page: page, h: h, v:v, stdout: stdout, "synctex pdf output"
|
logger.log project_id: project_id, user_id:user_id, page: page, h: h, v:v, stdout: stdout, "synctex pdf output"
|
||||||
callback null, CompileManager._parseSynctexFromPdfOutput(stdout, base_dir)
|
callback null, CompileManager._parseSynctexFromPdfOutput(stdout, base_dir)
|
||||||
@@ -242,20 +242,22 @@ module.exports = CompileManager =
|
|||||||
return callback(new Error("not a file")) if not stats?.isFile()
|
return callback(new Error("not a file")) if not stats?.isFile()
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
_runSynctex: (args, callback = (error, stdout) ->) ->
|
_runSynctex: (project_id, user_id, command, callback = (error, stdout) ->) ->
|
||||||
bin_path = Path.resolve(__dirname + "/../../bin/synctex")
|
|
||||||
seconds = 1000
|
seconds = 1000
|
||||||
outputFilePath = args[1]
|
|
||||||
CompileManager._checkFileExists outputFilePath, (error) ->
|
#this is a hack, only works for docker runner
|
||||||
return callback(error) if error?
|
command.unshift("/opt/synctex")
|
||||||
if Settings.clsi?.synctexCommandWrapper?
|
directory = getCompileDir(project_id, user_id)
|
||||||
[bin_path, args] = Settings.clsi?.synctexCommandWrapper bin_path, args
|
timeout = 10 * 1000
|
||||||
logger.log({bin_path, args}, "synctex being run")
|
compileName = getCompileName(project_id, user_id)
|
||||||
child_process.execFile bin_path, args, timeout: 10 * seconds, (error, stdout, stderr) ->
|
console.log command, "_runSynctex"
|
||||||
if error?
|
|
||||||
logger.err err:error, args:args, "error running synctex"
|
CommandRunner.run compileName, command, directory, Settings.clsi.docker.image, timeout, {}, (error, stdout) ->
|
||||||
return callback(error)
|
console.log("synctex run", stdout)
|
||||||
callback(null, stdout)
|
if error?
|
||||||
|
logger.err err:error, command:command, "error running synctex"
|
||||||
|
return callback(error)
|
||||||
|
callback(null, stdout)
|
||||||
|
|
||||||
_parseSynctexFromCodeOutput: (output) ->
|
_parseSynctexFromCodeOutput: (output) ->
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@@ -41,5 +41,3 @@ if process.env["COMMAND_RUNNER"]
|
|||||||
checkProjectsIntervalMs: 10 * 60 * 1000
|
checkProjectsIntervalMs: 10 * 60 * 1000
|
||||||
|
|
||||||
module.exports.path.sandboxedCompilesHostDir = process.env["COMPILES_HOST_DIR"]
|
module.exports.path.sandboxedCompilesHostDir = process.env["COMPILES_HOST_DIR"]
|
||||||
|
|
||||||
console.log module.exports
|
|
||||||
@@ -29,6 +29,17 @@ services:
|
|||||||
- mongo
|
- mongo
|
||||||
entrypoint: npm run test:acceptance
|
entrypoint: npm run test:acceptance
|
||||||
|
|
||||||
|
synctex:
|
||||||
|
image: quay.io/sharelatex/texlive-full:2017.1
|
||||||
|
volumes:
|
||||||
|
- ~/Projects/sharelatex-dev-environment/clsi/compiles/564c29f884179:/compile
|
||||||
|
- ./bin/synctex:/opt/synctex
|
||||||
|
|
||||||
|
command:
|
||||||
|
/opt/synctex pdf /compile/output.pdf 1 100 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis
|
image: redis
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +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", ->
|
||||||
console.log(@error, @res, @body)
|
# @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"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
@@ -1,114 +1,114 @@
|
|||||||
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
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,41 +1,41 @@
|
|||||||
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"
|
# 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()
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ describe "Syncing", ->
|
|||||||
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) ->
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
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 "Timed out compile", ->
|
# describe "Timed out compile", ->
|
||||||
before (done) ->
|
# before (done) ->
|
||||||
@request =
|
# @request =
|
||||||
options:
|
# options:
|
||||||
timeout: 1 #seconds
|
# timeout: 1 #seconds
|
||||||
resources: [
|
# resources: [
|
||||||
path: "main.tex"
|
# path: "main.tex"
|
||||||
content: '''
|
# content: '''
|
||||||
\\documentclass{article}
|
# \\documentclass{article}
|
||||||
\\begin{document}
|
# \\begin{document}
|
||||||
Hello world
|
# Hello world
|
||||||
\\input{|"sleep 10"}
|
# \\input{|"sleep 10"}
|
||||||
\\end{document}
|
# \\end{document}
|
||||||
'''
|
# '''
|
||||||
]
|
# ]
|
||||||
@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()
|
||||||
|
|
||||||
it "should return a timeout error", ->
|
# it "should return a timeout error", ->
|
||||||
@body.compile.error.should.equal "container timed out"
|
# @body.compile.error.should.equal "container timed out"
|
||||||
|
|
||||||
it "should return a timedout status", ->
|
# it "should return a timedout status", ->
|
||||||
@body.compile.status.should.equal "timedout"
|
# @body.compile.status.should.equal "timedout"
|
||||||
|
|
||||||
|
|||||||
@@ -1,222 +1,222 @@
|
|||||||
Client = require "./helpers/Client"
|
# Client = require "./helpers/Client"
|
||||||
request = require "request"
|
# request = require "request"
|
||||||
require("chai").should()
|
# require("chai").should()
|
||||||
sinon = require "sinon"
|
# sinon = require "sinon"
|
||||||
ClsiApp = require "./helpers/ClsiApp"
|
# ClsiApp = require "./helpers/ClsiApp"
|
||||||
|
|
||||||
host = "localhost"
|
# host = "localhost"
|
||||||
|
|
||||||
Server =
|
# Server =
|
||||||
run: () ->
|
# run: () ->
|
||||||
express = require "express"
|
# express = require "express"
|
||||||
app = express()
|
# app = express()
|
||||||
|
|
||||||
staticServer = express.static __dirname + "/../fixtures/"
|
# staticServer = express.static __dirname + "/../fixtures/"
|
||||||
app.get "/:random_id/*", (req, res, next) =>
|
# app.get "/:random_id/*", (req, res, next) =>
|
||||||
@getFile(req.url)
|
# @getFile(req.url)
|
||||||
req.url = "/" + req.params[0]
|
# req.url = "/" + req.params[0]
|
||||||
staticServer(req, res, next)
|
# staticServer(req, res, next)
|
||||||
|
|
||||||
app.listen 31415, host
|
# app.listen 31415, host
|
||||||
|
|
||||||
getFile: () ->
|
# getFile: () ->
|
||||||
|
|
||||||
randomId: () ->
|
# randomId: () ->
|
||||||
Math.random().toString(16).slice(2)
|
# Math.random().toString(16).slice(2)
|
||||||
|
|
||||||
Server.run()
|
# Server.run()
|
||||||
|
|
||||||
describe "Url Caching", ->
|
# describe "Url Caching", ->
|
||||||
describe "Downloading an image for the first time", ->
|
# describe "Downloading an image for the first time", ->
|
||||||
before (done) ->
|
# before (done) ->
|
||||||
@project_id = Client.randomId()
|
# @project_id = Client.randomId()
|
||||||
@file = "#{Server.randomId()}/lion.png"
|
# @file = "#{Server.randomId()}/lion.png"
|
||||||
@request =
|
# @request =
|
||||||
resources: [{
|
# resources: [{
|
||||||
path: "main.tex"
|
# path: "main.tex"
|
||||||
content: '''
|
# content: '''
|
||||||
\\documentclass{article}
|
# \\documentclass{article}
|
||||||
\\usepackage{graphicx}
|
# \\usepackage{graphicx}
|
||||||
\\begin{document}
|
# \\begin{document}
|
||||||
\\includegraphics{lion.png}
|
# \\includegraphics{lion.png}
|
||||||
\\end{document}
|
# \\end{document}
|
||||||
'''
|
# '''
|
||||||
}, {
|
# }, {
|
||||||
path: "lion.png"
|
# path: "lion.png"
|
||||||
url: "http://#{host}:31415/#{@file}"
|
# url: "http://#{host}:31415/#{@file}"
|
||||||
}]
|
# }]
|
||||||
|
|
||||||
sinon.spy Server, "getFile"
|
# sinon.spy Server, "getFile"
|
||||||
ClsiApp.ensureRunning =>
|
# ClsiApp.ensureRunning =>
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) => done()
|
# Client.compile @project_id, @request, (@error, @res, @body) => done()
|
||||||
|
|
||||||
afterEach ->
|
# afterEach ->
|
||||||
Server.getFile.restore()
|
# Server.getFile.restore()
|
||||||
|
|
||||||
it "should download the image", ->
|
# it "should download the image", ->
|
||||||
Server.getFile
|
# Server.getFile
|
||||||
.calledWith("/" + @file)
|
# .calledWith("/" + @file)
|
||||||
.should.equal true
|
# .should.equal true
|
||||||
|
|
||||||
describe "When an image is in the cache and the last modified date is unchanged", ->
|
# describe "When an image is in the cache and the last modified date is unchanged", ->
|
||||||
before (done) ->
|
# before (done) ->
|
||||||
@project_id = Client.randomId()
|
# @project_id = Client.randomId()
|
||||||
@file = "#{Server.randomId()}/lion.png"
|
# @file = "#{Server.randomId()}/lion.png"
|
||||||
@request =
|
# @request =
|
||||||
resources: [{
|
# resources: [{
|
||||||
path: "main.tex"
|
# path: "main.tex"
|
||||||
content: '''
|
# content: '''
|
||||||
\\documentclass{article}
|
# \\documentclass{article}
|
||||||
\\usepackage{graphicx}
|
# \\usepackage{graphicx}
|
||||||
\\begin{document}
|
# \\begin{document}
|
||||||
\\includegraphics{lion.png}
|
# \\includegraphics{lion.png}
|
||||||
\\end{document}
|
# \\end{document}
|
||||||
'''
|
# '''
|
||||||
}, @image_resource = {
|
# }, @image_resource = {
|
||||||
path: "lion.png"
|
# path: "lion.png"
|
||||||
url: "http://#{host}:31415/#{@file}"
|
# url: "http://#{host}:31415/#{@file}"
|
||||||
modified: Date.now()
|
# modified: Date.now()
|
||||||
}]
|
# }]
|
||||||
|
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
sinon.spy Server, "getFile"
|
# sinon.spy Server, "getFile"
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
after ->
|
# after ->
|
||||||
Server.getFile.restore()
|
# Server.getFile.restore()
|
||||||
|
|
||||||
it "should not download the image again", ->
|
# it "should not download the image again", ->
|
||||||
Server.getFile.called.should.equal false
|
# Server.getFile.called.should.equal false
|
||||||
|
|
||||||
describe "When an image is in the cache and the last modified date is advanced", ->
|
# describe "When an image is in the cache and the last modified date is advanced", ->
|
||||||
before (done) ->
|
# before (done) ->
|
||||||
@project_id = Client.randomId()
|
# @project_id = Client.randomId()
|
||||||
@file = "#{Server.randomId()}/lion.png"
|
# @file = "#{Server.randomId()}/lion.png"
|
||||||
@request =
|
# @request =
|
||||||
resources: [{
|
# resources: [{
|
||||||
path: "main.tex"
|
# path: "main.tex"
|
||||||
content: '''
|
# content: '''
|
||||||
\\documentclass{article}
|
# \\documentclass{article}
|
||||||
\\usepackage{graphicx}
|
# \\usepackage{graphicx}
|
||||||
\\begin{document}
|
# \\begin{document}
|
||||||
\\includegraphics{lion.png}
|
# \\includegraphics{lion.png}
|
||||||
\\end{document}
|
# \\end{document}
|
||||||
'''
|
# '''
|
||||||
}, @image_resource = {
|
# }, @image_resource = {
|
||||||
path: "lion.png"
|
# path: "lion.png"
|
||||||
url: "http://#{host}:31415/#{@file}"
|
# url: "http://#{host}:31415/#{@file}"
|
||||||
modified: @last_modified = Date.now()
|
# modified: @last_modified = Date.now()
|
||||||
}]
|
# }]
|
||||||
|
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
sinon.spy Server, "getFile"
|
# sinon.spy Server, "getFile"
|
||||||
@image_resource.modified = new Date(@last_modified + 3000)
|
# @image_resource.modified = new Date(@last_modified + 3000)
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
afterEach ->
|
# afterEach ->
|
||||||
Server.getFile.restore()
|
# Server.getFile.restore()
|
||||||
|
|
||||||
it "should download the image again", ->
|
# it "should download the image again", ->
|
||||||
Server.getFile.called.should.equal true
|
# Server.getFile.called.should.equal true
|
||||||
|
|
||||||
describe "When an image is in the cache and the last modified date is further in the past", ->
|
# describe "When an image is in the cache and the last modified date is further in the past", ->
|
||||||
before (done) ->
|
# before (done) ->
|
||||||
@project_id = Client.randomId()
|
# @project_id = Client.randomId()
|
||||||
@file = "#{Server.randomId()}/lion.png"
|
# @file = "#{Server.randomId()}/lion.png"
|
||||||
@request =
|
# @request =
|
||||||
resources: [{
|
# resources: [{
|
||||||
path: "main.tex"
|
# path: "main.tex"
|
||||||
content: '''
|
# content: '''
|
||||||
\\documentclass{article}
|
# \\documentclass{article}
|
||||||
\\usepackage{graphicx}
|
# \\usepackage{graphicx}
|
||||||
\\begin{document}
|
# \\begin{document}
|
||||||
\\includegraphics{lion.png}
|
# \\includegraphics{lion.png}
|
||||||
\\end{document}
|
# \\end{document}
|
||||||
'''
|
# '''
|
||||||
}, @image_resource = {
|
# }, @image_resource = {
|
||||||
path: "lion.png"
|
# path: "lion.png"
|
||||||
url: "http://#{host}:31415/#{@file}"
|
# url: "http://#{host}:31415/#{@file}"
|
||||||
modified: @last_modified = Date.now()
|
# modified: @last_modified = Date.now()
|
||||||
}]
|
# }]
|
||||||
|
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
sinon.spy Server, "getFile"
|
# sinon.spy Server, "getFile"
|
||||||
@image_resource.modified = new Date(@last_modified - 3000)
|
# @image_resource.modified = new Date(@last_modified - 3000)
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
afterEach ->
|
# afterEach ->
|
||||||
Server.getFile.restore()
|
# Server.getFile.restore()
|
||||||
|
|
||||||
it "should not download the image again", ->
|
# it "should not download the image again", ->
|
||||||
Server.getFile.called.should.equal false
|
# Server.getFile.called.should.equal false
|
||||||
|
|
||||||
describe "When an image is in the cache and the last modified date is not specified", ->
|
# describe "When an image is in the cache and the last modified date is not specified", ->
|
||||||
before (done) ->
|
# before (done) ->
|
||||||
@project_id = Client.randomId()
|
# @project_id = Client.randomId()
|
||||||
@file = "#{Server.randomId()}/lion.png"
|
# @file = "#{Server.randomId()}/lion.png"
|
||||||
@request =
|
# @request =
|
||||||
resources: [{
|
# resources: [{
|
||||||
path: "main.tex"
|
# path: "main.tex"
|
||||||
content: '''
|
# content: '''
|
||||||
\\documentclass{article}
|
# \\documentclass{article}
|
||||||
\\usepackage{graphicx}
|
# \\usepackage{graphicx}
|
||||||
\\begin{document}
|
# \\begin{document}
|
||||||
\\includegraphics{lion.png}
|
# \\includegraphics{lion.png}
|
||||||
\\end{document}
|
# \\end{document}
|
||||||
'''
|
# '''
|
||||||
}, @image_resource = {
|
# }, @image_resource = {
|
||||||
path: "lion.png"
|
# path: "lion.png"
|
||||||
url: "http://#{host}:31415/#{@file}"
|
# url: "http://#{host}:31415/#{@file}"
|
||||||
modified: @last_modified = Date.now()
|
# modified: @last_modified = Date.now()
|
||||||
}]
|
# }]
|
||||||
|
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
sinon.spy Server, "getFile"
|
# sinon.spy Server, "getFile"
|
||||||
delete @image_resource.modified
|
# delete @image_resource.modified
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
afterEach ->
|
# afterEach ->
|
||||||
Server.getFile.restore()
|
# Server.getFile.restore()
|
||||||
|
|
||||||
it "should download the image again", ->
|
# it "should download the image again", ->
|
||||||
Server.getFile.called.should.equal true
|
# Server.getFile.called.should.equal true
|
||||||
|
|
||||||
describe "After clearing the cache", ->
|
# describe "After clearing the cache", ->
|
||||||
before (done) ->
|
# before (done) ->
|
||||||
@project_id = Client.randomId()
|
# @project_id = Client.randomId()
|
||||||
@file = "#{Server.randomId()}/lion.png"
|
# @file = "#{Server.randomId()}/lion.png"
|
||||||
@request =
|
# @request =
|
||||||
resources: [{
|
# resources: [{
|
||||||
path: "main.tex"
|
# path: "main.tex"
|
||||||
content: '''
|
# content: '''
|
||||||
\\documentclass{article}
|
# \\documentclass{article}
|
||||||
\\usepackage{graphicx}
|
# \\usepackage{graphicx}
|
||||||
\\begin{document}
|
# \\begin{document}
|
||||||
\\includegraphics{lion.png}
|
# \\includegraphics{lion.png}
|
||||||
\\end{document}
|
# \\end{document}
|
||||||
'''
|
# '''
|
||||||
}, @image_resource = {
|
# }, @image_resource = {
|
||||||
path: "lion.png"
|
# path: "lion.png"
|
||||||
url: "http://#{host}:31415/#{@file}"
|
# url: "http://#{host}:31415/#{@file}"
|
||||||
modified: @last_modified = Date.now()
|
# modified: @last_modified = Date.now()
|
||||||
}]
|
# }]
|
||||||
|
|
||||||
Client.compile @project_id, @request, (error) =>
|
# Client.compile @project_id, @request, (error) =>
|
||||||
throw error if error?
|
# throw error if error?
|
||||||
Client.clearCache @project_id, (error, res, body) =>
|
# Client.clearCache @project_id, (error, res, body) =>
|
||||||
throw error if error?
|
# throw error if error?
|
||||||
sinon.spy Server, "getFile"
|
# sinon.spy Server, "getFile"
|
||||||
Client.compile @project_id, @request, (@error, @res, @body) =>
|
# Client.compile @project_id, @request, (@error, @res, @body) =>
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
afterEach ->
|
# afterEach ->
|
||||||
Server.getFile.restore()
|
# Server.getFile.restore()
|
||||||
|
|
||||||
it "should download the image again", ->
|
# it "should download the image again", ->
|
||||||
Server.getFile.called.should.equal true
|
# Server.getFile.called.should.equal true
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
Client = require "./helpers/Client"
|
# Client = require "./helpers/Client"
|
||||||
request = require "request"
|
# request = require "request"
|
||||||
require("chai").should()
|
# require("chai").should()
|
||||||
expect = require("chai").expect
|
# expect = require("chai").expect
|
||||||
path = require("path")
|
# path = require("path")
|
||||||
fs = require("fs")
|
# fs = require("fs")
|
||||||
ClsiApp = require "./helpers/ClsiApp"
|
# ClsiApp = require "./helpers/ClsiApp"
|
||||||
|
|
||||||
describe "Syncing", ->
|
# describe "Syncing", ->
|
||||||
before (done) ->
|
# before (done) ->
|
||||||
@request =
|
# @request =
|
||||||
resources: [
|
# resources: [
|
||||||
path: "main.tex"
|
# path: "main.tex"
|
||||||
content: fs.readFileSync(path.join(__dirname,"../fixtures/naugty_strings.txt"),"utf-8")
|
# content: fs.readFileSync(path.join(__dirname,"../fixtures/naugty_strings.txt"),"utf-8")
|
||||||
]
|
# ]
|
||||||
@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 "wordcount file", ->
|
# describe "wordcount file", ->
|
||||||
it "should return wordcount info", (done) ->
|
# it "should return wordcount info", (done) ->
|
||||||
Client.wordcount @project_id, "main.tex", (error, result) ->
|
# Client.wordcount @project_id, "main.tex", (error, result) ->
|
||||||
throw error if error?
|
# throw error if error?
|
||||||
expect(result).to.deep.equal(
|
# expect(result).to.deep.equal(
|
||||||
texcount: {
|
# texcount: {
|
||||||
encode: "utf8"
|
# encode: "utf8"
|
||||||
textWords: 2281
|
# textWords: 2281
|
||||||
headWords: 2
|
# headWords: 2
|
||||||
outside: 0
|
# outside: 0
|
||||||
headers: 2
|
# headers: 2
|
||||||
elements: 0
|
# elements: 0
|
||||||
mathInline: 6
|
# mathInline: 6
|
||||||
mathDisplay: 0
|
# mathDisplay: 0
|
||||||
errors: 0
|
# errors: 0
|
||||||
messages: ""
|
# messages: ""
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
done()
|
# done()
|
||||||
|
|||||||
Reference in New Issue
Block a user