SynctexTests.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. expect(String(error)).to.include('statusCode=404')
  100. expect(body).to.equal('Not Found')
  101. return done()
  102. }
  103. )
  104. })
  105. })
  106. describe('from pdf to code', function () {
  107. it('should return a 404 response', function (done) {
  108. return Client.syncFromPdf(
  109. this.other_project_id,
  110. 1,
  111. 100,
  112. 200,
  113. (error, body) => {
  114. expect(String(error)).to.include('statusCode=404')
  115. expect(body).to.equal('Not Found')
  116. return done()
  117. }
  118. )
  119. })
  120. })
  121. })
  122. describe('when the synctex file is not available', function () {
  123. before(function (done) {
  124. this.broken_project_id = Client.randomId()
  125. const content = 'this is not valid tex' // not a valid tex file
  126. this.request = {
  127. resources: [
  128. {
  129. path: 'main.tex',
  130. content
  131. }
  132. ]
  133. }
  134. Client.compile(
  135. this.broken_project_id,
  136. this.request,
  137. (error, res, body) => {
  138. this.error = error
  139. this.res = res
  140. this.body = body
  141. return done()
  142. }
  143. )
  144. })
  145. describe('from code to pdf', function () {
  146. it('should return a 404 response', function (done) {
  147. return Client.syncFromCode(
  148. this.broken_project_id,
  149. 'main.tex',
  150. 3,
  151. 5,
  152. (error, body) => {
  153. expect(String(error)).to.include('statusCode=404')
  154. expect(body).to.equal('Not Found')
  155. return done()
  156. }
  157. )
  158. })
  159. })
  160. describe('from pdf to code', function () {
  161. it('should return a 404 response', function (done) {
  162. return Client.syncFromPdf(
  163. this.broken_project_id,
  164. 1,
  165. 100,
  166. 200,
  167. (error, body) => {
  168. expect(String(error)).to.include('statusCode=404')
  169. expect(body).to.equal('Not Found')
  170. return done()
  171. }
  172. )
  173. })
  174. })
  175. })
  176. })