ClearCache.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { promisify } from 'node:util'
  2. import Client from './helpers/Client.js'
  3. import ClsiApp from './helpers/ClsiApp.js'
  4. import { expect } from 'chai'
  5. const sleep = promisify(setTimeout)
  6. describe('Clear cache', function () {
  7. before(async function () {
  8. this.request = {
  9. options: {
  10. timeout: 100,
  11. }, // seconds
  12. resources: [
  13. {
  14. path: 'main.tex',
  15. content: `\
  16. \\documentclass{article}
  17. \\begin{document}
  18. \\def\\x{Hello!\\par\\x}
  19. \\x
  20. \\end{document}\
  21. `,
  22. },
  23. ],
  24. }
  25. this.project_id = Client.randomId()
  26. await ClsiApp.ensureRunning()
  27. // start the compile in the background
  28. Client.compile(this.project_id, this.request)
  29. .then(body => {
  30. this.compileResult = { body }
  31. })
  32. .catch(error => {
  33. this.compileResult = { error }
  34. })
  35. // wait for 1 second before stopping the compile
  36. await sleep(1000)
  37. try {
  38. const res = await Client.clearCache(this.project_id)
  39. this.stopResult = { res }
  40. } catch (error) {
  41. this.stopResult = { error }
  42. }
  43. // allow time for the compile request to terminate
  44. await sleep(1000)
  45. })
  46. it('should emit a compile response with terminated status', function () {
  47. expect(this.stopResult.error).not.to.exist
  48. expect(this.stopResult.res.status).to.equal(204)
  49. expect(this.compileResult.error).not.to.exist
  50. expect(this.compileResult.body.compile.status).to.equal('terminated')
  51. expect(this.compileResult.body.compile.error).to.equal('terminated')
  52. })
  53. it('should return the log output file name', function () {
  54. const outputFilePaths = this.compileResult.body.compile.outputFiles.map(
  55. x => x.path
  56. )
  57. outputFilePaths.should.include('output.synctex(busy)') // compile was still pending
  58. outputFilePaths.should.include('output.log')
  59. })
  60. it('should work with not pending compile', async function () {
  61. const res = await Client.clearCache(this.project_id)
  62. expect(res.status).to.equal(204)
  63. })
  64. })