sandboxed-compiles.spec.ts 10 KB

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