UNPKG

3.22 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import CheckForMissingBuildRule from '../../src/Rules/CheckForMissingBuildRule'
6import Rule from '../../src/Rule'
7import { initializeRule } from '../helpers'
8
9import type { RuleDefinition } from '../helpers'
10
11async function initialize ({
12 RuleClass = CheckForMissingBuildRule,
13 parameters = [{
14 filePath: 'LaTeX_article.tex'
15 }],
16 ...rest }: RuleDefinition = {}) {
17 return initializeRule({ RuleClass, parameters, ...rest })
18}
19
20describe('CheckForMissingBuildRule', () => {
21 describe('appliesToParameters', () => {
22 it('returns true if the parameter is the main source file.', async (done) => {
23 const { dicy, rule, options } = await initialize({
24 parameters: [{
25 filePath: 'LaTeX_article.tex'
26 }]
27 })
28
29 expect(await CheckForMissingBuildRule.appliesToParameters(dicy.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
30
31 done()
32 })
33
34 it('returns false if the parameter is not the main source file.', async (done) => {
35 const { dicy, rule, options } = await initialize({
36 parameters: [{
37 filePath: 'LaTeX_standalone.tex'
38 }]
39 })
40
41 expect(await CheckForMissingBuildRule.appliesToParameters(dicy.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
42
43 done()
44 })
45 })
46
47 describe('run', () => {
48 it('run succeeds and does not log any error messages when build rules are present.', async (done) => {
49 const { dicy, rule, options } = await initialize()
50 const file = await dicy.getFile('LaTeX_article.tex')
51 const otherRule = new Rule(rule.state, 'build', 'execute', options, file)
52
53 dicy.addRule(otherRule)
54
55 expect(await rule.run()).toBe(true)
56 expect(rule.log).not.toHaveBeenCalled()
57
58 done()
59 })
60
61 it('run fails and logs an error messages when build rules are not present.', async (done) => {
62 const { rule } = await initialize()
63
64 expect(await rule.run()).toBe(false)
65 expect(rule.log).toHaveBeenCalledWith({
66 severity: 'error',
67 name: 'DiCy',
68 text: 'No applicable build rule was found for main source file `LaTeX_article.tex`.'
69 })
70
71 done()
72 })
73
74 it('run succeeds and does not any log error messages when targets are available when a jobname is set.', async (done) => {
75 const { dicy, rule, options } = await initialize({
76 options: { jobName: 'foo' }
77 })
78 const file = await dicy.getFile('LaTeX_article.tex')
79 const otherRule = new Rule(rule.state, 'build', 'execute', options, file)
80
81 dicy.addRule(otherRule)
82
83 expect(await rule.run()).toBe(true)
84 expect(rule.log).not.toHaveBeenCalled()
85
86 done()
87 })
88
89 it('run fails and logs an error messages when targets are not available when a jobname is set.', async (done) => {
90 const { rule } = await initialize({
91 options: { jobName: 'foo' }
92 })
93
94 expect(await rule.run()).toBe(false)
95 expect(rule.log).toHaveBeenCalledWith({
96 severity: 'error',
97 name: 'DiCy',
98 text: 'No applicable build rule was found for main source file `LaTeX_article.tex` with job name of `foo`.'
99 })
100
101 done()
102 })
103 })
104})