SimpleLatexFileTests.js 2.6 KB

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