mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
9199669c0f
Change draft mode implementation GitOrigin-RevId: 3de81a3643cc024c410b7b49e77cd41c7fec8294
43 lines
1.1 KiB
JavaScript
43 lines
1.1 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}' + this.contents
|
|
)
|
|
})
|
|
})
|
|
})
|