UNPKG

2.83 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import File from '../../src/File'
6import Rule from '../../src/Rule'
7import ApplyOptions from '../../src/Rules/ApplyOptions'
8import { initializeRule } from '../helpers'
9
10import type { RuleDefinition } from '../helpers'
11
12async function initialize ({ RuleClass = ApplyOptions, ...rest }: RuleDefinition = {}) {
13 return initializeRule({ RuleClass, ...rest })
14}
15
16describe('ApplyOptions', () => {
17 describe('doAssignOptions', () => {
18 it('verifies that high priority configuration overrides low priority configuration.', async (done) => {
19 const { rule } = await initialize()
20 const yaml: ?File = await rule.getResolvedFile('$NAME.yaml-ParsedYAML')
21 const magic: ?File = await rule.getResolvedFile('$BASE-ParsedLaTeXMagic')
22
23 expect(yaml).toBeDefined()
24 expect(magic).toBeDefined()
25
26 if (yaml && magic) {
27 yaml.value = {
28 engine: 'foo',
29 indexStyle: 'baz.ist'
30 }
31 magic.value = {
32 engine: 'bar',
33 outputDirectory: 'gronk'
34 }
35
36 await rule.doAssignOptions()
37
38 expect(rule.state.options.engine).toBe('bar')
39 expect(rule.state.options.indexStyle).toBe('baz.ist')
40 expect(rule.state.options.outputDirectory).toBe('gronk')
41 }
42
43 done()
44 })
45 })
46
47 describe('checkForConfigurationChange', () => {
48 let loadRule: Rule
49 let finalizeRule: Rule
50 let otherRule: Rule
51 let applyOptions: ApplyOptions
52
53 beforeEach(async (done) => {
54 const { dicy, rule } = await initialize()
55 const options = rule.state.getJobOptions()
56
57 loadRule = new Rule(rule.state, 'load', 'execute', options)
58 dicy.addRule(loadRule)
59
60 finalizeRule = new Rule(rule.state, 'load', 'finalize', options)
61 dicy.addRule(finalizeRule)
62
63 otherRule = new Rule(rule.state, 'build', 'execute', options)
64 dicy.addRule(otherRule)
65
66 applyOptions = rule
67
68 done()
69 })
70
71 it('verifies that not changing options does not remove any rules.', () => {
72 applyOptions.checkForConfigurationChange({})
73
74 expect(Array.from(applyOptions.state.rules.keys())).toEqual([
75 loadRule.id,
76 finalizeRule.id,
77 otherRule.id
78 ])
79 })
80
81 it('verifies that setting an option with `noInvalidate` does not remove any rules.', () => {
82 applyOptions.checkForConfigurationChange({ phaseCycles: 20 })
83
84 expect(Array.from(applyOptions.state.rules.keys())).toEqual([
85 loadRule.id,
86 finalizeRule.id,
87 otherRule.id
88 ])
89 })
90
91 it('verifies that setting an option without `noInvalidate` removes appropriate rules.', () => {
92 applyOptions.checkForConfigurationChange({ engine: 'foo' })
93
94 expect(Array.from(applyOptions.state.rules.keys())).toEqual([
95 loadRule.id
96 ])
97 })
98 })
99})