This repository has been archived by the owner on Aug 14, 2022. It is now read-only.
/
builder-spec.js
159 lines (125 loc) · 5.29 KB
/
builder-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/** @babel */
// eslint-disable-next-line no-unused-vars
import { afterEach, beforeEach, it, fit } from './async-spec-helpers'
import { cloneFixtures } from './spec-helpers'
import path from 'path'
import Builder from '../lib/builder'
import BuildState from '../lib/build-state'
describe('Builder', () => {
let builder, fixturesPath, filePath, logFilePath, fdbFilePath, state, jobState
beforeEach(() => {
builder = new Builder()
fixturesPath = cloneFixtures()
filePath = path.join(fixturesPath, 'file.tex')
logFilePath = path.join(fixturesPath, 'file.log')
fdbFilePath = path.join(fixturesPath, 'file.fdb_latexmk')
state = new BuildState(filePath)
state.setOutputDirectory('')
jobState = state.getJobStates()[0]
})
describe('constructPath', () => {
it('reads `latex.texPath` as configured', () => {
spyOn(atom.config, 'get').andReturn()
builder.constructPath()
expect(atom.config.get).toHaveBeenCalledWith('latex.texPath')
})
it('uses platform default when `latex.texPath` is not configured', () => {
const defaultTexPath = '/foo/bar'
const expectedPath = [defaultTexPath, process.env.PATH].join(path.delimiter)
atom.config.set('latex.texPath', '')
spyOn(builder, 'defaultTexPath').andReturn(defaultTexPath)
const constructedPath = builder.constructPath()
expect(constructedPath).toBe(expectedPath)
})
it('replaces surrounded $PATH with process.env.PATH', () => {
const texPath = '/foo:$PATH:/bar'
const expectedPath = texPath.replace('$PATH', process.env.PATH)
atom.config.set('latex.texPath', texPath)
const constructedPath = builder.constructPath()
expect(constructedPath).toBe(expectedPath)
})
it('replaces leading $PATH with process.env.PATH', () => {
const texPath = '$PATH:/bar'
const expectedPath = texPath.replace('$PATH', process.env.PATH)
atom.config.set('latex.texPath', texPath)
const constructedPath = builder.constructPath()
expect(constructedPath).toBe(expectedPath)
})
it('replaces trailing $PATH with process.env.PATH', () => {
const texPath = '/foo:$PATH'
const expectedPath = texPath.replace('$PATH', process.env.PATH)
atom.config.set('latex.texPath', texPath)
const constructedPath = builder.constructPath()
expect(constructedPath).toBe(expectedPath)
})
it('prepends process.env.PATH with texPath', () => {
const texPath = '/foo'
const expectedPath = [texPath, process.env.PATH].join(path.delimiter)
atom.config.set('latex.texPath', texPath)
const constructedPath = builder.constructPath()
expect(constructedPath).toBe(expectedPath)
})
})
describe('parseLogFile', () => {
let logParser
beforeEach(() => {
logParser = jasmine.createSpyObj('MockLogParser', ['parse'])
spyOn(builder, 'getLogParser').andReturn(logParser)
})
it('resolves the associated log file path by invoking @resolveLogFilePath', () => {
spyOn(builder, 'resolveLogFilePath').andReturn('foo.log')
builder.parseLogFile(jobState)
expect(builder.resolveLogFilePath).toHaveBeenCalledWith(jobState)
})
it('does not attempt parse if passed a file path that does not exist', () => {
state.setFilePath('/foo/bar/quux.tex')
builder.parseLogFile(jobState)
expect(logParser.parse).not.toHaveBeenCalled()
})
it('attempts to parse the resolved log file', () => {
builder.parseLogFile(jobState)
expect(builder.getLogParser).toHaveBeenCalledWith(logFilePath, filePath)
expect(logParser.parse).toHaveBeenCalled()
})
})
describe('parseFdbFile', () => {
let fdbParser
beforeEach(() => {
fdbParser = jasmine.createSpyObj('MockFdbParser', ['parse'])
spyOn(builder, 'getFdbParser').andReturn(fdbParser)
})
it('resolves the associated fdb file path by invoking @resolveFdbFilePath', () => {
spyOn(builder, 'resolveFdbFilePath').andReturn('foo.fdb_latexmk')
builder.parseFdbFile(jobState)
expect(builder.resolveFdbFilePath).toHaveBeenCalledWith(jobState)
})
it('does not attempt parse if passed a file path that does not exist', () => {
state.setFilePath('/foo/bar/quux.tex')
builder.parseFdbFile(jobState)
expect(fdbParser.parse).not.toHaveBeenCalled()
})
it('attempts to parse the resolved fdb file', () => {
builder.parseFdbFile(jobState)
expect(builder.getFdbParser).toHaveBeenCalledWith(fdbFilePath)
expect(fdbParser.parse).toHaveBeenCalled()
})
})
describe('parseLogAndFdbFiles', () => {
it('verifies that the correct output file is selected when using various latexmk modes', () => {
const switches = [
{ name: 'pdf', format: 'pdf' },
{ name: 'pdfdvi', format: 'pdf' },
{ name: 'pdfps', format: 'pdf' },
{ name: 'ps', format: 'ps' },
{ name: 'dvi', format: 'dvi' }]
state.setOutputDirectory('log-parse')
for (const { name, format } of switches) {
state.setJobNames([`file-${name}`])
jobState = state.getJobStates()[0]
builder.parseLogAndFdbFiles(jobState)
expect(path.basename(jobState.getOutputFilePath())).toBe(`${jobState.getJobName()}.${format}`,
`Select ${format} file when using -${name} switch.`)
}
})
})
})