UNPKG

2.23 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import DviToPdf from '../../src/Rules/DviToPdf'
6import { initializeRule } from '../helpers'
7
8import type { RuleDefinition } from '../helpers'
9
10async function initialize ({
11 RuleClass = DviToPdf,
12 parameters = [{
13 filePath: 'DeviceIndependentFile.dvi'
14 }],
15 ...rest }: RuleDefinition = {}) {
16 return initializeRule({ RuleClass, parameters, ...rest })
17}
18
19describe('DviToPdf', () => {
20 describe('appliesToParameters', () => {
21 it('returns true if outputFormat is \'pdf\'', async (done) => {
22 const { rule, options } = await initialize({
23 options: { outputFormat: 'pdf' }
24 })
25
26 expect(await DviToPdf.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
27
28 done()
29 })
30
31 it('returns false if outputFormat is not \'pdf\'', async (done) => {
32 const { rule, options } = await initialize({
33 options: { outputFormat: 'ps' }
34 })
35
36 expect(await DviToPdf.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
37
38 done()
39 })
40
41 it('returns false if outputFormat is \'pdf\' but intermediatePostScript is set.', async (done) => {
42 const { rule, options } = await initialize({
43 options: { outputFormat: 'pdf', intermediatePostScript: true }
44 })
45
46 expect(await DviToPdf.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
47
48 done()
49 })
50 })
51
52 describe('constructCommand', () => {
53 it('returns correct arguments and command options for dvi file.', async (done) => {
54 const { rule } = await initialize()
55
56 expect(rule.constructCommand()).toEqual({
57 args: [
58 'xdvipdfmx',
59 '-o',
60 '{{$DIR_0/$NAME_0.pdf}}',
61 '{{$FILEPATH_0}}'
62 ],
63 cd: '$ROOTDIR',
64 severity: 'error',
65 outputs: ['$DIR_0/$NAME_0.pdf']
66 })
67
68 done()
69 })
70
71 it('uses correct dvipdf program when dviToPdfEngine is set.', async (done) => {
72 const { rule } = await initialize({
73 options: { dviToPdfEngine: 'dvipdfm' }
74 })
75
76 expect(rule.constructCommand().args[0]).toEqual('dvipdfm')
77
78 done()
79 })
80 })
81})