sandboxed-compiles.spec.ts 7.9 KB

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