sandboxed-compiles.spec.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. import { isExcludedBySharding, startWith } from './helpers/config'
  4. import { throttledRecompile } 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. DOCKER_RUNNER: 'true',
  12. SANDBOXED_COMPILES: 'true',
  13. SANDBOXED_COMPILES_SIBLING_CONTAINERS: 'true',
  14. ALL_TEX_LIVE_DOCKER_IMAGE_NAMES: '2023,2022',
  15. }
  16. describe('enabled in Server Pro', function () {
  17. if (isExcludedBySharding('PRO_CUSTOM_2')) return
  18. startWith({
  19. pro: true,
  20. vars: enabledVars,
  21. resetData: true,
  22. })
  23. ensureUserExists({ email: 'user@example.com' })
  24. beforeEach(function () {
  25. login('user@example.com')
  26. })
  27. it('should offer TexLive images and switch the compiler', function () {
  28. createProject('sandboxed')
  29. const recompile = throttledRecompile()
  30. cy.log('wait for compile')
  31. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  32. cy.log('Check which compiler version was used, expect 2023')
  33. cy.get('[aria-label="View logs"]').click()
  34. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2023\) /)
  35. cy.log('Switch TeXLive version from 2023 to 2022')
  36. cy.get('header').findByText('Menu').click()
  37. cy.findByText(LABEL_TEX_LIVE_VERSION)
  38. .parent()
  39. .findByText('2023')
  40. .parent()
  41. .select('2022')
  42. cy.get('.left-menu-modal-backdrop').click()
  43. cy.log('Trigger compile with other TeX Live version')
  44. recompile()
  45. cy.log('Check which compiler version was used, expect 2022')
  46. cy.get('[aria-label="View logs"]').click()
  47. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2022\) /)
  48. })
  49. checkSyncTeX()
  50. checkXeTeX()
  51. checkRecompilesAfterErrors()
  52. })
  53. function checkSyncTeX() {
  54. describe('SyncTeX', function () {
  55. let projectName: string
  56. beforeEach(function () {
  57. projectName = `Project ${uuid()}`
  58. createProject(projectName)
  59. const recompile = throttledRecompile()
  60. cy.findByText('\\maketitle').parent().click()
  61. cy.findByText('\\maketitle')
  62. .parent()
  63. .type(
  64. `\n\\pagebreak\n\\section{{}Section A}\n\\pagebreak\n\\section{{}Section B}\n\\pagebreak`
  65. )
  66. recompile()
  67. cy.log('wait for pdf-rendering')
  68. cy.get('.pdf-viewer').within(() => {
  69. cy.findByText(projectName)
  70. })
  71. })
  72. it('should sync to code', function () {
  73. cy.log('navigate to \\maketitle using double click in PDF')
  74. cy.get('.pdf-viewer').within(() => {
  75. cy.findByText(projectName).dblclick()
  76. })
  77. cy.get('.cm-activeLine').should('have.text', '\\maketitle')
  78. cy.log('navigate to Section A using double click in PDF')
  79. cy.get('.pdf-viewer').within(() => {
  80. cy.findByText('Section A').dblclick()
  81. })
  82. cy.get('.cm-activeLine').should('have.text', '\\section{Section A}')
  83. cy.log('navigate to Section B using arrow button')
  84. cy.get('.pdfjs-viewer-inner')
  85. .should('have.prop', 'scrollTop')
  86. .as('start')
  87. cy.get('.pdf-viewer').within(() => {
  88. cy.findByText('Section B').scrollIntoView()
  89. })
  90. cy.get('@start').then((start: any) => {
  91. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  92. })
  93. // The sync button is swapped as the position in the PDF changes.
  94. // Cypress appears to click on a button that references a stale position.
  95. // Adding a cy.wait() statement is the most reliable "fix" so far :/
  96. cy.wait(1000)
  97. cy.get('[aria-label^="Go to PDF location in code"]').click()
  98. cy.get('.cm-activeLine').should('have.text', '\\section{Section B}')
  99. })
  100. it('should sync to pdf', function () {
  101. cy.log('zoom in')
  102. cy.findByText('45%').click()
  103. cy.findByText('400%').click()
  104. cy.log('scroll to top')
  105. cy.get('.pdfjs-viewer-inner').scrollTo('top')
  106. waitUntilScrollingFinished('.pdfjs-viewer-inner', -1).as('start')
  107. cy.log('navigate to title')
  108. cy.findByText('\\maketitle').parent().click()
  109. cy.get('[aria-label="Go to code location in PDF"]').click()
  110. cy.get('@start').then((start: any) => {
  111. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  112. .as('title')
  113. .should('be.greaterThan', start)
  114. })
  115. cy.log('navigate to Section A')
  116. cy.get('.cm-content').within(() => cy.findByText('Section A').click())
  117. cy.get('[aria-label="Go to code location in PDF"]').click()
  118. cy.get('@title').then((title: any) => {
  119. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  120. .as('sectionA')
  121. .should('be.greaterThan', title)
  122. })
  123. cy.log('navigate to Section B')
  124. cy.get('.cm-content').within(() => cy.findByText('Section B').click())
  125. cy.get('[aria-label="Go to code location in PDF"]').click()
  126. cy.get('@sectionA').then((title: any) => {
  127. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  128. .as('sectionB')
  129. .should('be.greaterThan', title)
  130. })
  131. })
  132. })
  133. }
  134. function checkRecompilesAfterErrors() {
  135. it('recompiles even if there are Latex errors', function () {
  136. login('user@example.com')
  137. createProject('test-project')
  138. const recompile = throttledRecompile()
  139. cy.findByText('\\maketitle').parent().click()
  140. cy.findByText('\\maketitle')
  141. .parent()
  142. .type('\n\\fakeCommand{} \n\\section{{}Test Section}')
  143. recompile()
  144. recompile()
  145. cy.get('.pdf-viewer').should('contain.text', 'Test Section')
  146. cy.get('.logs-pane').should('not.contain.text', 'No PDF')
  147. })
  148. }
  149. function checkXeTeX() {
  150. it('should be able to use XeLaTeX', function () {
  151. createProject('XeLaTeX')
  152. const recompile = throttledRecompile()
  153. cy.log('wait for compile')
  154. cy.get('.pdf-viewer').should('contain.text', 'XeLaTeX')
  155. cy.log('Check which compiler was used, expect pdfLaTeX')
  156. cy.get('[aria-label="View logs"]').click()
  157. cy.findByText(/This is pdfTeX/)
  158. cy.log('Switch compiler to from pdfLaTeX to XeLaTeX')
  159. cy.get('header').findByText('Menu').click()
  160. cy.findByText('Compiler')
  161. .parent()
  162. .findByText('pdfLaTeX')
  163. .parent()
  164. .select('XeLaTeX')
  165. cy.get('.left-menu-modal-backdrop').click()
  166. cy.log('Trigger compile with other compiler')
  167. recompile()
  168. cy.log('Check which compiler was used, expect XeLaTeX')
  169. cy.get('[aria-label="View logs"]').click()
  170. cy.findByText(/This is XeTeX/)
  171. })
  172. }
  173. function checkUsesDefaultCompiler() {
  174. beforeEach(function () {
  175. login('user@example.com')
  176. })
  177. it('should not offer TexLive images and use default compiler', function () {
  178. createProject('sandboxed')
  179. cy.log('wait for compile')
  180. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  181. cy.log('Check which compiler version was used, expect 2024')
  182. cy.get('[aria-label="View logs"]').click()
  183. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2024\) /)
  184. cy.log('Check that there is no TeX Live version toggle')
  185. cy.get('header').findByText('Menu').click()
  186. cy.findByText('Word Count') // wait for lazy loading
  187. cy.findByText(LABEL_TEX_LIVE_VERSION).should('not.exist')
  188. })
  189. }
  190. describe('disabled in Server Pro', function () {
  191. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  192. startWith({ pro: true })
  193. ensureUserExists({ email: 'user@example.com' })
  194. beforeEach(function () {
  195. login('user@example.com')
  196. })
  197. checkUsesDefaultCompiler()
  198. checkSyncTeX()
  199. checkXeTeX()
  200. checkRecompilesAfterErrors()
  201. })
  202. describe.skip('unavailable in CE', function () {
  203. if (isExcludedBySharding('CE_CUSTOM_1')) return
  204. startWith({ pro: false, vars: enabledVars, resetData: true })
  205. ensureUserExists({ email: 'user@example.com' })
  206. beforeEach(function () {
  207. login('user@example.com')
  208. })
  209. checkUsesDefaultCompiler()
  210. checkSyncTeX()
  211. checkXeTeX()
  212. checkRecompilesAfterErrors()
  213. })
  214. })