UNPKG

1.95 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import DviToPs from '../../src/Rules/DviToPs'
6import { initializeRule } from '../helpers'
7
8import type { RuleDefinition } from '../helpers'
9
10async function initialize ({
11 RuleClass = DviToPs,
12 parameters = [{
13 filePath: 'DeviceIndependentFile.dvi'
14 }],
15 ...rest }: RuleDefinition = {}) {
16 return initializeRule({ RuleClass, parameters, ...rest })
17}
18
19describe('DviToPs', () => {
20 describe('appliesToParameters', () => {
21 it('returns true if outputFormat is \'ps\'', async (done) => {
22 const { rule, options } = await initialize({
23 options: { outputFormat: 'ps' }
24 })
25
26 expect(await DviToPs.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
27
28 done()
29 })
30
31 it('returns true if outputFormat is \'pdf\' and intermediatePostScript is set', async (done) => {
32 const { rule, options } = await initialize({
33 options: { outputFormat: 'pdf', intermediatePostScript: true }
34 })
35
36 expect(await DviToPs.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
37
38 done()
39 })
40
41 it('returns false if outputFormat is not \'ps\'', async (done) => {
42 const { rule, options } = await initialize({
43 options: { outputFormat: 'dvi' }
44 })
45
46 expect(await DviToPs.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 'dvips',
59 '-o',
60 '{{$DIR_0/$NAME_0.ps}}',
61 '{{$FILEPATH_0}}'
62 ],
63 cd: '$ROOTDIR',
64 severity: 'error',
65 outputs: ['$DIR_0/$NAME_0.ps']
66 })
67
68 done()
69 })
70 })
71})