DraftModeManagerTests.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const Path = require('node:path')
  2. const fsPromises = require('node:fs/promises')
  3. const { expect } = require('chai')
  4. const mockFs = require('mock-fs')
  5. const SandboxedModule = require('sandboxed-module')
  6. const MODULE_PATH = Path.join(__dirname, '../../../app/js/DraftModeManager')
  7. describe('DraftModeManager', function () {
  8. beforeEach(function () {
  9. this.DraftModeManager = SandboxedModule.require(MODULE_PATH, {
  10. requires: {
  11. 'fs/promises': fsPromises,
  12. },
  13. })
  14. this.filename = '/mock/filename.tex'
  15. this.contents = `\
  16. \\documentclass{article}
  17. \\begin{document}
  18. Hello world
  19. \\end{document}\
  20. `
  21. mockFs({
  22. [this.filename]: this.contents,
  23. })
  24. })
  25. afterEach(function () {
  26. mockFs.restore()
  27. })
  28. describe('injectDraftMode', function () {
  29. it('prepends a special command to the beginning of the file', async function () {
  30. await this.DraftModeManager.promises.injectDraftMode(this.filename)
  31. const contents = await fsPromises.readFile(this.filename, {
  32. encoding: 'utf8',
  33. })
  34. expect(contents).to.equal(
  35. '\\PassOptionsToPackage{draft}{graphicx}\\PassOptionsToPackage{draft}{graphics}' +
  36. this.contents
  37. )
  38. })
  39. })
  40. })