2022-07-19 14:39:03 +00:00
|
|
|
const Path = require('path')
|
|
|
|
const fsPromises = require('fs/promises')
|
|
|
|
const { expect } = require('chai')
|
|
|
|
const mockFs = require('mock-fs')
|
2020-02-19 11:15:37 +00:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
2022-07-19 14:39:03 +00:00
|
|
|
|
|
|
|
const MODULE_PATH = Path.join(__dirname, '../../../app/js/DraftModeManager')
|
2016-02-02 14:26:14 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
describe('DraftModeManager', function () {
|
|
|
|
beforeEach(function () {
|
2022-07-19 14:39:03 +00:00
|
|
|
this.DraftModeManager = SandboxedModule.require(MODULE_PATH, {
|
2020-02-19 11:15:37 +00:00
|
|
|
requires: {
|
2022-07-19 14:39:03 +00:00
|
|
|
'fs/promises': fsPromises,
|
2021-07-13 11:04:48 +00:00
|
|
|
},
|
2020-02-19 11:15:37 +00:00
|
|
|
})
|
2022-07-19 14:39:03 +00:00
|
|
|
this.filename = '/mock/filename.tex'
|
|
|
|
this.contents = `\
|
2020-02-19 11:15:08 +00:00
|
|
|
\\documentclass{article}
|
|
|
|
\\begin{document}
|
|
|
|
Hello world
|
|
|
|
\\end{document}\
|
2020-02-19 11:15:37 +00:00
|
|
|
`
|
2022-07-19 14:39:03 +00:00
|
|
|
mockFs({
|
|
|
|
[this.filename]: this.contents,
|
2020-02-19 11:15:37 +00:00
|
|
|
})
|
2022-07-19 14:39:03 +00:00
|
|
|
})
|
2020-02-19 11:15:37 +00:00
|
|
|
|
2022-07-19 14:39:03 +00:00
|
|
|
afterEach(function () {
|
|
|
|
mockFs.restore()
|
|
|
|
})
|
2020-02-19 11:15:37 +00:00
|
|
|
|
2022-07-19 14:39:03 +00:00
|
|
|
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(
|
2022-07-22 08:12:18 +00:00
|
|
|
'\\PassOptionsToPackage{draft}{graphicx}\\PassOptionsToPackage{draft}{graphics}' +
|
|
|
|
this.contents
|
2022-07-19 14:39:03 +00:00
|
|
|
)
|
2020-02-19 11:15:37 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|