prettier: convert test/acceptance decaffeinated files to Prettier format

This commit is contained in:
mserranom
2020-02-19 12:16:14 +01:00
parent 7996f44942
commit 71a50dd11f
10 changed files with 1105 additions and 771 deletions

View File

@@ -8,68 +8,81 @@
* 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", {
content: `\ path: 'main.tex',
content: `\
\\documentclass{articl % :( \\documentclass{articl % :(
\\begin{documen % :( \\begin{documen % :(
Broken Broken
\\end{documen % :(\ \\end{documen % :(\
` `
} }
] ]
}; }
this.correct_request = { this.correct_request = {
resources: [{ resources: [
path: "main.tex", {
content: `\ path: 'main.tex',
content: `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
Hello world Hello world
\\end{document}\ \\end{document}\
` `
} }
] ]
}; }
return ClsiApp.ensureRunning(done); return ClsiApp.ensureRunning(done)
}); })
describe("on first run", function() {
before(function(done) {
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 it("should return a failure status", function() { describe('on first run', function() {
return this.body.compile.status.should.equal("failure"); before(function(done) {
}); 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 describe("on second run", function() { return it('should return a failure status', function() {
before(function(done) { return this.body.compile.status.should.equal('failure')
this.project_id = Client.randomId(); })
return Client.compile(this.project_id, this.correct_request, () => { })
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 describe('on second run', function() {
return this.body.compile.status.should.equal("failure"); before(function(done) {
}); this.project_id = Client.randomId()
}); return Client.compile(this.project_id, this.correct_request, () => {
}); 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 this.body.compile.status.should.equal('failure')
})
})
})

View File

@@ -8,53 +8,66 @@
* 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", {
content: `\ path: 'main.tex',
content: `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
Hello world Hello world
\\end{document}\ \\end{document}\
` `
} }
] ]
}; }
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
// remove output diff if test matches expected image )} ${diff_file}`
fs.unlink(diff_file, (err) => { )
if (err) { let stderr = ''
throw err; proc.stderr.on('data', chunk => (stderr += chunk))
} return proc.on('exit', () => {
}); if (stderr.trim() === '0 (0)') {
return callback(null, true); // remove output diff if test matches expected image
} else { fs.unlink(diff_file, err => {
console.log("compare result", stderr); if (err) {
return callback(null, false); throw err
} }
}); })
}; return callback(null, true)
} else {
console.log('compare result', stderr)
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) {
var compareNext = function(page_no, callback) { callback = function(error) {}
const path = `tmp/${project_id}-source-${page_no}.png`; }
return fs.stat(fixturePath(path), (error, stat) => { var compareNext = function(page_no, callback) {
if (error != null) { const path = `tmp/${project_id}-source-${page_no}.png`
return callback(); return fs.stat(fixturePath(path), (error, stat) => {
} else { if (error != null) {
return compare(`tmp/${project_id}-source-${page_no}.png`, `tmp/${project_id}-generated-${page_no}.png`, (error, same) => { return callback()
if (error != null) { throw error; } } else {
same.should.equal(true); return compare(
return compareNext(page_no + 1, callback); `tmp/${project_id}-source-${page_no}.png`,
}); `tmp/${project_id}-generated-${page_no}.png`,
} (error, same) => {
}); if (error != null) {
}; throw error
return compareNext(0, callback); }
}; same.should.equal(true)
return compareNext(page_no + 1, 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)
return checkPdfInfo(`tmp/${project_id}.pdf`, (error, optimised) => { console.log('writing file out', fixturePath(`tmp/${project_id}.pdf`))
if (error != null) { throw error; } return writeStream.on('close', () => {
optimised.should.equal(true); return checkPdfInfo(`tmp/${project_id}.pdf`, (error, optimised) => {
return comparePdf(project_id, example_dir, callback); if (error != null) {
}); throw error
}); }
}; 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 =>
(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) => it('should generate the correct pdf', function(done) {
(example_dir => this.timeout(MOCHA_LATEX_TIMEOUT)
describe(example_dir, function() { return Client.compileDirectory(
before(function() { this.project_id,
return this.project_id = Client.randomId() + "_" + example_dir; fixturePath('examples'),
}); example_dir,
4242,
it("should generate the correct pdf", function(done) { (error, res, body) => {
this.timeout(MOCHA_LATEX_TIMEOUT); if (
return Client.compileDirectory(this.project_id, fixturePath("examples"), example_dir, 4242, (error, res, body) => { error ||
if (error || (__guard__(body != null ? body.compile : undefined, x => x.status) === "failure")) { __guard__(
console.log("DEBUG: error", error, "body", JSON.stringify(body)); body != null ? body.compile : undefined,
} x => x.status
const pdf = Client.getOutputFile(body, "pdf"); ) === 'failure'
return downloadAndComparePdf(this.project_id, example_dir, pdf.url, done); ) {
}); console.log('DEBUG: error', error, 'body', JSON.stringify(body))
}); }
const pdf = Client.getOutputFile(body, 'pdf')
return it("should generate the correct pdf on the second run as well", function(done) { return downloadAndComparePdf(
this.timeout(MOCHA_LATEX_TIMEOUT); this.project_id,
return Client.compileDirectory(this.project_id, fixturePath("examples"), example_dir, 4242, (error, res, body) => { example_dir,
if (error || (__guard__(body != null ? body.compile : undefined, x => x.status) === "failure")) { pdf.url,
console.log("DEBUG: error", error, "body", JSON.stringify(body)); done
} )
const pdf = Client.getOutputFile(body, "pdf"); }
return downloadAndComparePdf(this.project_id, example_dir, pdf.url, done); )
}); })
});
})
)(example_dir));
});
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,55 +8,64 @@
* 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", {
content: `\ path: 'main.tex',
content: `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
Hello world Hello world
\\end{document}\ \\end{document}\
` `
} }
] ]
}; }
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() {
const log = Client.getOutputFile(this.body, "log");
return log.type.should.equal("log");
});
it("should provide the pdf for download", function(done) { it('should return the log', function() {
const pdf = Client.getOutputFile(this.body, "pdf"); const log = Client.getOutputFile(this.body, 'log')
return request.get(pdf.url, (error, res, body) => { return log.type.should.equal('log')
res.statusCode.should.equal(200); })
return 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) => {
return it("should provide the log for download", function(done) { res.statusCode.should.equal(200)
const log = Client.getOutputFile(this.body, "pdf"); return done()
return request.get(log.url, (error, res, body) => { })
res.statusCode.should.equal(200); })
return 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)
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", {
content path: 'main.tex',
} content
] }
}; ]
this.project_id = Client.randomId(); }
return ClsiApp.ensureRunning(() => { 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 ClsiApp.ensureRunning(() => {
}); 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(
expect(pdfPositions).to.deep.equal({ this.project_id,
pdf: [ { page: 1, h: 133.77, v: 134.76, height: 6.92, width: 343.71 } ] 'main.tex',
}); 3,
return done(); 5,
}); (error, pdfPositions) => {
}); } if (error != null) {
); throw error
}
expect(pdfPositions).to.deep.equal({
pdf: [
{ page: 1, h: 133.77, v: 134.76, height: 6.92, width: 343.71 }
]
})
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(
expect(codePositions).to.deep.equal({ this.project_id,
code: [ { file: 'main.tex', line: 3, column: -1 } ] 1,
}); 100,
return done(); 200,
}); (error, codePositions) => {
}); } if (error != null) {
); throw error
}); }
expect(codePositions).to.deep.equal({
code: [{ file: 'main.tex', line: 3, column: -1 }]
})
return done()
}
)
})
})
})

View File

@@ -8,46 +8,55 @@
* 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}
\\def\\x{Hello!\\par\\x} \\def\\x{Hello!\\par\\x}
\\x \\x
\\end{document}\ \\end{document}\
` `
} }
] ]
}; }
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,277 +10,364 @@
* 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", {
content: `\ path: 'main.tex',
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", {
url: `http://${host}:31415/${this.file}` path: 'lion.png',
}] 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() {
before(function(done) {
describe("When an image is in the cache and the last modified date is unchanged", function() { this.project_id = Client.randomId()
before(function(done) { this.file = `${Server.randomId()}/lion.png`
this.project_id = Client.randomId(); this.request = {
this.file = `${Server.randomId()}/lion.png`; resources: [
this.request = { {
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}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
url: `http://${host}:31415/${this.file}`, path: 'lion.png',
modified: Date.now() url: `http://${host}:31415/${this.file}`,
})] 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", {
content: `\ path: 'main.tex',
content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
\\begin{document} \\begin{document}
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
url: `http://${host}:31415/${this.file}`, path: 'lion.png',
modified: (this.last_modified = Date.now()) url: `http://${host}:31415/${this.file}`,
})] 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", {
content: `\ path: 'main.tex',
content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
\\begin{document} \\begin{document}
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
url: `http://${host}:31415/${this.file}`, path: 'lion.png',
modified: (this.last_modified = Date.now()) url: `http://${host}:31415/${this.file}`,
})] 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", {
content: `\ path: 'main.tex',
content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
\\begin{document} \\begin{document}
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
url: `http://${host}:31415/${this.file}`, path: 'lion.png',
modified: (this.last_modified = Date.now()) url: `http://${host}:31415/${this.file}`,
})] 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() { })
before(function(done) {
this.project_id = Client.randomId(); return describe('After clearing the cache', function() {
this.file = `${Server.randomId()}/lion.png`; before(function(done) {
this.request = { this.project_id = Client.randomId()
resources: [{ this.file = `${Server.randomId()}/lion.png`
path: "main.tex", this.request = {
content: `\ resources: [
{
path: 'main.tex',
content: `\
\\documentclass{article} \\documentclass{article}
\\usepackage{graphicx} \\usepackage{graphicx}
\\begin{document} \\begin{document}
\\includegraphics{lion.png} \\includegraphics{lion.png}
\\end{document}\ \\end{document}\
` `
}, (this.image_resource = { },
path: "lion.png", (this.image_resource = {
url: `http://${host}:31415/${this.file}`, path: 'lion.png',
modified: (this.last_modified = Date.now()) url: `http://${host}:31415/${this.file}`,
})] 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) {
return Client.clearCache(this.project_id, (error, res, body) => { throw error
if (error != null) { throw error; } }
sinon.spy(Server, "getFile"); return Client.clearCache(this.project_id, (error, res, body) => {
return Client.compile(this.project_id, this.request, (error1, res1, body1) => { if (error != null) {
this.error = error1; throw error
this.res = res1; }
this.body = body1; sinon.spy(Server, 'getFile')
return done(); return Client.compile(
}); 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)
}); })
})
})

View File

@@ -9,48 +9,64 @@
* 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(); )
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(); }); ]
}); }
}); this.project_id = Client.randomId()
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 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) => {
expect(result).to.deep.equal({ if (error != null) {
texcount: { throw error
encode: "utf8", }
textWords: 2281, expect(result).to.deep.equal({
headWords: 2, texcount: {
outside: 0, encode: 'utf8',
headers: 2, textWords: 2281,
elements: 0, headWords: 2,
mathInline: 6, outside: 0,
mathDisplay: 0, headers: 2,
errors: 0, elements: 0,
messages: "" mathInline: 6,
} mathDisplay: 0,
}); errors: 0,
return done(); messages: ''
}); }
}); } })
); 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) {}
url: `${this.host}/project/${project_id}/compile`, }
json: { return request.post(
compile: data {
} url: `${this.host}/project/${project_id}/compile`,
}, callback); json: {
}, compile: data
}
},
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) {
if (callback == null) {
callback = function(error, pdfPositions) {}
}
return request.get(
{
url: `${this.host}/project/${project_id}/sync/code`,
qs: {
file,
line,
column
}
},
(error, response, body) => {
if (error != null) {
return callback(error)
}
return callback(null, JSON.parse(body))
}
)
},
syncFromCode(project_id, file, line, column, 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) {}
url: `${this.host}/project/${project_id}/sync/code`, }
qs: { return request.get(
file, {
line, url: `${this.host}/project/${project_id}/sync/pdf`,
column qs: {
} page,
}, (error, response, body) => { h,
if (error != null) { return callback(error); } v
return callback(null, JSON.parse(body)); }
}); },
}, (error, response, body) => {
if (error != null) {
return callback(error)
}
return callback(null, JSON.parse(body))
}
)
},
syncFromPdf(project_id, page, h, v, callback) { compileDirectory(project_id, baseDirectory, directory, serverPort, callback) {
if (callback == null) { callback = function(error, pdfPositions) {}; } if (callback == null) {
return request.get({ callback = function(error, res, body) {}
url: `${this.host}/project/${project_id}/sync/pdf`, }
qs: { const resources = []
page, let entities = fs.readdirSync(`${baseDirectory}/${directory}`)
h, v let rootResourcePath = 'main.tex'
} while (entities.length > 0) {
}, (error, response, body) => { var entity = entities.pop()
if (error != null) { return callback(error); } const stat = fs.statSync(`${baseDirectory}/${directory}/${entity}`)
return callback(null, JSON.parse(body)); 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') {
const extension = entity.split('.').pop()
if (
[
'tex',
'bib',
'cls',
'sty',
'pdf_tex',
'Rtex',
'ist',
'md',
'Rmd'
].indexOf(extension) > -1
) {
resources.push({
path: entity,
content: fs
.readFileSync(`${baseDirectory}/${directory}/${entity}`)
.toString()
})
} else if (
['eps', 'ttf', 'png', 'jpg', 'pdf', 'jpeg'].indexOf(extension) > -1
) {
resources.push({
path: entity,
url: `http://${host}:${serverPort}/${directory}/${entity}`,
modified: stat.mtime
})
}
}
}
compileDirectory(project_id, baseDirectory, directory, serverPort, callback) { return fs.readFile(
if (callback == null) { callback = function(error, res, body) {}; } `${baseDirectory}/${directory}/options.json`,
const resources = []; (error, body) => {
let entities = fs.readdirSync(`${baseDirectory}/${directory}`); const req = {
let rootResourcePath = "main.tex"; resources,
while (entities.length > 0) { rootResourcePath
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")) {
const extension = entity.split(".").pop();
if (["tex", "bib", "cls", "sty", "pdf_tex", "Rtex", "ist", "md", "Rmd"].indexOf(extension) > -1) {
resources.push({
path: entity,
content: fs.readFileSync(`${baseDirectory}/${directory}/${entity}`).toString()
});
} else if (["eps", "ttf", "png", "jpg", "pdf", "jpeg"].indexOf(extension) > -1) {
resources.push({
path: entity,
url: `http://${host}:${serverPort}/${directory}/${entity}`,
modified: stat.mtime
});
}
}
}
return fs.readFile(`${baseDirectory}/${directory}/options.json`, (error, body) => { if (error == null) {
const req = { body = JSON.parse(body)
resources, req.options = body
rootResourcePath }
};
if ((error == null)) { return this.compile(project_id, req, callback)
body = JSON.parse(body); }
req.options = body; )
} },
return this.compile(project_id, req, callback); wordcount(project_id, file, callback) {
}); if (callback == null) {
}, callback = function(error, pdfPositions) {}
}
wordcount(project_id, file, callback) { return request.get(
if (callback == null) { 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) => { (error, response, body) => {
if (error != null) { return callback(error); } if (error != null) {
return callback(null, JSON.parse(body)); 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) {
if (this.running) { callback = function(error) {}
return callback(); }
} else if (this.initing) { if (this.running) {
return this.callbacks.push(callback); return callback()
} else { } else if (this.initing) {
this.initing = true; return this.callbacks.push(callback)
this.callbacks.push(callback); } else {
return app.listen(__guard__(Settings.internal != null ? Settings.internal.clsi : undefined, x => x.port), "localhost", error => { this.initing = true
if (error != null) { throw error; } this.callbacks.push(callback)
this.running = true; return app.listen(
logger.log("clsi running in dev mode"); __guard__(
Settings.internal != null ? Settings.internal.clsi : undefined,
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
}