[misc] bump the dev-env to 3.3.2

This commit is contained in:
Jakob Ackermann
2020-08-10 17:01:11 +01:00
parent 1ee48d0274
commit f4561c2fe2
66 changed files with 1371 additions and 1458 deletions

View File

@@ -2,8 +2,8 @@ const Client = require('./helpers/Client')
const ClsiApp = require('./helpers/ClsiApp')
const { expect } = require('chai')
describe('AllowedImageNames', function() {
beforeEach(function(done) {
describe('AllowedImageNames', function () {
beforeEach(function (done) {
this.project_id = Client.randomId()
this.request = {
options: {
@@ -24,8 +24,8 @@ Hello world
ClsiApp.ensureRunning(done)
})
describe('with a valid name', function() {
beforeEach(function(done) {
describe('with a valid name', function () {
beforeEach(function (done) {
this.request.options.imageName = process.env.TEXLIVE_IMAGE
Client.compile(this.project_id, this.request, (error, res, body) => {
@@ -35,11 +35,11 @@ Hello world
done(error)
})
})
it('should return success', function() {
it('should return success', function () {
expect(this.res.statusCode).to.equal(200)
})
it('should return a PDF', function() {
it('should return a PDF', function () {
let pdf
try {
pdf = Client.getOutputFile(this.body, 'pdf')
@@ -48,8 +48,8 @@ Hello world
})
})
describe('with an invalid name', function() {
beforeEach(function(done) {
describe('with an invalid name', function () {
beforeEach(function (done) {
this.request.options.imageName = 'something/evil:1337'
Client.compile(this.project_id, this.request, (error, res, body) => {
this.error = error
@@ -58,11 +58,11 @@ Hello world
done(error)
})
})
it('should return non success', function() {
it('should return non success', function () {
expect(this.res.statusCode).to.not.equal(200)
})
it('should not return a PDF', function() {
it('should not return a PDF', function () {
let pdf
try {
pdf = Client.getOutputFile(this.body, 'pdf')
@@ -71,11 +71,11 @@ Hello world
})
})
describe('wordcount', function() {
beforeEach(function(done) {
describe('wordcount', function () {
beforeEach(function (done) {
Client.compile(this.project_id, this.request, done)
})
it('should error out with an invalid imageName', function() {
it('should error out with an invalid imageName', function () {
Client.wordcountWithImage(
this.project_id,
'main.tex',
@@ -86,7 +86,7 @@ Hello world
)
})
it('should produce a texcout a valid imageName', function() {
it('should produce a texcout a valid imageName', function () {
Client.wordcountWithImage(
this.project_id,
'main.tex',

View File

@@ -13,8 +13,8 @@ const request = require('request')
require('chai').should()
const ClsiApp = require('./helpers/ClsiApp')
describe('Broken LaTeX file', function() {
before(function(done) {
describe('Broken LaTeX file', function () {
before(function (done) {
this.broken_request = {
resources: [
{
@@ -44,8 +44,8 @@ Hello world
return ClsiApp.ensureRunning(done)
})
describe('on first run', function() {
before(function(done) {
describe('on first run', function () {
before(function (done) {
this.project_id = Client.randomId()
return Client.compile(
this.project_id,
@@ -59,13 +59,13 @@ Hello world
)
})
return it('should return a failure status', function() {
return it('should return a failure status', function () {
return this.body.compile.status.should.equal('failure')
})
})
return describe('on second run', function() {
before(function(done) {
return describe('on second run', function () {
before(function (done) {
this.project_id = Client.randomId()
return Client.compile(this.project_id, this.correct_request, () => {
return Client.compile(
@@ -81,7 +81,7 @@ Hello world
})
})
return it('should return a failure status', function() {
return it('should return a failure status', function () {
return this.body.compile.status.should.equal('failure')
})
})

View File

@@ -13,8 +13,8 @@ const request = require('request')
require('chai').should()
const ClsiApp = require('./helpers/ClsiApp')
describe('Deleting Old Files', function() {
before(function(done) {
describe('Deleting Old Files', function () {
before(function (done) {
this.request = {
resources: [
{
@@ -31,8 +31,8 @@ Hello world
return ClsiApp.ensureRunning(done)
})
return describe('on first run', function() {
before(function(done) {
return describe('on first run', function () {
before(function (done) {
this.project_id = Client.randomId()
return Client.compile(
this.project_id,
@@ -46,12 +46,12 @@ Hello world
)
})
it('should return a success status', function() {
it('should return a success status', function () {
return this.body.compile.status.should.equal('success')
})
return describe('after file has been deleted', function() {
before(function(done) {
return describe('after file has been deleted', function () {
before(function (done) {
this.request.resources = []
return Client.compile(
this.project_id,
@@ -65,7 +65,7 @@ Hello world
)
})
return it('should return a failure status', function() {
return it('should return a failure status', function () {
return this.body.compile.status.should.equal('failure')
})
})

View File

@@ -24,7 +24,7 @@ const ChildProcess = require('child_process')
const ClsiApp = require('./helpers/ClsiApp')
const logger = require('logger-sharelatex')
const Path = require('path')
const fixturePath = path => {
const fixturePath = (path) => {
if (path.slice(0, 3) === 'tmp') {
return '/tmp/clsi_acceptance_tests' + path.slice(3)
}
@@ -41,23 +41,23 @@ console.log(
const MOCHA_LATEX_TIMEOUT = 60 * 1000
const convertToPng = function(pdfPath, pngPath, callback) {
const convertToPng = function (pdfPath, pngPath, callback) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
const command = `convert ${fixturePath(pdfPath)} ${fixturePath(pngPath)}`
console.log('COMMAND')
console.log(command)
const convert = ChildProcess.exec(command)
const stdout = ''
convert.stdout.on('data', chunk => console.log('STDOUT', chunk.toString()))
convert.stderr.on('data', chunk => console.log('STDERR', chunk.toString()))
convert.stdout.on('data', (chunk) => console.log('STDOUT', chunk.toString()))
convert.stderr.on('data', (chunk) => console.log('STDERR', chunk.toString()))
return convert.on('exit', () => callback())
}
const compare = function(originalPath, generatedPath, callback) {
const compare = function (originalPath, generatedPath, callback) {
if (callback == null) {
callback = function(error, same) {}
callback = function (error, same) {}
}
const diff_file = `${fixturePath(generatedPath)}-diff.png`
const proc = ChildProcess.exec(
@@ -66,11 +66,11 @@ const compare = function(originalPath, generatedPath, callback) {
)} ${diff_file}`
)
let stderr = ''
proc.stderr.on('data', chunk => (stderr += chunk))
proc.stderr.on('data', (chunk) => (stderr += chunk))
return proc.on('exit', () => {
if (stderr.trim() === '0 (0)') {
// remove output diff if test matches expected image
fs.unlink(diff_file, err => {
fs.unlink(diff_file, (err) => {
if (err) {
throw err
}
@@ -83,14 +83,14 @@ const compare = function(originalPath, generatedPath, callback) {
})
}
const checkPdfInfo = function(pdfPath, callback) {
const checkPdfInfo = function (pdfPath, callback) {
if (callback == null) {
callback = function(error, output) {}
callback = function (error, output) {}
}
const proc = ChildProcess.exec(`pdfinfo ${fixturePath(pdfPath)}`)
let stdout = ''
proc.stdout.on('data', chunk => (stdout += chunk))
proc.stderr.on('data', chunk => console.log('STDERR', chunk.toString()))
proc.stdout.on('data', (chunk) => (stdout += chunk))
proc.stderr.on('data', (chunk) => console.log('STDERR', chunk.toString()))
return proc.on('exit', () => {
if (stdout.match(/Optimized:\s+yes/)) {
return callback(null, true)
@@ -100,11 +100,11 @@ const checkPdfInfo = function(pdfPath, callback) {
})
}
const compareMultiplePages = function(project_id, callback) {
const compareMultiplePages = function (project_id, callback) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
var compareNext = function(page_no, callback) {
var compareNext = function (page_no, callback) {
const path = `tmp/${project_id}-source-${page_no}.png`
return fs.stat(fixturePath(path), (error, stat) => {
if (error != null) {
@@ -127,23 +127,23 @@ const compareMultiplePages = function(project_id, callback) {
return compareNext(0, callback)
}
const comparePdf = function(project_id, example_dir, callback) {
const comparePdf = function (project_id, example_dir, callback) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
console.log('CONVERT')
console.log(`tmp/${project_id}.pdf`, `tmp/${project_id}-generated.png`)
return convertToPng(
`tmp/${project_id}.pdf`,
`tmp/${project_id}-generated.png`,
error => {
(error) => {
if (error != null) {
throw error
}
return convertToPng(
`examples/${example_dir}/output.pdf`,
`tmp/${project_id}-source.png`,
error => {
(error) => {
if (error != null) {
throw error
}
@@ -163,7 +163,7 @@ const comparePdf = function(project_id, example_dir, callback) {
}
)
} else {
return compareMultiplePages(project_id, error => {
return compareMultiplePages(project_id, (error) => {
if (error != null) {
throw error
}
@@ -178,9 +178,14 @@ const comparePdf = function(project_id, example_dir, callback) {
)
}
const downloadAndComparePdf = function(project_id, example_dir, url, callback) {
const downloadAndComparePdf = function (
project_id,
example_dir,
url,
callback
) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
const writeStream = fs.createWriteStream(fixturePath(`tmp/${project_id}.pdf`))
request.get(url).pipe(writeStream)
@@ -198,85 +203,96 @@ const downloadAndComparePdf = function(project_id, example_dir, url, callback) {
Client.runServer(4242, fixturePath('examples'))
describe('Example Documents', function() {
before(function(done) {
describe('Example Documents', function () {
before(function (done) {
ClsiApp.ensureRunning(done)
})
before(function(done) {
before(function (done) {
fsExtra.remove(fixturePath('tmp'), done)
})
before(function(done) {
before(function (done) {
fs.mkdir(fixturePath('tmp'), done)
})
after(function(done) {
after(function (done) {
fsExtra.remove(fixturePath('tmp'), done)
})
return Array.from(fs.readdirSync(fixturePath('examples'))).map(example_dir =>
(example_dir =>
describe(example_dir, function() {
before(function() {
return (this.project_id = Client.randomId() + '_' + example_dir)
})
return Array.from(fs.readdirSync(fixturePath('examples'))).map(
(example_dir) =>
((example_dir) =>
describe(example_dir, function () {
before(function () {
return (this.project_id = Client.randomId() + '_' + example_dir)
})
it('should generate the correct pdf', function(done) {
this.timeout(MOCHA_LATEX_TIMEOUT)
return Client.compileDirectory(
this.project_id,
fixturePath('examples'),
example_dir,
4242,
(error, res, body) => {
if (
error ||
__guard__(
body != null ? body.compile : undefined,
x => x.status
) === 'failure'
) {
console.log('DEBUG: error', error, 'body', JSON.stringify(body))
return done(new Error('Compile failed'))
it('should generate the correct pdf', function (done) {
this.timeout(MOCHA_LATEX_TIMEOUT)
return Client.compileDirectory(
this.project_id,
fixturePath('examples'),
example_dir,
4242,
(error, res, body) => {
if (
error ||
__guard__(
body != null ? body.compile : undefined,
(x) => x.status
) === 'failure'
) {
console.log(
'DEBUG: error',
error,
'body',
JSON.stringify(body)
)
return done(new Error('Compile failed'))
}
const pdf = Client.getOutputFile(body, 'pdf')
return downloadAndComparePdf(
this.project_id,
example_dir,
pdf.url,
done
)
}
const pdf = Client.getOutputFile(body, 'pdf')
return downloadAndComparePdf(
this.project_id,
example_dir,
pdf.url,
done
)
}
)
})
)
})
return it('should generate the correct pdf on the second run as well', function(done) {
this.timeout(MOCHA_LATEX_TIMEOUT)
return Client.compileDirectory(
this.project_id,
fixturePath('examples'),
example_dir,
4242,
(error, res, body) => {
if (
error ||
__guard__(
body != null ? body.compile : undefined,
x => x.status
) === 'failure'
) {
console.log('DEBUG: error', error, 'body', JSON.stringify(body))
return done(new Error('Compile failed'))
return it('should generate the correct pdf on the second run as well', function (done) {
this.timeout(MOCHA_LATEX_TIMEOUT)
return Client.compileDirectory(
this.project_id,
fixturePath('examples'),
example_dir,
4242,
(error, res, body) => {
if (
error ||
__guard__(
body != null ? body.compile : undefined,
(x) => x.status
) === 'failure'
) {
console.log(
'DEBUG: error',
error,
'body',
JSON.stringify(body)
)
return done(new Error('Compile failed'))
}
const pdf = Client.getOutputFile(body, 'pdf')
return downloadAndComparePdf(
this.project_id,
example_dir,
pdf.url,
done
)
}
const pdf = Client.getOutputFile(body, 'pdf')
return downloadAndComparePdf(
this.project_id,
example_dir,
pdf.url,
done
)
}
)
})
}))(example_dir)
)
})
}))(example_dir)
)
})

View File

@@ -13,8 +13,8 @@ const request = require('request')
require('chai').should()
const ClsiApp = require('./helpers/ClsiApp')
describe('Simple LaTeX file', function() {
before(function(done) {
describe('Simple LaTeX file', function () {
before(function (done) {
this.project_id = Client.randomId()
this.request = {
resources: [
@@ -43,17 +43,17 @@ Hello world
})
})
it('should return the PDF', function() {
it('should return the PDF', function () {
const pdf = Client.getOutputFile(this.body, 'pdf')
return pdf.type.should.equal('pdf')
})
it('should return the log', function() {
it('should return the log', function () {
const log = Client.getOutputFile(this.body, 'log')
return log.type.should.equal('log')
})
it('should provide the pdf for download', function(done) {
it('should provide the pdf for download', function (done) {
const pdf = Client.getOutputFile(this.body, 'pdf')
return request.get(pdf.url, (error, res, body) => {
res.statusCode.should.equal(200)
@@ -61,7 +61,7 @@ Hello world
})
})
return it('should provide the log for download', function(done) {
return it('should provide the log for download', function (done) {
const log = Client.getOutputFile(this.body, 'pdf')
return request.get(log.url, (error, res, body) => {
res.statusCode.should.equal(200)

View File

@@ -16,8 +16,8 @@ const { expect } = require('chai')
const ClsiApp = require('./helpers/ClsiApp')
const crypto = require('crypto')
describe('Syncing', function() {
before(function(done) {
describe('Syncing', function () {
before(function (done) {
const content = `\
\\documentclass{article}
\\begin{document}
@@ -47,8 +47,8 @@ Hello world
})
})
describe('from code to pdf', function() {
return it('should return the correct location', function(done) {
describe('from code to pdf', function () {
return it('should return the correct location', function (done) {
return Client.syncFromCode(
this.project_id,
'main.tex',
@@ -69,8 +69,8 @@ Hello world
})
})
describe('from pdf to code', function() {
return it('should return the correct location', function(done) {
describe('from pdf to code', function () {
return it('should return the correct location', function (done) {
return Client.syncFromPdf(
this.project_id,
1,
@@ -89,12 +89,12 @@ Hello world
})
})
describe('when the project directory is not available', function() {
before(function() {
describe('when the project directory is not available', function () {
before(function () {
this.other_project_id = Client.randomId()
})
describe('from code to pdf', function() {
it('should return a 404 response', function(done) {
describe('from code to pdf', function () {
it('should return a 404 response', function (done) {
return Client.syncFromCode(
this.other_project_id,
'main.tex',
@@ -110,8 +110,8 @@ Hello world
)
})
})
describe('from pdf to code', function() {
it('should return a 404 response', function(done) {
describe('from pdf to code', function () {
it('should return a 404 response', function (done) {
return Client.syncFromPdf(
this.other_project_id,
1,
@@ -129,8 +129,8 @@ Hello world
})
})
describe('when the synctex file is not available', function() {
before(function(done) {
describe('when the synctex file is not available', function () {
before(function (done) {
this.broken_project_id = Client.randomId()
const content = 'this is not valid tex' // not a valid tex file
this.request = {
@@ -153,8 +153,8 @@ Hello world
)
})
describe('from code to pdf', function() {
it('should return a 404 response', function(done) {
describe('from code to pdf', function () {
it('should return a 404 response', function (done) {
return Client.syncFromCode(
this.broken_project_id,
'main.tex',
@@ -170,8 +170,8 @@ Hello world
)
})
})
describe('from pdf to code', function() {
it('should return a 404 response', function(done) {
describe('from pdf to code', function () {
it('should return a 404 response', function (done) {
return Client.syncFromPdf(
this.broken_project_id,
1,

View File

@@ -13,8 +13,8 @@ const request = require('request')
require('chai').should()
const ClsiApp = require('./helpers/ClsiApp')
describe('Timed out compile', function() {
before(function(done) {
describe('Timed out compile', function () {
before(function (done) {
this.request = {
options: {
timeout: 10
@@ -47,16 +47,16 @@ describe('Timed out compile', function() {
})
})
it('should return a timeout error', function() {
it('should return a timeout error', function () {
return this.body.compile.error.should.equal('container timed out')
})
it('should return a timedout status', function() {
it('should return a timedout status', function () {
return this.body.compile.status.should.equal('timedout')
})
return it('should return the log output file name', function() {
const outputFilePaths = this.body.compile.outputFiles.map(x => x.path)
return it('should return the log output file name', function () {
const outputFilePaths = this.body.compile.outputFiles.map((x) => x.path)
return outputFilePaths.should.include('output.log')
})
})

View File

@@ -35,17 +35,15 @@ const Server = {
getFile() {},
randomId() {
return Math.random()
.toString(16)
.slice(2)
return Math.random().toString(16).slice(2)
}
}
Server.run()
describe('Url Caching', function() {
describe('Downloading an image for the first time', function() {
before(function(done) {
describe('Url Caching', function () {
describe('Downloading an image for the first time', function () {
before(function (done) {
this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`
this.request = {
@@ -82,17 +80,17 @@ describe('Url Caching', function() {
})
})
afterEach(function() {
afterEach(function () {
return Server.getFile.restore()
})
return it('should download the image', function() {
return it('should download the image', function () {
return Server.getFile.calledWith(`/${this.file}`).should.equal(true)
})
})
describe('When an image is in the cache and the last modified date is unchanged', function() {
before(function(done) {
describe('When an image is in the cache and the last modified date is unchanged', function () {
before(function (done) {
this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`
this.request = {
@@ -137,17 +135,17 @@ describe('Url Caching', function() {
)
})
after(function() {
after(function () {
return Server.getFile.restore()
})
return it('should not download the image again', function() {
return it('should not download the image again', function () {
return Server.getFile.called.should.equal(false)
})
})
describe('When an image is in the cache and the last modified date is advanced', function() {
before(function(done) {
describe('When an image is in the cache and the last modified date is advanced', function () {
before(function (done) {
this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`
this.request = {
@@ -193,17 +191,17 @@ describe('Url Caching', function() {
)
})
afterEach(function() {
afterEach(function () {
return Server.getFile.restore()
})
return it('should download the image again', function() {
return it('should download the image again', function () {
return Server.getFile.called.should.equal(true)
})
})
describe('When an image is in the cache and the last modified date is further in the past', function() {
before(function(done) {
describe('When an image is in the cache and the last modified date is further in the past', function () {
before(function (done) {
this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`
this.request = {
@@ -249,17 +247,17 @@ describe('Url Caching', function() {
)
})
afterEach(function() {
afterEach(function () {
return Server.getFile.restore()
})
return it('should not download the image again', function() {
return it('should not download the image again', function () {
return Server.getFile.called.should.equal(false)
})
})
describe('When an image is in the cache and the last modified date is not specified', function() {
before(function(done) {
describe('When an image is in the cache and the last modified date is not specified', function () {
before(function (done) {
this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`
this.request = {
@@ -305,17 +303,17 @@ describe('Url Caching', function() {
)
})
afterEach(function() {
afterEach(function () {
return Server.getFile.restore()
})
return it('should download the image again', function() {
return it('should download the image again', function () {
return Server.getFile.called.should.equal(true)
})
})
return describe('After clearing the cache', function() {
before(function(done) {
return describe('After clearing the cache', function () {
before(function (done) {
this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`
this.request = {
@@ -338,7 +336,7 @@ describe('Url Caching', function() {
]
}
return Client.compile(this.project_id, this.request, error => {
return Client.compile(this.project_id, this.request, (error) => {
if (error != null) {
throw error
}
@@ -361,11 +359,11 @@ describe('Url Caching', function() {
})
})
afterEach(function() {
afterEach(function () {
return Server.getFile.restore()
})
return it('should download the image again', function() {
return it('should download the image again', function () {
return Server.getFile.called.should.equal(true)
})
})

View File

@@ -17,8 +17,8 @@ const path = require('path')
const fs = require('fs')
const ClsiApp = require('./helpers/ClsiApp')
describe('Syncing', function() {
before(function(done) {
describe('Syncing', function () {
before(function (done) {
this.request = {
resources: [
{
@@ -45,8 +45,8 @@ describe('Syncing', function() {
})
})
return describe('wordcount file', function() {
return it('should return wordcount info', function(done) {
return describe('wordcount file', function () {
return it('should return wordcount info', function (done) {
return Client.wordcount(this.project_id, 'main.tex', (error, result) => {
if (error != null) {
throw error

View File

@@ -23,14 +23,12 @@ module.exports = Client = {
host: Settings.apis.clsi.url,
randomId() {
return Math.random()
.toString(16)
.slice(2)
return Math.random().toString(16).slice(2)
},
compile(project_id, data, callback) {
if (callback == null) {
callback = function(error, res, body) {}
callback = function (error, res, body) {}
}
return request.post(
{
@@ -45,7 +43,7 @@ module.exports = Client = {
clearCache(project_id, callback) {
if (callback == null) {
callback = function(error, res, body) {}
callback = function (error, res, body) {}
}
return request.del(`${this.host}/project/${project_id}`, callback)
},
@@ -64,7 +62,7 @@ module.exports = Client = {
const app = express()
app.use(express.static(directory))
console.log('starting test server on', port, host)
return app.listen(port, host).on('error', error => {
return app.listen(port, host).on('error', (error) => {
console.error('error starting server:', error.message)
return process.exit(1)
})
@@ -72,7 +70,7 @@ module.exports = Client = {
syncFromCode(project_id, file, line, column, callback) {
if (callback == null) {
callback = function(error, pdfPositions) {}
callback = function (error, pdfPositions) {}
}
return request.get(
{
@@ -95,7 +93,7 @@ module.exports = Client = {
syncFromPdf(project_id, page, h, v, callback) {
if (callback == null) {
callback = function(error, pdfPositions) {}
callback = function (error, pdfPositions) {}
}
return request.get(
{
@@ -118,7 +116,7 @@ module.exports = Client = {
compileDirectory(project_id, baseDirectory, directory, serverPort, callback) {
if (callback == null) {
callback = function(error, res, body) {}
callback = function (error, res, body) {}
}
const resources = []
let entities = fs.readdirSync(`${baseDirectory}/${directory}`)
@@ -130,7 +128,7 @@ module.exports = Client = {
entities = entities.concat(
fs
.readdirSync(`${baseDirectory}/${directory}/${entity}`)
.map(subEntity => {
.map((subEntity) => {
if (subEntity === 'main.tex') {
rootResourcePath = `${entity}/${subEntity}`
}
@@ -195,7 +193,7 @@ module.exports = Client = {
wordcountWithImage(project_id, file, image, callback) {
if (callback == null) {
callback = function(error, pdfPositions) {}
callback = function (error, pdfPositions) {}
}
return request.get(
{

View File

@@ -23,7 +23,7 @@ module.exports = {
callbacks: [],
ensureRunning(callback) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
if (this.running) {
return callback()
@@ -35,10 +35,10 @@ module.exports = {
return app.listen(
__guard__(
Settings.internal != null ? Settings.internal.clsi : undefined,
x => x.port
(x) => x.port
),
'localhost',
error => {
(error) => {
if (error != null) {
throw error
}