SynctexTests.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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('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. })
  69. return done()
  70. }
  71. )
  72. })
  73. })
  74. describe('from pdf to code', function () {
  75. return it('should return the correct location', function (done) {
  76. return Client.syncFromPdf(
  77. this.project_id,
  78. 1,
  79. 100,
  80. 200,
  81. (error, codePositions) => {
  82. if (error != null) {
  83. throw error
  84. }
  85. expect(codePositions).to.deep.equal({
  86. code: [{ file: 'main.tex', line: 3, column: -1 }],
  87. })
  88. return done()
  89. }
  90. )
  91. })
  92. })
  93. describe('when the project directory is not available', function () {
  94. before(function () {
  95. this.other_project_id = Client.randomId()
  96. })
  97. describe('from code to pdf', function () {
  98. it('should return a 404 response', function (done) {
  99. return Client.syncFromCode(
  100. this.other_project_id,
  101. 'main.tex',
  102. 3,
  103. 5,
  104. (error, body) => {
  105. expect(String(error)).to.include('statusCode=404')
  106. expect(body).to.equal('Not Found')
  107. return done()
  108. }
  109. )
  110. })
  111. })
  112. describe('from pdf to code', function () {
  113. it('should return a 404 response', function (done) {
  114. return Client.syncFromPdf(
  115. this.other_project_id,
  116. 1,
  117. 100,
  118. 200,
  119. (error, body) => {
  120. expect(String(error)).to.include('statusCode=404')
  121. expect(body).to.equal('Not Found')
  122. return done()
  123. }
  124. )
  125. })
  126. })
  127. })
  128. describe('when the synctex file is not available', function () {
  129. before(function (done) {
  130. this.broken_project_id = Client.randomId()
  131. const content = 'this is not valid tex' // not a valid tex file
  132. this.request = {
  133. resources: [
  134. {
  135. path: 'main.tex',
  136. content,
  137. },
  138. ],
  139. }
  140. Client.compile(
  141. this.broken_project_id,
  142. this.request,
  143. (error, res, body) => {
  144. this.error = error
  145. this.res = res
  146. this.body = body
  147. return done()
  148. }
  149. )
  150. })
  151. describe('from code to pdf', function () {
  152. it('should return a 404 response', function (done) {
  153. return Client.syncFromCode(
  154. this.broken_project_id,
  155. 'main.tex',
  156. 3,
  157. 5,
  158. (error, body) => {
  159. expect(String(error)).to.include('statusCode=404')
  160. expect(body).to.equal('Not Found')
  161. return done()
  162. }
  163. )
  164. })
  165. })
  166. describe('from pdf to code', function () {
  167. it('should return a 404 response', function (done) {
  168. return Client.syncFromPdf(
  169. this.broken_project_id,
  170. 1,
  171. 100,
  172. 200,
  173. (error, body) => {
  174. expect(String(error)).to.include('statusCode=404')
  175. expect(body).to.equal('Not Found')
  176. return done()
  177. }
  178. )
  179. })
  180. })
  181. })
  182. })