1 |
|
2 |
|
3 | import 'babel-polyfill'
|
4 |
|
5 | import Pweave from '../../src/Rules/Pweave'
|
6 | import { initializeRule } from '../helpers'
|
7 |
|
8 | import type { RuleDefinition } from '../helpers'
|
9 |
|
10 | async function initialize ({
|
11 | RuleClass = Pweave,
|
12 | filePath = 'file-types/PythonNoWeb.Pnw',
|
13 | parameters = [{
|
14 | filePath: 'PythonNoWeb.Pnw'
|
15 | }],
|
16 | ...rest }: RuleDefinition = {}) {
|
17 | return initializeRule({ RuleClass, parameters, ...rest })
|
18 | }
|
19 |
|
20 | describe('Pweave', () => {
|
21 | describe('constructCommand', () => {
|
22 | it('returns correct arguments and command options for Pnw file.', async (done) => {
|
23 | const { rule } = await initialize({
|
24 | options: {
|
25 | pweaveCacheDirectory: 'cache',
|
26 | pweaveFigureDirectory: 'figures'
|
27 | }
|
28 | })
|
29 |
|
30 | expect(rule.constructCommand()).toEqual({
|
31 | args: [
|
32 | 'pweave',
|
33 | '--format=tex',
|
34 | '--output={{$JOB.tex}}',
|
35 | '{{$FILEPATH_0}}'
|
36 | ],
|
37 | cd: '$ROOTDIR',
|
38 | severity: 'error',
|
39 | outputs: ['$JOB.tex']
|
40 | })
|
41 |
|
42 | done()
|
43 | })
|
44 |
|
45 | it('returns correct arguments and command options for Pnw file when pweaveOutputPath is set.', async (done) => {
|
46 | const { rule } = await initialize({
|
47 | options: {
|
48 | pweaveCacheDirectory: 'cache',
|
49 | pweaveFigureDirectory: 'figures',
|
50 | pweaveOutputPath: 'foo.tex'
|
51 | }
|
52 | })
|
53 |
|
54 | expect(rule.constructCommand()).toEqual({
|
55 | args: [
|
56 | 'pweave',
|
57 | '--format=tex',
|
58 | '--output={{foo.tex}}',
|
59 | '{{$FILEPATH_0}}'
|
60 | ],
|
61 | cd: '$ROOTDIR',
|
62 | severity: 'error',
|
63 | outputs: ['foo.tex']
|
64 | })
|
65 |
|
66 | done()
|
67 | })
|
68 | })
|
69 |
|
70 | it('adds --cache-directory to args when pweaveCacheDirectory is set.', async (done) => {
|
71 | const { rule } = await initialize({
|
72 | options: { pweaveCacheDirectory: 'foo' }
|
73 | })
|
74 |
|
75 | expect(rule.constructCommand().args).toContain('--cache-directory={{foo}}')
|
76 |
|
77 | done()
|
78 | })
|
79 |
|
80 | it('adds --documentation-mode to args when pweaveDocumentationMode is set.', async (done) => {
|
81 | const { rule } = await initialize({
|
82 | options: { pweaveDocumentationMode: true }
|
83 | })
|
84 |
|
85 | expect(rule.constructCommand().args).toContain('--documentation-mode')
|
86 |
|
87 | done()
|
88 | })
|
89 |
|
90 | it('adds --figure-directory to args when pweaveFigureDirectory is set.', async (done) => {
|
91 | const { rule } = await initialize({
|
92 | options: { pweaveFigureDirectory: 'foo' }
|
93 | })
|
94 |
|
95 | expect(rule.constructCommand().args).toContain('--figure-directory={{foo}}')
|
96 |
|
97 | done()
|
98 | })
|
99 |
|
100 | it('adds --format to args when pweaveOutputFormat is set.', async (done) => {
|
101 | const { rule } = await initialize({
|
102 | options: { pweaveOutputFormat: 'texminted' }
|
103 | })
|
104 |
|
105 | expect(rule.constructCommand().args).toContain('--format=texminted')
|
106 |
|
107 | done()
|
108 | })
|
109 | })
|