97247b8ea5
GitOrigin-RevId: ff8df32d85b2ecd2837c9eee6d6d2b3b95285239
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import { vi, expect, describe, beforeEach, afterEach, it } from 'vitest'
|
|
import Path from 'node:path'
|
|
import fs from 'node:fs'
|
|
import fsPromises from 'node:fs/promises'
|
|
import os from 'node:os'
|
|
|
|
const MODULE_PATH = Path.join(
|
|
import.meta.dirname,
|
|
'../../../app/js/DraftModeManager'
|
|
)
|
|
|
|
describe('DraftModeManager', () => {
|
|
beforeEach(async ctx => {
|
|
vi.doMock('node:fs/promises', () => ({
|
|
default: fsPromises,
|
|
}))
|
|
|
|
ctx.DraftModeManager = (await import(MODULE_PATH)).default
|
|
ctx.tmpDir = fs.mkdtempSync(Path.join(os.tmpdir(), 'draft-mode-test-'))
|
|
ctx.filename = Path.join(ctx.tmpDir, 'filename.tex')
|
|
ctx.contents = `\
|
|
\\documentclass{article}
|
|
\\begin{document}
|
|
Hello world
|
|
\\end{document}\
|
|
`
|
|
fs.writeFileSync(ctx.filename, ctx.contents)
|
|
})
|
|
|
|
afterEach(ctx => {
|
|
fs.rmSync(ctx.tmpDir, { recursive: true })
|
|
})
|
|
|
|
describe('injectDraftMode', () => {
|
|
it('prepends a special command to the beginning of the file', async ctx => {
|
|
await ctx.DraftModeManager.promises.injectDraftMode(ctx.filename)
|
|
const contents = await fsPromises.readFile(ctx.filename, {
|
|
encoding: 'utf8',
|
|
})
|
|
expect(contents).to.equal(
|
|
'\\PassOptionsToPackage{draft}{graphicx}\\PassOptionsToPackage{draft}{graphics}' +
|
|
ctx.contents
|
|
)
|
|
})
|
|
})
|
|
})
|