SimpleLatexFileTests.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const Client = require('./helpers/Client')
  2. const { fetchNothing } = require('@overleaf/fetch-utils')
  3. const ClsiApp = require('./helpers/ClsiApp')
  4. const { expect } = require('chai')
  5. describe('Simple LaTeX file', function () {
  6. const content = `\
  7. \\documentclass{article}
  8. \\begin{document}
  9. Hello world
  10. \\end{document}\
  11. `
  12. const scenarios = [
  13. {
  14. description: 'simple file',
  15. request: {
  16. resources: [{ path: 'main.tex', content }],
  17. },
  18. },
  19. {
  20. description: 'clsi-perf request',
  21. request: {
  22. resources: [{ path: 'main.tex', content }],
  23. options: {
  24. metricsPath: 'clsi-perf',
  25. metricsMethod: 'priority',
  26. },
  27. },
  28. },
  29. ]
  30. for (const scenario of scenarios) {
  31. describe(scenario.description, function () {
  32. before(async function () {
  33. this.project_id = Client.randomId()
  34. this.request = scenario.request
  35. await ClsiApp.ensureRunning()
  36. try {
  37. this.body = await Client.compile(this.project_id, this.request)
  38. } catch (error) {
  39. this.error = error
  40. }
  41. })
  42. it('should return the PDF', function () {
  43. const pdf = Client.getOutputFile(this.body, 'pdf')
  44. pdf.type.should.equal('pdf')
  45. })
  46. it('should return the log', function () {
  47. const log = Client.getOutputFile(this.body, 'log')
  48. log.type.should.equal('log')
  49. })
  50. it('should provide the pdf for download', async function () {
  51. const pdf = Client.getOutputFile(this.body, 'pdf')
  52. const response = await fetchNothing(pdf.url)
  53. response.status.should.equal(200)
  54. })
  55. it('should provide the log for download', async function () {
  56. const log = Client.getOutputFile(this.body, 'pdf')
  57. const response = await fetchNothing(log.url)
  58. response.status.should.equal(200)
  59. })
  60. it('should return only the expected keys for stats and timings', function () {
  61. const { stats, timings } = this.body.compile
  62. // Note: chai's all.keys assertion rejects extra keys
  63. stats.should.have.all.keys(
  64. 'isInitialCompile',
  65. 'latexmk-errors',
  66. 'latex-runs',
  67. 'latex-runs-with-errors',
  68. 'latex-runs-1',
  69. 'latex-runs-with-errors-1',
  70. 'pdf-caching-total-ranges-size',
  71. 'pdf-caching-reclaimed-space',
  72. 'pdf-caching-new-ranges-size',
  73. 'pdf-caching-n-ranges',
  74. 'pdf-caching-n-new-ranges',
  75. 'pdf-size'
  76. )
  77. timings.should.have.all.keys(
  78. 'sync',
  79. 'compile',
  80. 'output',
  81. 'compileE2E',
  82. 'compute-pdf-caching',
  83. 'pdf-caching-overhead-delete-stale-hashes'
  84. )
  85. })
  86. })
  87. }
  88. describe('document with shell commands', function () {
  89. before(async function () {
  90. this.project_id = Client.randomId()
  91. this.request = {
  92. resources: [
  93. {
  94. path: 'main.tex',
  95. content: `\
  96. \\documentclass{article}
  97. \\begin{document}
  98. Testing system calls:
  99. \\immediate\\write18{/bin/date > date.txt}
  100. The current date from system is: \\input{date.txt}
  101. The current date from popen is: \\input{"|date"}
  102. \\end{document}\
  103. `,
  104. },
  105. ],
  106. }
  107. await ClsiApp.ensureRunning()
  108. })
  109. it('should compile successfully', async function () {
  110. const body = await Client.compile(this.project_id, this.request)
  111. expect(body).to.exist
  112. expect(body.compile?.status, 'compile status').to.equal('success')
  113. })
  114. it('should return the PDF', async function () {
  115. const body = await Client.compile(this.project_id, this.request)
  116. const pdf = Client.getOutputFile(body, 'pdf')
  117. expect(pdf, 'pdf file not produced').to.exist
  118. expect(pdf.type, 'invalid pdf file').to.equal('pdf')
  119. })
  120. })
  121. })