SynctexTests.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* eslint-disable
  2. no-unused-vars,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const Client = require('./helpers/Client')
  13. const request = require('request')
  14. const { expect } = require('chai')
  15. const ClsiApp = require('./helpers/ClsiApp')
  16. const crypto = require('node:crypto')
  17. describe('Syncing', function () {
  18. before(function (done) {
  19. const content = `\
  20. \\documentclass{article}
  21. \\begin{document}
  22. Hello world
  23. \\end{document}\
  24. `
  25. this.request = {
  26. resources: [
  27. {
  28. path: 'main.tex',
  29. content,
  30. },
  31. ],
  32. }
  33. this.project_id = Client.randomId()
  34. return ClsiApp.ensureRunning(() => {
  35. return Client.compile(
  36. this.project_id,
  37. this.request,
  38. (error, res, body) => {
  39. this.error = error
  40. this.res = res
  41. this.body = body
  42. return done()
  43. }
  44. )
  45. })
  46. })
  47. describe('from code to pdf', function () {
  48. return it('should return the correct location', function (done) {
  49. return Client.syncFromCode(
  50. this.project_id,
  51. 'main.tex',
  52. 3,
  53. 5,
  54. (error, pdfPositions) => {
  55. if (error != null) {
  56. throw error
  57. }
  58. expect(pdfPositions).to.deep.equal({
  59. pdf: [
  60. {
  61. page: 1,
  62. h: 133.768356,
  63. v: 134.764618,
  64. height: 6.918498,
  65. width: 343.71106,
  66. },
  67. ],
  68. downloadedFromCache: false,
  69. })
  70. return done()
  71. }
  72. )
  73. })
  74. })
  75. describe('from pdf to code', function () {
  76. return it('should return the correct location', function (done) {
  77. return Client.syncFromPdf(
  78. this.project_id,
  79. 1,
  80. 100,
  81. 200,
  82. (error, codePositions) => {
  83. if (error != null) {
  84. throw error
  85. }
  86. expect(codePositions).to.deep.equal({
  87. code: [{ file: 'main.tex', line: 3, column: -1 }],
  88. downloadedFromCache: false,
  89. })
  90. return done()
  91. }
  92. )
  93. })
  94. })
  95. describe('when the project directory is not available', function () {
  96. before(function () {
  97. this.other_project_id = Client.randomId()
  98. })
  99. describe('from code to pdf', function () {
  100. it('should return a 404 response', function (done) {
  101. return Client.syncFromCode(
  102. this.other_project_id,
  103. 'main.tex',
  104. 3,
  105. 5,
  106. (error, body) => {
  107. expect(String(error)).to.include('statusCode=404')
  108. expect(body).to.equal('Not Found')
  109. return done()
  110. }
  111. )
  112. })
  113. })
  114. describe('from pdf to code', function () {
  115. it('should return a 404 response', function (done) {
  116. return Client.syncFromPdf(
  117. this.other_project_id,
  118. 1,
  119. 100,
  120. 200,
  121. (error, body) => {
  122. expect(String(error)).to.include('statusCode=404')
  123. expect(body).to.equal('Not Found')
  124. return done()
  125. }
  126. )
  127. })
  128. })
  129. })
  130. describe('when the synctex file is not available', function () {
  131. before(function (done) {
  132. this.broken_project_id = Client.randomId()
  133. const content = 'this is not valid tex' // not a valid tex file
  134. this.request = {
  135. resources: [
  136. {
  137. path: 'main.tex',
  138. content,
  139. },
  140. ],
  141. }
  142. Client.compile(
  143. this.broken_project_id,
  144. this.request,
  145. (error, res, body) => {
  146. this.error = error
  147. this.res = res
  148. this.body = body
  149. return done()
  150. }
  151. )
  152. })
  153. describe('from code to pdf', function () {
  154. it('should return a 404 response', function (done) {
  155. return Client.syncFromCode(
  156. this.broken_project_id,
  157. 'main.tex',
  158. 3,
  159. 5,
  160. (error, body) => {
  161. expect(String(error)).to.include('statusCode=404')
  162. expect(body).to.equal('Not Found')
  163. return done()
  164. }
  165. )
  166. })
  167. })
  168. describe('from pdf to code', function () {
  169. it('should return a 404 response', function (done) {
  170. return Client.syncFromPdf(
  171. this.broken_project_id,
  172. 1,
  173. 100,
  174. 200,
  175. (error, body) => {
  176. expect(String(error)).to.include('statusCode=404')
  177. expect(body).to.equal('Not Found')
  178. return done()
  179. }
  180. )
  181. })
  182. })
  183. })
  184. })