SimpleLatexFileTests.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const Client = require('./helpers/Client')
  2. const { fetchNothing } = require('@overleaf/fetch-utils')
  3. const ClsiApp = require('./helpers/ClsiApp')
  4. describe('Simple LaTeX file', function () {
  5. const content = `\
  6. \\documentclass{article}
  7. \\begin{document}
  8. Hello world
  9. \\end{document}\
  10. `
  11. const scenarios = [
  12. {
  13. description: 'simple file',
  14. request: {
  15. resources: [{ path: 'main.tex', content }],
  16. },
  17. },
  18. {
  19. description: 'clsi-perf request',
  20. request: {
  21. resources: [{ path: 'main.tex', content }],
  22. options: {
  23. metricsPath: 'clsi-perf',
  24. metricsMethod: 'priority',
  25. },
  26. },
  27. },
  28. ]
  29. for (const scenario of scenarios) {
  30. describe(scenario.description, function () {
  31. before(async function () {
  32. this.project_id = Client.randomId()
  33. this.request = scenario.request
  34. await ClsiApp.ensureRunning()
  35. try {
  36. this.body = await Client.compile(this.project_id, this.request)
  37. } catch (error) {
  38. this.error = error
  39. }
  40. })
  41. it('should return the PDF', function () {
  42. const pdf = Client.getOutputFile(this.body, 'pdf')
  43. pdf.type.should.equal('pdf')
  44. })
  45. it('should return the log', function () {
  46. const log = Client.getOutputFile(this.body, 'log')
  47. log.type.should.equal('log')
  48. })
  49. it('should provide the pdf for download', async function () {
  50. const pdf = Client.getOutputFile(this.body, 'pdf')
  51. const response = await fetchNothing(pdf.url)
  52. response.status.should.equal(200)
  53. })
  54. it('should provide the log for download', async function () {
  55. const log = Client.getOutputFile(this.body, 'pdf')
  56. const response = await fetchNothing(log.url)
  57. response.status.should.equal(200)
  58. })
  59. it('should return only the expected keys for stats and timings', function () {
  60. const { stats, timings } = this.body.compile
  61. // Note: chai's all.keys assertion rejects extra keys
  62. stats.should.have.all.keys(
  63. 'isInitialCompile',
  64. 'latexmk-errors',
  65. 'latex-runs',
  66. 'latex-runs-with-errors',
  67. 'latex-runs-2',
  68. 'latex-runs-with-errors-2',
  69. 'pdf-caching-total-ranges-size',
  70. 'pdf-caching-reclaimed-space',
  71. 'pdf-caching-new-ranges-size',
  72. 'pdf-caching-n-ranges',
  73. 'pdf-caching-n-new-ranges',
  74. 'pdf-size'
  75. )
  76. timings.should.have.all.keys(
  77. 'sync',
  78. 'compile',
  79. 'output',
  80. 'compileE2E',
  81. 'compute-pdf-caching',
  82. 'pdf-caching-overhead-delete-stale-hashes'
  83. )
  84. })
  85. })
  86. }
  87. })