prettier: convert test/acceptance decaffeinated files to Prettier format

This commit is contained in:
mserranom 2020-02-19 12:16:14 +01:00
parent c5a6496b71
commit 778f2a8420
10 changed files with 1105 additions and 771 deletions

View file

@ -8,16 +8,17 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const Client = require("./helpers/Client"); const Client = require('./helpers/Client')
const request = require("request"); const request = require('request')
require("chai").should(); require('chai').should()
const ClsiApp = require("./helpers/ClsiApp"); const ClsiApp = require('./helpers/ClsiApp')
describe("Broken LaTeX file", function() { describe('Broken LaTeX file', function() {
before(function(done) { before(function(done) {
this.broken_request = { this.broken_request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{articl % :( \\documentclass{articl % :(
\\begin{documen % :( \\begin{documen % :(
@ -26,10 +27,11 @@ Broken
` `
} }
] ]
}; }
this.correct_request = { this.correct_request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
@ -38,38 +40,49 @@ Hello world
` `
} }
] ]
}; }
return ClsiApp.ensureRunning(done); return ClsiApp.ensureRunning(done)
}); })
describe("on first run", function() { describe('on first run', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
return Client.compile(this.project_id, this.broken_request, (error, res, body) => { this.error = error; this.res = res; this.body = body; return done(); }); return Client.compile(
}); this.project_id,
this.broken_request,
(error, res, body) => {
this.error = error
this.res = res
this.body = body
return done()
}
)
})
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 this.body.compile.status.should.equal('failure')
}); })
}); })
return describe("on second run", function() { return describe('on second run', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
return Client.compile(this.project_id, this.correct_request, () => { return Client.compile(this.project_id, this.correct_request, () => {
return Client.compile(this.project_id, this.broken_request, (error, res, body) => { return Client.compile(
this.error = error; this.project_id,
this.res = res; this.broken_request,
this.body = body; (error, res, body) => {
return done(); this.error = error
}); this.res = res
}); this.body = body
}); return done()
}
return it("should return a failure status", function() { )
return this.body.compile.status.should.equal("failure"); })
}); })
});
});
return it('should return a failure status', function() {
return this.body.compile.status.should.equal('failure')
})
})
})

View file

@ -8,16 +8,17 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const Client = require("./helpers/Client"); const Client = require('./helpers/Client')
const request = require("request"); const request = require('request')
require("chai").should(); require('chai').should()
const ClsiApp = require("./helpers/ClsiApp"); const ClsiApp = require('./helpers/ClsiApp')
describe("Deleting Old Files", function() { describe('Deleting Old Files', function() {
before(function(done) { before(function(done) {
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
@ -26,35 +27,47 @@ Hello world
` `
} }
] ]
}; }
return ClsiApp.ensureRunning(done); return ClsiApp.ensureRunning(done)
}); })
return describe("on first run", function() { return describe('on first run', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
return Client.compile(this.project_id, this.request, (error, res, body) => { this.error = error; this.res = res; this.body = body; return done(); }); return Client.compile(
}); this.project_id,
this.request,
(error, res, body) => {
this.error = error
this.res = res
this.body = body
return done()
}
)
})
it("should return a success status", function() { it('should return a success status', function() {
return this.body.compile.status.should.equal("success"); return this.body.compile.status.should.equal('success')
}); })
return describe("after file has been deleted", function() { return describe('after file has been deleted', function() {
before(function(done) { before(function(done) {
this.request.resources = []; this.request.resources = []
return Client.compile(this.project_id, this.request, (error, res, body) => { return Client.compile(
this.error = error; this.project_id,
this.res = res; this.request,
this.body = body; (error, res, body) => {
return done(); this.error = error
}); this.res = res
}); this.body = body
return done()
return it("should return a failure status", function() { }
return this.body.compile.status.should.equal("failure"); )
}); })
});
});
});
return it('should return a failure status', function() {
return this.body.compile.status.should.equal('failure')
})
})
})
})

View file

@ -15,176 +15,266 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const Client = require("./helpers/Client"); const Client = require('./helpers/Client')
const request = require("request"); const request = require('request')
require("chai").should(); require('chai').should()
const fs = require("fs"); const fs = require('fs')
const ChildProcess = require("child_process"); const ChildProcess = require('child_process')
const ClsiApp = require("./helpers/ClsiApp"); const ClsiApp = require('./helpers/ClsiApp')
const logger = require("logger-sharelatex"); const logger = require('logger-sharelatex')
const Path = require("path"); const Path = require('path')
const fixturePath = path => Path.normalize(__dirname + "/../fixtures/" + path); const fixturePath = path => Path.normalize(__dirname + '/../fixtures/' + path)
const process = require("process"); const process = require('process')
console.log(process.pid, process.ppid, process.getuid(),process.getgroups(), "PID"); console.log(
process.pid,
process.ppid,
process.getuid(),
process.getgroups(),
'PID'
)
try { try {
console.log("creating tmp directory", fixturePath("tmp")); console.log('creating tmp directory', fixturePath('tmp'))
fs.mkdirSync(fixturePath("tmp")); fs.mkdirSync(fixturePath('tmp'))
} catch (error) { } catch (error) {
const err = error; const err = error
console.log(err, fixturePath("tmp"), "unable to create fixture tmp path"); console.log(err, fixturePath('tmp'), 'unable to create fixture tmp path')
} }
const MOCHA_LATEX_TIMEOUT = 60 * 1000; const MOCHA_LATEX_TIMEOUT = 60 * 1000
const convertToPng = function(pdfPath, pngPath, callback) { const convertToPng = function(pdfPath, pngPath, callback) {
if (callback == null) { callback = function(error) {}; } if (callback == null) {
const command = `convert ${fixturePath(pdfPath)} ${fixturePath(pngPath)}`; callback = function(error) {}
console.log("COMMAND"); }
console.log(command); const command = `convert ${fixturePath(pdfPath)} ${fixturePath(pngPath)}`
const convert = ChildProcess.exec(command); console.log('COMMAND')
const stdout = ""; console.log(command)
convert.stdout.on("data", chunk => console.log("STDOUT", chunk.toString())); const convert = ChildProcess.exec(command)
convert.stderr.on("data", chunk => console.log("STDERR", chunk.toString())); const stdout = ''
return convert.on("exit", () => callback()); 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) {}; } if (callback == null) {
const diff_file = `${fixturePath(generatedPath)}-diff.png`; callback = function(error, same) {}
const proc = ChildProcess.exec(`compare -metric mae ${fixturePath(originalPath)} ${fixturePath(generatedPath)} ${diff_file}`); }
let stderr = ""; const diff_file = `${fixturePath(generatedPath)}-diff.png`
proc.stderr.on("data", chunk => stderr += chunk); const proc = ChildProcess.exec(
return proc.on("exit", () => { `compare -metric mae ${fixturePath(originalPath)} ${fixturePath(
if (stderr.trim() === "0 (0)") { generatedPath
)} ${diff_file}`
)
let stderr = ''
proc.stderr.on('data', chunk => (stderr += chunk))
return proc.on('exit', () => {
if (stderr.trim() === '0 (0)') {
// remove output diff if test matches expected image // remove output diff if test matches expected image
fs.unlink(diff_file, (err) => { fs.unlink(diff_file, err => {
if (err) { if (err) {
throw err; throw err
} }
}); })
return callback(null, true); return callback(null, true)
} else { } else {
console.log("compare result", stderr); console.log('compare result', stderr)
return callback(null, false); return callback(null, false)
}
})
} }
});
};
const checkPdfInfo = function(pdfPath, callback) { const checkPdfInfo = function(pdfPath, callback) {
if (callback == null) { callback = function(error, output) {}; } if (callback == null) {
const proc = ChildProcess.exec(`pdfinfo ${fixturePath(pdfPath)}`); callback = function(error, output) {}
let stdout = ""; }
proc.stdout.on("data", chunk => stdout += chunk); const proc = ChildProcess.exec(`pdfinfo ${fixturePath(pdfPath)}`)
proc.stderr.on("data", chunk => console.log("STDERR", chunk.toString())); let stdout = ''
return proc.on("exit", () => { proc.stdout.on('data', chunk => (stdout += chunk))
if (stdout.match(/Optimized:\s+yes/)) { proc.stderr.on('data', chunk => console.log('STDERR', chunk.toString()))
return callback(null, true); return proc.on('exit', () => {
} else { if (stdout.match(/Optimized:\s+yes/)) {
return callback(null, false); return callback(null, true)
} else {
return callback(null, false)
}
})
} }
});
};
const compareMultiplePages = function(project_id, callback) { const compareMultiplePages = function(project_id, callback) {
if (callback == null) { callback = function(error) {}; } if (callback == null) {
callback = function(error) {}
}
var compareNext = function(page_no, callback) { var compareNext = function(page_no, callback) {
const path = `tmp/${project_id}-source-${page_no}.png`; const path = `tmp/${project_id}-source-${page_no}.png`
return fs.stat(fixturePath(path), (error, stat) => { return fs.stat(fixturePath(path), (error, stat) => {
if (error != null) { if (error != null) {
return callback(); return callback()
} else { } else {
return compare(`tmp/${project_id}-source-${page_no}.png`, `tmp/${project_id}-generated-${page_no}.png`, (error, same) => { return compare(
if (error != null) { throw error; } `tmp/${project_id}-source-${page_no}.png`,
same.should.equal(true); `tmp/${project_id}-generated-${page_no}.png`,
return compareNext(page_no + 1, callback); (error, same) => {
}); if (error != null) {
throw error
}
same.should.equal(true)
return compareNext(page_no + 1, callback)
}
)
}
})
}
return compareNext(0, 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) {}; } if (callback == null) {
console.log("CONVERT"); callback = function(error) {}
console.log(`tmp/${project_id}.pdf`, `tmp/${project_id}-generated.png`); }
return convertToPng(`tmp/${project_id}.pdf`, `tmp/${project_id}-generated.png`, error => { console.log('CONVERT')
if (error != null) { throw error; } console.log(`tmp/${project_id}.pdf`, `tmp/${project_id}-generated.png`)
return convertToPng(`examples/${example_dir}/output.pdf`, `tmp/${project_id}-source.png`, error => { return convertToPng(
if (error != null) { throw error; } `tmp/${project_id}.pdf`,
return fs.stat(fixturePath(`tmp/${project_id}-source-0.png`), (error, stat) => { `tmp/${project_id}-generated.png`,
if (error != null) { error => {
return compare(`tmp/${project_id}-source.png`, `tmp/${project_id}-generated.png`, (error, same) => { if (error != null) {
if (error != null) { throw error; } throw error
same.should.equal(true); }
return callback(); return convertToPng(
}); `examples/${example_dir}/output.pdf`,
} else { `tmp/${project_id}-source.png`,
return compareMultiplePages(project_id, (error) => { error => {
if (error != null) { throw error; } if (error != null) {
return callback(); throw error
}); }
return fs.stat(
fixturePath(`tmp/${project_id}-source-0.png`),
(error, stat) => {
if (error != null) {
return compare(
`tmp/${project_id}-source.png`,
`tmp/${project_id}-generated.png`,
(error, same) => {
if (error != null) {
throw error
}
same.should.equal(true)
return callback()
}
)
} else {
return compareMultiplePages(project_id, error => {
if (error != null) {
throw error
}
return 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) {}; } if (callback == null) {
const writeStream = fs.createWriteStream(fixturePath(`tmp/${project_id}.pdf`)); callback = function(error) {}
request.get(url).pipe(writeStream); }
console.log("writing file out", fixturePath(`tmp/${project_id}.pdf`)); const writeStream = fs.createWriteStream(fixturePath(`tmp/${project_id}.pdf`))
return writeStream.on("close", () => { request.get(url).pipe(writeStream)
console.log('writing file out', fixturePath(`tmp/${project_id}.pdf`))
return writeStream.on('close', () => {
return checkPdfInfo(`tmp/${project_id}.pdf`, (error, optimised) => { return checkPdfInfo(`tmp/${project_id}.pdf`, (error, optimised) => {
if (error != null) { throw error; } if (error != null) {
optimised.should.equal(true); throw error
return comparePdf(project_id, example_dir, callback); }
}); optimised.should.equal(true)
}); return comparePdf(project_id, example_dir, callback)
}; })
})
}
Client.runServer(4242, fixturePath("examples")); Client.runServer(4242, fixturePath('examples'))
describe("Example Documents", function() { describe('Example Documents', function() {
before(function(done) { return ChildProcess.exec("rm test/acceptance/fixtures/tmp/*").on("exit", () => ClsiApp.ensureRunning(done)); } before(function(done) {
); return ChildProcess.exec('rm test/acceptance/fixtures/tmp/*').on(
'exit',
() => ClsiApp.ensureRunning(done)
)
})
return Array.from(fs.readdirSync(fixturePath('examples'))).map(example_dir =>
return Array.from(fs.readdirSync(fixturePath("examples"))).map((example_dir) =>
(example_dir => (example_dir =>
describe(example_dir, function() { describe(example_dir, function() {
before(function() { before(function() {
return this.project_id = Client.randomId() + "_" + example_dir; 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));
}
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));
}
const pdf = Client.getOutputFile(body, "pdf");
return downloadAndComparePdf(this.project_id, example_dir, pdf.url, done);
});
});
}) })
)(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))
}
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))
}
const pdf = Client.getOutputFile(body, 'pdf')
return downloadAndComparePdf(
this.project_id,
example_dir,
pdf.url,
done
)
}
)
})
}))(example_dir)
)
})
function __guard__(value, transform) { function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined; return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
} }

View file

@ -8,17 +8,18 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const Client = require("./helpers/Client"); const Client = require('./helpers/Client')
const request = require("request"); const request = require('request')
require("chai").should(); require('chai').should()
const ClsiApp = require("./helpers/ClsiApp"); const ClsiApp = require('./helpers/ClsiApp')
describe("Simple LaTeX file", function() { describe('Simple LaTeX file', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
@ -27,36 +28,44 @@ Hello world
` `
} }
] ]
}; }
return ClsiApp.ensureRunning(() => { return ClsiApp.ensureRunning(() => {
return Client.compile(this.project_id, this.request, (error, res, body) => { this.error = error; this.res = res; this.body = body; return done(); }); return Client.compile(
}); this.project_id,
}); this.request,
(error, res, body) => {
this.error = error
this.res = res
this.body = body
return done()
}
)
})
})
it("should return the PDF", function() { it('should return the PDF', function() {
const pdf = Client.getOutputFile(this.body, "pdf"); const pdf = Client.getOutputFile(this.body, 'pdf')
return pdf.type.should.equal("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"); const log = Client.getOutputFile(this.body, 'log')
return log.type.should.equal("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"); const pdf = Client.getOutputFile(this.body, 'pdf')
return request.get(pdf.url, (error, res, body) => { return request.get(pdf.url, (error, res, body) => {
res.statusCode.should.equal(200); res.statusCode.should.equal(200)
return done(); return done()
}); })
}); })
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"); const log = Client.getOutputFile(this.body, 'pdf')
return request.get(log.url, (error, res, body) => { return request.get(log.url, (error, res, body) => {
res.statusCode.should.equal(200); res.statusCode.should.equal(200)
return done(); return done()
}); })
}); })
}); })

View file

@ -9,53 +9,83 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const Client = require("./helpers/Client"); const Client = require('./helpers/Client')
const request = require("request"); const request = require('request')
require("chai").should(); require('chai').should()
const { expect } = require("chai"); const { expect } = require('chai')
const ClsiApp = require("./helpers/ClsiApp"); const ClsiApp = require('./helpers/ClsiApp')
const crypto = require("crypto"); const crypto = require('crypto')
describe("Syncing", function() { describe('Syncing', function() {
before(function(done) { before(function(done) {
const content = `\ const content = `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
Hello world Hello world
\\end{document}\ \\end{document}\
`; `
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content content
} }
] ]
}; }
this.project_id = Client.randomId(); this.project_id = Client.randomId()
return ClsiApp.ensureRunning(() => { return ClsiApp.ensureRunning(() => {
return Client.compile(this.project_id, this.request, (error, res, body) => { this.error = error; this.res = res; this.body = body; return done(); }); return Client.compile(
}); this.project_id,
}); this.request,
(error, res, body) => {
this.error = error
this.res = res
this.body = body
return done()
}
)
})
})
describe("from code to pdf", function() { return it("should return the correct location", function(done) { describe('from code to pdf', function() {
return Client.syncFromCode(this.project_id, "main.tex", 3, 5, (error, pdfPositions) => { return it('should return the correct location', function(done) {
if (error != null) { throw error; } return Client.syncFromCode(
this.project_id,
'main.tex',
3,
5,
(error, pdfPositions) => {
if (error != null) {
throw 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 }
return done(); ]
}); })
}); } return done()
); }
)
})
})
return describe("from pdf to code", function() { return it("should return the correct location", function(done) { return describe('from pdf to code', function() {
return Client.syncFromPdf(this.project_id, 1, 100, 200, (error, codePositions) => { return it('should return the correct location', function(done) {
if (error != null) { throw error; } return Client.syncFromPdf(
this.project_id,
1,
100,
200,
(error, codePositions) => {
if (error != null) {
throw 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 }]
}); })
return done(); return done()
}); }
}); } )
); })
}); })
})

View file

@ -8,20 +8,20 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const Client = require("./helpers/Client"); const Client = require('./helpers/Client')
const request = require("request"); const request = require('request')
require("chai").should(); require('chai').should()
const ClsiApp = require("./helpers/ClsiApp"); const ClsiApp = require('./helpers/ClsiApp')
describe('Timed out compile', function() {
describe("Timed out compile", function() {
before(function(done) { before(function(done) {
this.request = { this.request = {
options: { options: {
timeout: 10 timeout: 10
}, // seconds }, // seconds
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
@ -31,23 +31,32 @@ describe("Timed out compile", function() {
` `
} }
] ]
}; }
this.project_id = Client.randomId(); this.project_id = Client.randomId()
return ClsiApp.ensureRunning(() => { return ClsiApp.ensureRunning(() => {
return Client.compile(this.project_id, this.request, (error, res, body) => { this.error = error; this.res = res; this.body = body; return done(); }); return Client.compile(
}); this.project_id,
}); this.request,
(error, res, body) => {
this.error = error
this.res = res
this.body = body
return done()
}
)
})
})
it("should return a timeout error", function() { it('should return a timeout error', function() {
return this.body.compile.error.should.equal("container timed out"); 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 this.body.compile.status.should.equal('timedout')
}); })
return it("should return the log output file name", function() { return it('should return the log output file name', function() {
const outputFilePaths = this.body.compile.outputFiles.map(x => x.path); const outputFilePaths = this.body.compile.outputFiles.map(x => x.path)
return outputFilePaths.should.include('output.log'); return outputFilePaths.should.include('output.log')
}); })
}); })

View file

@ -10,46 +10,49 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const Client = require("./helpers/Client"); const Client = require('./helpers/Client')
const request = require("request"); const request = require('request')
require("chai").should(); require('chai').should()
const sinon = require("sinon"); const sinon = require('sinon')
const ClsiApp = require("./helpers/ClsiApp"); const ClsiApp = require('./helpers/ClsiApp')
const host = "localhost"; const host = 'localhost'
const Server = { const Server = {
run() { run() {
const express = require("express"); const express = require('express')
const app = express(); const app = express()
const staticServer = express.static(__dirname + "/../fixtures/"); const staticServer = express.static(__dirname + '/../fixtures/')
app.get("/:random_id/*", (req, res, next) => { app.get('/:random_id/*', (req, res, next) => {
this.getFile(req.url); this.getFile(req.url)
req.url = `/${req.params[0]}`; req.url = `/${req.params[0]}`
return staticServer(req, res, next); return staticServer(req, res, next)
}); })
return app.listen(31415, host); return app.listen(31415, host)
}, },
getFile() {}, getFile() {},
randomId() { randomId() {
return Math.random().toString(16).slice(2); return Math.random()
.toString(16)
.slice(2)
}
} }
};
Server.run(); Server.run()
describe("Url Caching", function() { describe('Url Caching', function() {
describe("Downloading an image for the first time", function() { describe('Downloading an image for the first time', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`; this.file = `${Server.randomId()}/lion.png`
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
@ -57,34 +60,46 @@ describe("Url Caching", function() {
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, { },
path: "lion.png", {
path: 'lion.png',
url: `http://${host}:31415/${this.file}` url: `http://${host}:31415/${this.file}`
}] }
}; ]
}
sinon.spy(Server, "getFile"); sinon.spy(Server, 'getFile')
return ClsiApp.ensureRunning(() => { return ClsiApp.ensureRunning(() => {
return Client.compile(this.project_id, this.request, (error, res, body) => { this.error = error; this.res = res; this.body = body; return done(); }); return Client.compile(
}); this.project_id,
}); this.request,
(error, res, body) => {
this.error = error
this.res = res
this.body = body
return done()
}
)
})
})
afterEach(function() { return Server.getFile.restore(); }); afterEach(function() {
return Server.getFile.restore()
})
return it("should download the image", function() { return it('should download the image', function() {
return Server.getFile return Server.getFile.calledWith(`/${this.file}`).should.equal(true)
.calledWith(`/${this.file}`) })
.should.equal(true); })
});
});
describe("When an image is in the cache and the last modified date is unchanged", function() { describe('When an image is in the cache and the last modified date is unchanged', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`; this.file = `${Server.randomId()}/lion.png`
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
@ -92,39 +107,54 @@ describe("Url Caching", function() {
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
path: 'lion.png',
url: `http://${host}:31415/${this.file}`, url: `http://${host}:31415/${this.file}`,
modified: Date.now() modified: Date.now()
})] })
}; ]
}
return Client.compile(this.project_id, this.request, (error, res, body) => { return Client.compile(
this.error = error; this.project_id,
this.res = res; this.request,
this.body = body; (error, res, body) => {
sinon.spy(Server, "getFile"); this.error = error
return Client.compile(this.project_id, this.request, (error1, res1, body1) => { this.res = res
this.error = error1; this.body = body
this.res = res1; sinon.spy(Server, 'getFile')
this.body = body1; return Client.compile(
return done(); this.project_id,
}); this.request,
}); (error1, res1, body1) => {
}); this.error = error1
this.res = res1
this.body = body1
return done()
}
)
}
)
})
after(function() { return Server.getFile.restore(); }); after(function() {
return Server.getFile.restore()
})
return it("should not download the image again", function() { return Server.getFile.called.should.equal(false); }); 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() { describe('When an image is in the cache and the last modified date is advanced', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`; this.file = `${Server.randomId()}/lion.png`
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
@ -132,40 +162,55 @@ describe("Url Caching", function() {
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
path: 'lion.png',
url: `http://${host}:31415/${this.file}`, url: `http://${host}:31415/${this.file}`,
modified: (this.last_modified = Date.now()) modified: (this.last_modified = Date.now())
})] })
}; ]
}
return Client.compile(this.project_id, this.request, (error, res, body) => { return Client.compile(
this.error = error; this.project_id,
this.res = res; this.request,
this.body = body; (error, res, body) => {
sinon.spy(Server, "getFile"); this.error = error
this.image_resource.modified = new Date(this.last_modified + 3000); this.res = res
return Client.compile(this.project_id, this.request, (error1, res1, body1) => { this.body = body
this.error = error1; sinon.spy(Server, 'getFile')
this.res = res1; this.image_resource.modified = new Date(this.last_modified + 3000)
this.body = body1; return Client.compile(
return done(); this.project_id,
}); this.request,
}); (error1, res1, body1) => {
}); this.error = error1
this.res = res1
this.body = body1
return done()
}
)
}
)
})
afterEach(function() { return Server.getFile.restore(); }); afterEach(function() {
return Server.getFile.restore()
})
return it("should download the image again", function() { return Server.getFile.called.should.equal(true); }); 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() { describe('When an image is in the cache and the last modified date is further in the past', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`; this.file = `${Server.randomId()}/lion.png`
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
@ -173,40 +218,55 @@ describe("Url Caching", function() {
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
path: 'lion.png',
url: `http://${host}:31415/${this.file}`, url: `http://${host}:31415/${this.file}`,
modified: (this.last_modified = Date.now()) modified: (this.last_modified = Date.now())
})] })
}; ]
}
return Client.compile(this.project_id, this.request, (error, res, body) => { return Client.compile(
this.error = error; this.project_id,
this.res = res; this.request,
this.body = body; (error, res, body) => {
sinon.spy(Server, "getFile"); this.error = error
this.image_resource.modified = new Date(this.last_modified - 3000); this.res = res
return Client.compile(this.project_id, this.request, (error1, res1, body1) => { this.body = body
this.error = error1; sinon.spy(Server, 'getFile')
this.res = res1; this.image_resource.modified = new Date(this.last_modified - 3000)
this.body = body1; return Client.compile(
return done(); this.project_id,
}); this.request,
}); (error1, res1, body1) => {
}); this.error = error1
this.res = res1
this.body = body1
return done()
}
)
}
)
})
afterEach(function() { return Server.getFile.restore(); }); afterEach(function() {
return Server.getFile.restore()
})
return it("should not download the image again", function() { return Server.getFile.called.should.equal(false); }); 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() { describe('When an image is in the cache and the last modified date is not specified', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`; this.file = `${Server.randomId()}/lion.png`
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
@ -214,40 +274,55 @@ describe("Url Caching", function() {
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
path: 'lion.png',
url: `http://${host}:31415/${this.file}`, url: `http://${host}:31415/${this.file}`,
modified: (this.last_modified = Date.now()) modified: (this.last_modified = Date.now())
})] })
}; ]
}
return Client.compile(this.project_id, this.request, (error, res, body) => { return Client.compile(
this.error = error; this.project_id,
this.res = res; this.request,
this.body = body; (error, res, body) => {
sinon.spy(Server, "getFile"); this.error = error
delete this.image_resource.modified; this.res = res
return Client.compile(this.project_id, this.request, (error1, res1, body1) => { this.body = body
this.error = error1; sinon.spy(Server, 'getFile')
this.res = res1; delete this.image_resource.modified
this.body = body1; return Client.compile(
return done(); this.project_id,
}); this.request,
}); (error1, res1, body1) => {
}); this.error = error1
this.res = res1
this.body = body1
return done()
}
)
}
)
})
afterEach(function() { return Server.getFile.restore(); }); afterEach(function() {
return Server.getFile.restore()
})
return it("should download the image again", function() { return Server.getFile.called.should.equal(true); }); return it('should download the image again', function() {
}); return Server.getFile.called.should.equal(true)
})
})
return describe("After clearing the cache", function() { return describe('After clearing the cache', function() {
before(function(done) { before(function(done) {
this.project_id = Client.randomId(); this.project_id = Client.randomId()
this.file = `${Server.randomId()}/lion.png`; this.file = `${Server.randomId()}/lion.png`
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
path: 'main.tex',
content: `\ content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
@ -255,32 +330,44 @@ describe("Url Caching", function() {
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
path: 'lion.png',
url: `http://${host}:31415/${this.file}`, url: `http://${host}:31415/${this.file}`,
modified: (this.last_modified = Date.now()) modified: (this.last_modified = Date.now())
})] })
}; ]
}
return Client.compile(this.project_id, this.request, error => { return Client.compile(this.project_id, this.request, error => {
if (error != null) { throw error; } if (error != null) {
throw error
}
return Client.clearCache(this.project_id, (error, res, body) => { return Client.clearCache(this.project_id, (error, res, body) => {
if (error != null) { throw error; } if (error != null) {
sinon.spy(Server, "getFile"); throw error
return Client.compile(this.project_id, this.request, (error1, res1, body1) => { }
this.error = error1; sinon.spy(Server, 'getFile')
this.res = res1; return Client.compile(
this.body = body1; this.project_id,
return done(); this.request,
}); (error1, res1, body1) => {
}); this.error = error1
}); this.res = res1
}); this.body = body1
return done()
afterEach(function() { return Server.getFile.restore(); }); }
)
return it("should download the image again", function() { return Server.getFile.called.should.equal(true); }); })
}); })
}); })
afterEach(function() {
return Server.getFile.restore()
})
return it('should download the image again', function() {
return Server.getFile.called.should.equal(true)
})
})
})

View file

@ -9,35 +9,51 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const Client = require("./helpers/Client"); const Client = require('./helpers/Client')
const request = require("request"); const request = require('request')
require("chai").should(); require('chai').should()
const { expect } = require("chai"); const { expect } = require('chai')
const path = require("path"); const path = require('path')
const fs = require("fs"); const fs = require('fs')
const ClsiApp = require("./helpers/ClsiApp"); const ClsiApp = require('./helpers/ClsiApp')
describe("Syncing", function() { describe('Syncing', function() {
before(function(done) { before(function(done) {
this.request = { this.request = {
resources: [{ resources: [
path: "main.tex", {
content: fs.readFileSync(path.join(__dirname,"../fixtures/naugty_strings.txt"),"utf-8") path: 'main.tex',
content: fs.readFileSync(
path.join(__dirname, '../fixtures/naugty_strings.txt'),
'utf-8'
)
} }
] ]
}; }
this.project_id = Client.randomId(); this.project_id = Client.randomId()
return ClsiApp.ensureRunning(() => { return ClsiApp.ensureRunning(() => {
return Client.compile(this.project_id, this.request, (error, res, body) => { this.error = error; this.res = res; this.body = body; return done(); }); return Client.compile(
}); this.project_id,
}); this.request,
(error, res, body) => {
this.error = error
this.res = res
this.body = body
return done()
}
)
})
})
return describe("wordcount file", function() { return it("should return wordcount info", function(done) { return describe('wordcount file', function() {
return Client.wordcount(this.project_id, "main.tex", (error, result) => { return it('should return wordcount info', function(done) {
if (error != null) { throw error; } return Client.wordcount(this.project_id, 'main.tex', (error, result) => {
if (error != null) {
throw 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,
@ -46,11 +62,11 @@ describe("Syncing", function() {
mathInline: 6, mathInline: 6,
mathDisplay: 0, mathDisplay: 0,
errors: 0, errors: 0,
messages: "" messages: ''
} }
}); })
return done(); return done()
}); })
}); } })
); })
}); })

View file

@ -12,143 +12,197 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let Client; let Client
const request = require("request"); const request = require('request')
const fs = require("fs"); const fs = require('fs')
const Settings = require("settings-sharelatex"); const Settings = require('settings-sharelatex')
const host = "localhost"; const host = 'localhost'
module.exports = (Client = { module.exports = Client = {
host: Settings.apis.clsi.url, host: Settings.apis.clsi.url,
randomId() { randomId() {
return Math.random().toString(16).slice(2); return Math.random()
.toString(16)
.slice(2)
}, },
compile(project_id, data, callback) { compile(project_id, data, callback) {
if (callback == null) { callback = function(error, res, body) {}; } if (callback == null) {
return request.post({ callback = function(error, res, body) {}
}
return request.post(
{
url: `${this.host}/project/${project_id}/compile`, url: `${this.host}/project/${project_id}/compile`,
json: { json: {
compile: data compile: data
} }
}, callback); },
callback
)
}, },
clearCache(project_id, callback) { clearCache(project_id, callback) {
if (callback == null) { callback = function(error, res, body) {}; } if (callback == null) {
return request.del(`${this.host}/project/${project_id}`, callback); callback = function(error, res, body) {}
}
return request.del(`${this.host}/project/${project_id}`, callback)
}, },
getOutputFile(response, type) { getOutputFile(response, type) {
for (const file of Array.from(response.compile.outputFiles)) { for (const file of Array.from(response.compile.outputFiles)) {
if ((file.type === type) && file.url.match(`output.${type}`)) { if (file.type === type && file.url.match(`output.${type}`)) {
return file; return file
} }
} }
return null; return null
}, },
runServer(port, directory) { runServer(port, directory) {
const express = require("express"); const express = require('express')
const app = express(); const app = express()
app.use(express.static(directory)); app.use(express.static(directory))
console.log("starting test server on", port, host); 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); console.error('error starting server:', error.message)
return process.exit(1); return process.exit(1)
}); })
}, },
syncFromCode(project_id, file, line, column, callback) { syncFromCode(project_id, file, line, column, callback) {
if (callback == null) { callback = function(error, pdfPositions) {}; } if (callback == null) {
return request.get({ callback = function(error, pdfPositions) {}
}
return request.get(
{
url: `${this.host}/project/${project_id}/sync/code`, url: `${this.host}/project/${project_id}/sync/code`,
qs: { qs: {
file, file,
line, line,
column column
} }
}, (error, response, body) => { },
if (error != null) { return callback(error); } (error, response, body) => {
return callback(null, JSON.parse(body)); if (error != null) {
}); return callback(error)
}
return callback(null, JSON.parse(body))
}
)
}, },
syncFromPdf(project_id, page, h, v, callback) { syncFromPdf(project_id, page, h, v, callback) {
if (callback == null) { callback = function(error, pdfPositions) {}; } if (callback == null) {
return request.get({ callback = function(error, pdfPositions) {}
}
return request.get(
{
url: `${this.host}/project/${project_id}/sync/pdf`, url: `${this.host}/project/${project_id}/sync/pdf`,
qs: { qs: {
page, page,
h, v h,
v
} }
}, (error, response, body) => { },
if (error != null) { return callback(error); } (error, response, body) => {
return callback(null, JSON.parse(body)); if (error != null) {
}); return callback(error)
}
return callback(null, JSON.parse(body))
}
)
}, },
compileDirectory(project_id, baseDirectory, directory, serverPort, callback) { compileDirectory(project_id, baseDirectory, directory, serverPort, callback) {
if (callback == null) { callback = function(error, res, body) {}; } if (callback == null) {
const resources = []; callback = function(error, res, body) {}
let entities = fs.readdirSync(`${baseDirectory}/${directory}`);
let rootResourcePath = "main.tex";
while (entities.length > 0) {
var entity = entities.pop();
const stat = fs.statSync(`${baseDirectory}/${directory}/${entity}`);
if (stat.isDirectory()) {
entities = entities.concat(fs.readdirSync(`${baseDirectory}/${directory}/${entity}`).map((subEntity) => {
if (subEntity === "main.tex") {
rootResourcePath = `${entity}/${subEntity}`;
} }
return `${entity}/${subEntity}`; const resources = []
let entities = fs.readdirSync(`${baseDirectory}/${directory}`)
let rootResourcePath = 'main.tex'
while (entities.length > 0) {
var entity = entities.pop()
const stat = fs.statSync(`${baseDirectory}/${directory}/${entity}`)
if (stat.isDirectory()) {
entities = entities.concat(
fs
.readdirSync(`${baseDirectory}/${directory}/${entity}`)
.map(subEntity => {
if (subEntity === 'main.tex') {
rootResourcePath = `${entity}/${subEntity}`
}
return `${entity}/${subEntity}`
}) })
); )
} else if (stat.isFile() && (entity !== "output.pdf")) { } else if (stat.isFile() && entity !== 'output.pdf') {
const extension = entity.split(".").pop(); const extension = entity.split('.').pop()
if (["tex", "bib", "cls", "sty", "pdf_tex", "Rtex", "ist", "md", "Rmd"].indexOf(extension) > -1) { if (
[
'tex',
'bib',
'cls',
'sty',
'pdf_tex',
'Rtex',
'ist',
'md',
'Rmd'
].indexOf(extension) > -1
) {
resources.push({ resources.push({
path: entity, path: entity,
content: fs.readFileSync(`${baseDirectory}/${directory}/${entity}`).toString() content: fs
}); .readFileSync(`${baseDirectory}/${directory}/${entity}`)
} else if (["eps", "ttf", "png", "jpg", "pdf", "jpeg"].indexOf(extension) > -1) { .toString()
})
} else if (
['eps', 'ttf', 'png', 'jpg', 'pdf', 'jpeg'].indexOf(extension) > -1
) {
resources.push({ resources.push({
path: entity, path: entity,
url: `http://${host}:${serverPort}/${directory}/${entity}`, url: `http://${host}:${serverPort}/${directory}/${entity}`,
modified: stat.mtime modified: stat.mtime
}); })
} }
} }
} }
return fs.readFile(`${baseDirectory}/${directory}/options.json`, (error, body) => { return fs.readFile(
`${baseDirectory}/${directory}/options.json`,
(error, body) => {
const req = { const req = {
resources, resources,
rootResourcePath rootResourcePath
};
if ((error == null)) {
body = JSON.parse(body);
req.options = body;
} }
return this.compile(project_id, req, callback); if (error == null) {
}); body = JSON.parse(body)
req.options = body
}
return this.compile(project_id, req, callback)
}
)
}, },
wordcount(project_id, file, callback) { wordcount(project_id, file, callback) {
if (callback == null) { callback = function(error, pdfPositions) {}; } if (callback == null) {
return request.get({ callback = function(error, pdfPositions) {}
}
return request.get(
{
url: `${this.host}/project/${project_id}/wordcount`, url: `${this.host}/project/${project_id}/wordcount`,
qs: { qs: {
file file
} }
}, (error, response, body) => { },
if (error != null) { return callback(error); } (error, response, body) => {
return callback(null, JSON.parse(body)); if (error != null) {
}); return callback(error)
}
return callback(null, JSON.parse(body))
}
)
}
} }
});

View file

@ -12,40 +12,53 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const app = require('../../../../app'); const app = require('../../../../app')
require("logger-sharelatex").logger.level("info"); require('logger-sharelatex').logger.level('info')
const logger = require("logger-sharelatex"); const logger = require('logger-sharelatex')
const Settings = require("settings-sharelatex"); const Settings = require('settings-sharelatex')
module.exports = { module.exports = {
running: false, running: false,
initing: false, initing: false,
callbacks: [], callbacks: [],
ensureRunning(callback) { ensureRunning(callback) {
if (callback == null) { callback = function(error) {}; } if (callback == null) {
callback = function(error) {}
}
if (this.running) { if (this.running) {
return callback(); return callback()
} else if (this.initing) { } else if (this.initing) {
return this.callbacks.push(callback); return this.callbacks.push(callback)
} else { } else {
this.initing = true; this.initing = true
this.callbacks.push(callback); this.callbacks.push(callback)
return app.listen(__guard__(Settings.internal != null ? Settings.internal.clsi : undefined, x => x.port), "localhost", error => { return app.listen(
if (error != null) { throw error; } __guard__(
this.running = true; Settings.internal != null ? Settings.internal.clsi : undefined,
logger.log("clsi running in dev mode"); x => x.port
),
'localhost',
error => {
if (error != null) {
throw error
}
this.running = true
logger.log('clsi running in dev mode')
return (() => { return (() => {
const result = []; const result = []
for (callback of Array.from(this.callbacks)) { for (callback of Array.from(this.callbacks)) {
result.push(callback()); result.push(callback())
}
return result
})()
}
)
} }
return result;
})();
});
} }
} }
};
function __guard__(value, transform) { function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined; return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
} }