sandboxed-compiles.spec.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. import { isExcludedBySharding, startWith } from './helpers/config'
  4. import { throttledRecompile, stopCompile } from './helpers/compile'
  5. import { v4 as uuid } from 'uuid'
  6. import { waitUntilScrollingFinished } from './helpers/waitUntilScrollingFinished'
  7. import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
  8. const LABEL_TEX_LIVE_VERSION = 'TeX Live version'
  9. describe('SandboxedCompiles', function () {
  10. const enabledVars = {
  11. SANDBOXED_COMPILES: 'true',
  12. ALL_TEX_LIVE_DOCKER_IMAGE_NAMES: '2023,2022',
  13. }
  14. describe('enabled in Server Pro', function () {
  15. if (isExcludedBySharding('PRO_CUSTOM_2')) return
  16. startWith({
  17. pro: true,
  18. vars: enabledVars,
  19. resetData: true,
  20. })
  21. ensureUserExists({ email: 'user@example.com' })
  22. beforeEach(function () {
  23. login('user@example.com')
  24. })
  25. it('should offer TexLive images and switch the compiler', function () {
  26. createProject('sandboxed')
  27. const recompile = throttledRecompile()
  28. cy.log('wait for compile')
  29. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  30. cy.log('Check which compiler version was used, expect 2023')
  31. cy.get('[aria-label="View logs"]').click()
  32. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2023\) /)
  33. cy.log('Switch TeXLive version from 2023 to 2022')
  34. cy.get('header').findByText('Menu').click()
  35. cy.findByText(LABEL_TEX_LIVE_VERSION)
  36. .parent()
  37. .findByText('2023')
  38. .parent()
  39. .select('2022')
  40. cy.get('.left-menu-modal-backdrop').click()
  41. cy.log('Trigger compile with other TeX Live version')
  42. recompile()
  43. cy.log('Check which compiler version was used, expect 2022')
  44. cy.get('[aria-label="View logs"]').click()
  45. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2022\) /)
  46. })
  47. checkSyncTeX()
  48. checkXeTeX()
  49. checkRecompilesAfterErrors()
  50. checkStopCompile()
  51. })
  52. function checkStopCompile() {
  53. it('users can stop a running compile', function () {
  54. login('user@example.com')
  55. createProject('test-project')
  56. // create an infinite loop in the main document
  57. // this will cause the compile to run indefinitely
  58. cy.findByText('\\maketitle').parent().click()
  59. cy.findByText('\\maketitle')
  60. .parent()
  61. .type('\n\\def\\x{{}Hello!\\par\\x}\\x')
  62. cy.log('Start compile')
  63. // We need to start the compile manually because we do not want to wait for it to finish
  64. cy.findByText('Recompile').click()
  65. // Now stop the compile and kill the latex process
  66. stopCompile({ delay: 1000 })
  67. cy.get('.logs-pane')
  68. .invoke('text')
  69. .should('match', /PDF Rendering Error|Compilation cancelled/)
  70. // Check that the previous compile is not running in the background by
  71. // disabling the infinite loop and recompiling
  72. cy.findByText('\\def').parent().click()
  73. cy.findByText('\\def').parent().type('{home}disabled loop% ')
  74. cy.findByText('Recompile').click()
  75. cy.get('.pdf-viewer').should('contain.text', 'disabled loop')
  76. cy.get('.logs-pane').should(
  77. 'not.contain.text',
  78. 'A previous compile is still running'
  79. )
  80. })
  81. }
  82. function checkSyncTeX() {
  83. // TODO(25342): re-enable
  84. // eslint-disable-next-line mocha/no-skipped-tests
  85. describe.skip('SyncTeX', function () {
  86. let projectName: string
  87. beforeEach(function () {
  88. projectName = `Project ${uuid()}`
  89. createProject(projectName)
  90. const recompile = throttledRecompile()
  91. cy.findByText('\\maketitle').parent().click()
  92. cy.findByText('\\maketitle')
  93. .parent()
  94. .type(
  95. `\n\\pagebreak\n\\section{{}Section A}\n\\pagebreak\n\\section{{}Section B}\n\\pagebreak`
  96. )
  97. recompile()
  98. cy.log('wait for pdf-rendering')
  99. cy.get('.pdf-viewer').within(() => {
  100. cy.findByText(projectName)
  101. })
  102. })
  103. it('should sync to code', function () {
  104. cy.log('navigate to \\maketitle using double click in PDF')
  105. cy.get('.pdf-viewer').within(() => {
  106. cy.findByText(projectName).dblclick()
  107. })
  108. cy.get('.cm-activeLine').should('have.text', '\\maketitle')
  109. cy.log('navigate to Section A using double click in PDF')
  110. cy.get('.pdf-viewer').within(() => {
  111. cy.findByText('Section A').dblclick()
  112. })
  113. cy.get('.cm-activeLine').should('have.text', '\\section{Section A}')
  114. cy.log('navigate to Section B using arrow button')
  115. cy.get('.pdfjs-viewer-inner')
  116. .should('have.prop', 'scrollTop')
  117. .as('start')
  118. cy.get('.pdf-viewer').within(() => {
  119. cy.findByText('Section B').scrollIntoView()
  120. })
  121. cy.get('@start').then((start: any) => {
  122. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  123. })
  124. // The sync button is swapped as the position in the PDF changes.
  125. // Cypress appears to click on a button that references a stale position.
  126. // Adding a cy.wait() statement is the most reliable "fix" so far :/
  127. cy.wait(1000)
  128. cy.get('[aria-label^="Go to PDF location in code"]').click()
  129. cy.get('.cm-activeLine').should('have.text', '\\section{Section B}')
  130. })
  131. it('should sync to pdf', function () {
  132. cy.log('zoom in')
  133. cy.findByText('45%').click()
  134. cy.findByText('400%').click()
  135. cy.log('scroll to top')
  136. cy.get('.pdfjs-viewer-inner').scrollTo('top')
  137. waitUntilScrollingFinished('.pdfjs-viewer-inner', -1).as('start')
  138. cy.log('navigate to title')
  139. cy.findByText('\\maketitle').parent().click()
  140. cy.get('[aria-label="Go to code location in PDF"]').click()
  141. cy.get('@start').then((start: any) => {
  142. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  143. .as('title')
  144. .should('be.greaterThan', start)
  145. })
  146. cy.log('navigate to Section A')
  147. cy.get('.cm-content').within(() => cy.findByText('Section A').click())
  148. cy.get('[aria-label="Go to code location in PDF"]').click()
  149. cy.get('@title').then((title: any) => {
  150. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  151. .as('sectionA')
  152. .should('be.greaterThan', title)
  153. })
  154. cy.log('navigate to Section B')
  155. cy.get('.cm-content').within(() => cy.findByText('Section B').click())
  156. cy.get('[aria-label="Go to code location in PDF"]').click()
  157. cy.get('@sectionA').then((title: any) => {
  158. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  159. .as('sectionB')
  160. .should('be.greaterThan', title)
  161. })
  162. })
  163. })
  164. }
  165. function checkRecompilesAfterErrors() {
  166. it('recompiles even if there are Latex errors', function () {
  167. login('user@example.com')
  168. createProject('test-project')
  169. const recompile = throttledRecompile()
  170. cy.findByText('\\maketitle').parent().click()
  171. cy.findByText('\\maketitle')
  172. .parent()
  173. .type('\n\\fakeCommand{} \n\\section{{}Test Section}')
  174. recompile()
  175. recompile()
  176. cy.get('.pdf-viewer').should('contain.text', 'Test Section')
  177. cy.get('.logs-pane').should('not.contain.text', 'No PDF')
  178. })
  179. }
  180. function checkXeTeX() {
  181. it('should be able to use XeLaTeX', function () {
  182. createProject('XeLaTeX')
  183. const recompile = throttledRecompile()
  184. cy.log('wait for compile')
  185. cy.get('.pdf-viewer').should('contain.text', 'XeLaTeX')
  186. cy.log('Check which compiler was used, expect pdfLaTeX')
  187. cy.get('[aria-label="View logs"]').click()
  188. cy.findByText(/This is pdfTeX/)
  189. cy.log('Switch compiler to from pdfLaTeX to XeLaTeX')
  190. cy.get('header').findByText('Menu').click()
  191. cy.findByText('Compiler')
  192. .parent()
  193. .findByText('pdfLaTeX')
  194. .parent()
  195. .select('XeLaTeX')
  196. cy.get('.left-menu-modal-backdrop').click()
  197. cy.log('Trigger compile with other compiler')
  198. recompile()
  199. cy.log('Check which compiler was used, expect XeLaTeX')
  200. cy.get('[aria-label="View logs"]').click()
  201. cy.findByText(/This is XeTeX/)
  202. })
  203. }
  204. function checkUsesDefaultCompiler() {
  205. beforeEach(function () {
  206. login('user@example.com')
  207. })
  208. it('should not offer TexLive images and use default compiler', function () {
  209. createProject('sandboxed')
  210. cy.log('wait for compile')
  211. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  212. cy.log('Check which compiler version was used, expect 2025')
  213. cy.get('[aria-label="View logs"]').click()
  214. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2025\) /)
  215. cy.log('Check that there is no TeX Live version toggle')
  216. cy.get('header').findByText('Menu').click()
  217. cy.findByText('Word Count') // wait for lazy loading
  218. cy.findByText(LABEL_TEX_LIVE_VERSION).should('not.exist')
  219. })
  220. }
  221. describe('disabled in Server Pro', function () {
  222. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  223. startWith({ pro: true })
  224. ensureUserExists({ email: 'user@example.com' })
  225. beforeEach(function () {
  226. login('user@example.com')
  227. })
  228. checkUsesDefaultCompiler()
  229. checkSyncTeX()
  230. checkXeTeX()
  231. checkRecompilesAfterErrors()
  232. checkStopCompile()
  233. })
  234. describe.skip('unavailable in CE', function () {
  235. if (isExcludedBySharding('CE_CUSTOM_1')) return
  236. startWith({ pro: false, vars: enabledVars, resetData: true })
  237. ensureUserExists({ email: 'user@example.com' })
  238. beforeEach(function () {
  239. login('user@example.com')
  240. })
  241. checkUsesDefaultCompiler()
  242. checkSyncTeX()
  243. checkXeTeX()
  244. checkRecompilesAfterErrors()
  245. checkStopCompile()
  246. })
  247. })