LatexRunnerTests.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. const modulePath = require('path').join(
  15. __dirname,
  16. '../../../app/js/LatexRunner'
  17. )
  18. const Path = require('path')
  19. describe('LatexRunner', function () {
  20. beforeEach(function () {
  21. let Timer
  22. this.LatexRunner = SandboxedModule.require(modulePath, {
  23. requires: {
  24. 'settings-sharelatex': (this.Settings = {
  25. docker: {
  26. socketPath: '/var/run/docker.sock'
  27. }
  28. }),
  29. './Metrics': {
  30. Timer: (Timer = class Timer {
  31. done() {}
  32. })
  33. },
  34. './CommandRunner': (this.CommandRunner = {}),
  35. fs: (this.fs = {
  36. writeFile: sinon.stub().callsArg(2)
  37. })
  38. }
  39. })
  40. this.directory = '/local/compile/directory'
  41. this.mainFile = 'main-file.tex'
  42. this.compiler = 'pdflatex'
  43. this.image = 'example.com/image'
  44. this.compileGroup = 'compile-group'
  45. this.callback = sinon.stub()
  46. this.project_id = 'project-id-123'
  47. return (this.env = { foo: '123' })
  48. })
  49. return describe('runLatex', function () {
  50. beforeEach(function () {
  51. return (this.CommandRunner.run = sinon.stub().callsArgWith(7, null, {
  52. stdout: 'this is stdout',
  53. stderr: 'this is stderr'
  54. }))
  55. })
  56. describe('normally', function () {
  57. beforeEach(function () {
  58. return this.LatexRunner.runLatex(
  59. this.project_id,
  60. {
  61. directory: this.directory,
  62. mainFile: this.mainFile,
  63. compiler: this.compiler,
  64. timeout: (this.timeout = 42000),
  65. image: this.image,
  66. environment: this.env,
  67. compileGroup: this.compileGroup
  68. },
  69. this.callback
  70. )
  71. })
  72. it('should run the latex command', function () {
  73. return this.CommandRunner.run
  74. .calledWith(
  75. this.project_id,
  76. sinon.match.any,
  77. this.directory,
  78. this.image,
  79. this.timeout,
  80. this.env,
  81. this.compileGroup
  82. )
  83. .should.equal(true)
  84. })
  85. it('should record the stdout and stderr', function () {
  86. this.fs.writeFile
  87. .calledWith(this.directory + '/' + 'output.stdout', 'this is stdout')
  88. .should.equal(true)
  89. this.fs.writeFile
  90. .calledWith(this.directory + '/' + 'output.stderr', 'this is stderr')
  91. .should.equal(true)
  92. })
  93. })
  94. describe('with an .Rtex main file', function () {
  95. beforeEach(function () {
  96. return this.LatexRunner.runLatex(
  97. this.project_id,
  98. {
  99. directory: this.directory,
  100. mainFile: 'main-file.Rtex',
  101. compiler: this.compiler,
  102. image: this.image,
  103. timeout: (this.timeout = 42000)
  104. },
  105. this.callback
  106. )
  107. })
  108. return it('should run the latex command on the equivalent .tex file', function () {
  109. const command = this.CommandRunner.run.args[0][1]
  110. const mainFile = command.slice(-1)[0]
  111. return mainFile.should.equal('$COMPILE_DIR/main-file.tex')
  112. })
  113. })
  114. return describe('with a flags option', function () {
  115. beforeEach(function () {
  116. return this.LatexRunner.runLatex(
  117. this.project_id,
  118. {
  119. directory: this.directory,
  120. mainFile: this.mainFile,
  121. compiler: this.compiler,
  122. image: this.image,
  123. timeout: (this.timeout = 42000),
  124. flags: ['-file-line-error', '-halt-on-error']
  125. },
  126. this.callback
  127. )
  128. })
  129. return it('should include the flags in the command', function () {
  130. const command = this.CommandRunner.run.args[0][1]
  131. const flags = command.filter(
  132. (arg) => arg === '-file-line-error' || arg === '-halt-on-error'
  133. )
  134. flags.length.should.equal(2)
  135. flags[0].should.equal('-file-line-error')
  136. return flags[1].should.equal('-halt-on-error')
  137. })
  138. })
  139. })
  140. })