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