UNPKG

1.9 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import Knitr from '../../src/Rules/Knitr'
6import { initializeRule } from '../helpers'
7
8import type { RuleDefinition } from '../helpers'
9
10async function initialize ({
11 RuleClass = Knitr,
12 filePath = 'file-types/RNoWeb.Rnw',
13 parameters = [{
14 filePath: 'RNoWeb.Rnw'
15 }],
16 ...rest }: RuleDefinition = {}) {
17 return initializeRule({ RuleClass, filePath, parameters, ...rest })
18}
19
20describe('Knitr', () => {
21 describe('constructCommand', () => {
22 it('returns correct arguments and command options for Rnw file.', async (done) => {
23 const { rule } = await initialize()
24
25 expect(rule.constructCommand()).toEqual({
26 args: ['Rscript', '-e', 'library(knitr);opts_knit$set(concordance=TRUE);knit(\'RNoWeb.Rnw\',\'RNoWeb.tex\')'],
27 cd: '$ROOTDIR',
28 severity: 'error',
29 outputs: ['$JOB.tex', '$JOB-concordance.tex']
30 })
31
32 done()
33 })
34
35 it('returns correct arguments and command options for Rnw file when concordance is off.', async (done) => {
36 const { rule } = await initialize({
37 options: { knitrConcordance: false }
38 })
39
40 expect(rule.constructCommand()).toEqual({
41 args: ['Rscript', '-e', 'library(knitr);knit(\'RNoWeb.Rnw\',\'RNoWeb.tex\')'],
42 cd: '$ROOTDIR',
43 severity: 'error',
44 outputs: ['$JOB.tex']
45 })
46
47 done()
48 })
49
50 it('returns correct arguments and command options for Rnw file when knitrOutputPath is set.', async (done) => {
51 const { rule } = await initialize({
52 options: { knitrOutputPath: 'foo.tex' }
53 })
54
55 expect(rule.constructCommand()).toEqual({
56 args: ['Rscript', '-e', 'library(knitr);opts_knit$set(concordance=TRUE);knit(\'RNoWeb.Rnw\',\'foo.tex\')'],
57 cd: '$ROOTDIR',
58 severity: 'error',
59 outputs: ['foo.tex', 'foo-concordance.tex']
60 })
61
62 done()
63 })
64 })
65})