LatexRunnerTests.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* eslint-disable
  2. no-return-assign,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const SandboxedModule = require('sandboxed-module')
  13. const sinon = require('sinon')
  14. require('chai').should()
  15. const modulePath = require('path').join(
  16. __dirname,
  17. '../../../app/js/LatexRunner'
  18. )
  19. const Path = require('path')
  20. describe('LatexRunner', function() {
  21. beforeEach(function() {
  22. let Timer
  23. this.LatexRunner = SandboxedModule.require(modulePath, {
  24. requires: {
  25. 'settings-sharelatex': (this.Settings = {
  26. docker: {
  27. socketPath: '/var/run/docker.sock'
  28. }
  29. }),
  30. 'logger-sharelatex': (this.logger = {
  31. log: sinon.stub(),
  32. error: sinon.stub()
  33. }),
  34. './Metrics': {
  35. Timer: (Timer = class Timer {
  36. done() {}
  37. })
  38. },
  39. './CommandRunner': (this.CommandRunner = {}),
  40. fs: (this.fs = {
  41. writeFile: sinon.stub().callsArg(2)
  42. })
  43. }
  44. })
  45. this.directory = '/local/compile/directory'
  46. this.mainFile = 'main-file.tex'
  47. this.compiler = 'pdflatex'
  48. this.image = 'example.com/image'
  49. this.compileGroup = 'compile-group'
  50. this.callback = sinon.stub()
  51. this.project_id = 'project-id-123'
  52. return (this.env = { foo: '123' })
  53. })
  54. return describe('runLatex', function() {
  55. beforeEach(function() {
  56. return (this.CommandRunner.run = sinon.stub().callsArgWith(7, null, {
  57. stdout: 'this is stdout',
  58. stderr: 'this is stderr'
  59. }))
  60. })
  61. describe('normally', function() {
  62. beforeEach(function() {
  63. return this.LatexRunner.runLatex(
  64. this.project_id,
  65. {
  66. directory: this.directory,
  67. mainFile: this.mainFile,
  68. compiler: this.compiler,
  69. timeout: (this.timeout = 42000),
  70. image: this.image,
  71. environment: this.env,
  72. compileGroup: this.compileGroup
  73. },
  74. this.callback
  75. )
  76. })
  77. it('should run the latex command', function() {
  78. return this.CommandRunner.run
  79. .calledWith(
  80. this.project_id,
  81. sinon.match.any,
  82. this.directory,
  83. this.image,
  84. this.timeout,
  85. this.env,
  86. this.compileGroup
  87. )
  88. .should.equal(true)
  89. })
  90. it('should record the stdout and stderr', function() {
  91. this.fs.writeFile
  92. .calledWith(this.directory + '/' + 'output.stdout', 'this is stdout')
  93. .should.equal(true)
  94. this.fs.writeFile
  95. .calledWith(this.directory + '/' + 'output.stderr', 'this is stderr')
  96. .should.equal(true)
  97. })
  98. })
  99. describe('with an .Rtex main file', function() {
  100. beforeEach(function() {
  101. return this.LatexRunner.runLatex(
  102. this.project_id,
  103. {
  104. directory: this.directory,
  105. mainFile: 'main-file.Rtex',
  106. compiler: this.compiler,
  107. image: this.image,
  108. timeout: (this.timeout = 42000)
  109. },
  110. this.callback
  111. )
  112. })
  113. return it('should run the latex command on the equivalent .tex file', function() {
  114. const command = this.CommandRunner.run.args[0][1]
  115. const mainFile = command.slice(-1)[0]
  116. return mainFile.should.equal('$COMPILE_DIR/main-file.tex')
  117. })
  118. })
  119. return describe('with a flags option', function() {
  120. beforeEach(function() {
  121. return this.LatexRunner.runLatex(
  122. this.project_id,
  123. {
  124. directory: this.directory,
  125. mainFile: this.mainFile,
  126. compiler: this.compiler,
  127. image: this.image,
  128. timeout: (this.timeout = 42000),
  129. flags: ['-file-line-error', '-halt-on-error']
  130. },
  131. this.callback
  132. )
  133. })
  134. return it('should include the flags in the command', function() {
  135. const command = this.CommandRunner.run.args[0][1]
  136. const flags = command.filter(
  137. arg => arg === '-file-line-error' || arg === '-halt-on-error'
  138. )
  139. flags.length.should.equal(2)
  140. flags[0].should.equal('-file-line-error')
  141. return flags[1].should.equal('-halt-on-error')
  142. })
  143. })
  144. })
  145. })