sandboxed-compiles.spec.ts 7.7 KB

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