sandboxed-compiles.spec.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. beforeEach(function () {
  56. projectName = `Project ${uuid()}`
  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. cy.log('wait for pdf-rendering')
  68. cy.get('.pdf-viewer').within(() => {
  69. cy.findByText(projectName)
  70. })
  71. })
  72. it('should sync to code', () => {
  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', () => {
  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 checkXeTeX() {
  135. it('should be able to use XeLaTeX', () => {
  136. cy.visit('/project')
  137. createProject('XeLaTeX')
  138. const recompile = throttledRecompile()
  139. cy.log('wait for compile')
  140. cy.get('.pdf-viewer').should('contain.text', 'XeLaTeX')
  141. cy.log('Check which compiler was used, expect pdfLaTeX')
  142. cy.get('[aria-label="View logs"]').click()
  143. cy.findByText(/This is pdfTeX/)
  144. cy.log('Switch compiler to from pdfLaTeX to XeLaTeX')
  145. cy.get('header').findByText('Menu').click()
  146. cy.findByText('Compiler')
  147. .parent()
  148. .findByText('pdfLaTeX')
  149. .parent()
  150. .select('XeLaTeX')
  151. cy.get('#left-menu-modal').click()
  152. cy.log('Trigger compile with other compiler')
  153. recompile()
  154. cy.log('Check which compiler was used, expect XeLaTeX')
  155. cy.get('[aria-label="View logs"]').click()
  156. cy.findByText(/This is XeTeX/)
  157. })
  158. }
  159. function checkUsesDefaultCompiler() {
  160. beforeEach(function () {
  161. login('user@example.com')
  162. })
  163. it('should not offer TexLive images and use default compiler', () => {
  164. cy.visit('/project')
  165. createProject('sandboxed')
  166. cy.log('wait for compile')
  167. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  168. cy.log('Check which compiler version was used, expect 2024')
  169. cy.get('[aria-label="View logs"]').click()
  170. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2024\) /)
  171. cy.log('Check that there is no TeX Live version toggle')
  172. cy.get('header').findByText('Menu').click()
  173. cy.findByText('Word Count') // wait for lazy loading
  174. cy.findByText(LABEL_TEX_LIVE_VERSION).should('not.exist')
  175. })
  176. }
  177. describe('disabled in Server Pro', () => {
  178. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  179. startWith({ pro: true })
  180. checkUsesDefaultCompiler()
  181. checkSyncTeX()
  182. checkXeTeX()
  183. })
  184. describe.skip('unavailable in CE', () => {
  185. if (isExcludedBySharding('CE_CUSTOM_1')) return
  186. startWith({ pro: false, vars: enabledVars })
  187. checkUsesDefaultCompiler()
  188. checkSyncTeX()
  189. checkXeTeX()
  190. })
  191. })