overleaf/services/clsi/test/unit/js/DraftModeManagerTests.js
Brian Gough 9ea1226460 Merge pull request #8969 from overleaf/bg-issue8967
Apply draft mode to graphics package as well (in addition to graphicx)

GitOrigin-RevId: 6137f90ef9d579f0e6554801e8f2e0f5dee2aa83
2022-07-25 08:03:57 +00:00

44 lines
1.2 KiB
JavaScript

const Path = require('path')
const fsPromises = require('fs/promises')
const { expect } = require('chai')
const mockFs = require('mock-fs')
const SandboxedModule = require('sandboxed-module')
const MODULE_PATH = Path.join(__dirname, '../../../app/js/DraftModeManager')
describe('DraftModeManager', function () {
beforeEach(function () {
this.DraftModeManager = SandboxedModule.require(MODULE_PATH, {
requires: {
'fs/promises': fsPromises,
},
})
this.filename = '/mock/filename.tex'
this.contents = `\
\\documentclass{article}
\\begin{document}
Hello world
\\end{document}\
`
mockFs({
[this.filename]: this.contents,
})
})
afterEach(function () {
mockFs.restore()
})
describe('injectDraftMode', function () {
it('prepends a special command to the beginning of the file', async function () {
await this.DraftModeManager.promises.injectDraftMode(this.filename)
const contents = await fsPromises.readFile(this.filename, {
encoding: 'utf8',
})
expect(contents).to.equal(
'\\PassOptionsToPackage{draft}{graphicx}\\PassOptionsToPackage{draft}{graphics}' +
this.contents
)
})
})
})