sandboxed-compiles.spec.ts 8.5 KB

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