StopCompile.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const Client = require('./helpers/Client')
  2. const ClsiApp = require('./helpers/ClsiApp')
  3. const { expect } = require('chai')
  4. describe('Stop compile', function () {
  5. before(function (done) {
  6. this.request = {
  7. options: {
  8. timeout: 100,
  9. }, // seconds
  10. resources: [
  11. {
  12. path: 'main.tex',
  13. content: `\
  14. \\documentclass{article}
  15. \\begin{document}
  16. \\def\\x{Hello!\\par\\x}
  17. \\x
  18. \\end{document}\
  19. `,
  20. },
  21. ],
  22. }
  23. this.project_id = Client.randomId()
  24. ClsiApp.ensureRunning(() => {
  25. // start the compile in the background
  26. Client.compile(this.project_id, this.request, (error, res, body) => {
  27. this.compileResult = { error, res, body }
  28. })
  29. // wait for 1 second before stopping the compile
  30. setTimeout(() => {
  31. Client.stopCompile(this.project_id, (error, res, body) => {
  32. this.stopResult = { error, res, body }
  33. setTimeout(done, 1000) // allow time for the compile request to terminate
  34. })
  35. }, 1000)
  36. })
  37. })
  38. it('should force a compile response with an error status', function () {
  39. expect(this.stopResult.error).to.be.null
  40. expect(this.stopResult.res.statusCode).to.equal(204)
  41. expect(this.compileResult.res.statusCode).to.equal(200)
  42. expect(this.compileResult.body.compile.status).to.equal('terminated')
  43. expect(this.compileResult.body.compile.error).to.equal('terminated')
  44. })
  45. })