UNPKG

2.66 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import Biber from '../../src/Rules/Biber'
6import { initializeRule } from '../helpers'
7
8import type { RuleDefinition } from '../helpers'
9
10async function initialize ({
11 RuleClass = Biber,
12 parameters = [{
13 filePath: 'BiberControlFile.bcf'
14 }],
15 ...rest }: RuleDefinition = {}) {
16 return initializeRule({ RuleClass, parameters, ...rest })
17}
18
19describe('Biber', () => {
20 describe('getFileActions', () => {
21 it('returns a run action for a control file.', async (done) => {
22 const { rule } = await initialize()
23 const file = await rule.getFile('BiberControlFile.bcf')
24
25 if (file) {
26 const actions = await rule.getFileActions(file)
27 expect(actions).toEqual(['run'])
28 }
29
30 done()
31 })
32
33 it('returns a updateDependencies action for a biber log file.', async (done) => {
34 const { rule } = await initialize()
35 const file = await rule.getFile('BiberControlFile.blg-ParsedBiberLog')
36
37 if (file) {
38 const actions = await rule.getFileActions(file)
39 expect(actions).toEqual(['updateDependencies'])
40 }
41
42 done()
43 })
44
45 it('returns a run action for a latex log file if a rerun biber instruction is found.', async (done) => {
46 const { rule } = await initialize()
47 const file = await rule.getFile('LaTeX.log-ParsedLaTeXLog')
48
49 if (file) {
50 file.value = {
51 messages: [{
52 type: 'info',
53 text: 'Please (re)run Biber on the file: BiberControlFile and rerun LaTeX afterwards.'
54 }]
55 }
56 const actions = await rule.getFileActions(file)
57 expect(actions).toEqual(['run'])
58 }
59
60 done()
61 })
62
63 it('returns a no actions for a latex log file if no rerun biber instruction is found.', async (done) => {
64 const { rule } = await initialize()
65 const file = await rule.getFile('LaTeX.log-ParsedLaTeXLog')
66
67 if (file) {
68 file.value = {
69 messages: [{
70 type: 'info',
71 text: 'Please (re)run Biber on the file: foo and rerun LaTeX afterwards.'
72 }]
73 }
74 const actions = await rule.getFileActions(file)
75 expect(actions).toEqual([])
76 }
77
78 done()
79 })
80 })
81
82 describe('constructCommand', () => {
83 it('returns correct arguments and command options for control file file.', async (done) => {
84 const { rule } = await initialize()
85
86 expect(rule.constructCommand()).toEqual({
87 args: ['biber', '{{$FILEPATH_0}}'],
88 cd: '$ROOTDIR',
89 severity: 'error',
90 outputs: ['$DIR_0/$NAME_0.bbl', '$DIR_0/$NAME_0.blg']
91 })
92
93 done()
94 })
95 })
96})