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