|
1 |
| -(function () { |
2 |
| - "use strict"; |
| 1 | +"use strict"; |
3 | 2 |
|
4 |
| - var path = require('path'); |
5 |
| - var pa = require('../core/lib/pattern_assembler'); |
6 |
| - var testPatternsPath = path.resolve(__dirname, 'files', '_underscore-test-patterns'); |
7 |
| - var eol = require('os').EOL; |
| 3 | +var path = require('path'); |
| 4 | +var pa = require('../core/lib/pattern_assembler'); |
| 5 | +var testPatternsPath = path.resolve(__dirname, 'files', '_underscore-test-patterns'); |
| 6 | +var eol = require('os').EOL; |
8 | 7 |
|
9 |
| - try { |
10 |
| - require('underscore'); |
11 |
| - } catch (err) { |
12 |
| - console.log('underscore renderer not installed; skipping tests'); |
13 |
| - return; |
14 |
| - } |
| 8 | +// fake pattern lab constructor: |
| 9 | +// sets up a fake patternlab object, which is needed by the pattern processing |
| 10 | +// apparatus. |
| 11 | +function fakePatternLab() { |
| 12 | + var fpl = { |
| 13 | + partials: {}, |
| 14 | + patterns: [], |
| 15 | + footer: '', |
| 16 | + header: '', |
| 17 | + listitems: {}, |
| 18 | + listItemArray: [], |
| 19 | + data: { |
| 20 | + link: {} |
| 21 | + }, |
| 22 | + config: require('../patternlab-config.json'), |
| 23 | + package: {} |
| 24 | + }; |
15 | 25 |
|
16 |
| - // fake pattern lab constructor: |
17 |
| - // sets up a fake patternlab object, which is needed by the pattern processing |
18 |
| - // apparatus. |
19 |
| - function fakePatternLab() { |
20 |
| - var fpl = { |
21 |
| - partials: {}, |
22 |
| - patterns: [], |
23 |
| - footer: '', |
24 |
| - header: '', |
25 |
| - listitems: {}, |
26 |
| - listItemArray: [], |
27 |
| - data: { |
28 |
| - link: {} |
29 |
| - }, |
30 |
| - config: require('../patternlab-config.json'), |
31 |
| - package: {} |
32 |
| - }; |
| 26 | + // patch the pattern source so the pattern assembler can correctly determine |
| 27 | + // the "subdir" |
| 28 | + fpl.config.paths.source.patterns = testPatternsPath; |
33 | 29 |
|
34 |
| - // patch the pattern source so the pattern assembler can correctly determine |
35 |
| - // the "subdir" |
36 |
| - fpl.config.paths.source.patterns = testPatternsPath; |
| 30 | + return fpl; |
| 31 | +} |
37 | 32 |
|
38 |
| - return fpl; |
39 |
| - } |
| 33 | +exports['engine_underscore'] = { |
| 34 | + 'hello world underscore pattern renders': function (test) { |
| 35 | + test.expect(1); |
40 | 36 |
|
41 |
| - exports['engine_underscore'] = { |
42 |
| - 'hello world underscore pattern renders': function (test) { |
43 |
| - test.expect(1); |
| 37 | + var patternPath = path.resolve( |
| 38 | + testPatternsPath, |
| 39 | + '00-atoms', |
| 40 | + '00-global', |
| 41 | + '00-helloworld.html' |
| 42 | + ); |
44 | 43 |
|
45 |
| - var patternPath = path.resolve( |
46 |
| - testPatternsPath, |
47 |
| - '00-atoms', |
48 |
| - '00-global', |
49 |
| - '00-helloworld.html' |
50 |
| - ); |
| 44 | + // do all the normal processing of the pattern |
| 45 | + var patternlab = new fakePatternLab(); |
| 46 | + var assembler = new pa(); |
| 47 | + var helloWorldPattern = assembler.process_pattern_iterative(patternPath, patternlab); |
| 48 | + assembler.process_pattern_recursive(patternPath, patternlab); |
51 | 49 |
|
52 |
| - // do all the normal processing of the pattern |
53 |
| - var patternlab = new fakePatternLab(); |
54 |
| - var assembler = new pa(); |
55 |
| - var helloWorldPattern = assembler.process_pattern_iterative(patternPath, patternlab); |
56 |
| - assembler.process_pattern_recursive(patternPath, patternlab); |
| 50 | + test.equals(helloWorldPattern.render(), 'Hello world!' + eol); |
| 51 | + test.done(); |
| 52 | + }, |
| 53 | + 'underscore partials can render JSON values': function (test) { |
| 54 | + test.expect(1); |
57 | 55 |
|
58 |
| - test.equals(helloWorldPattern.render(), 'Hello world!' + eol); |
59 |
| - test.done(); |
60 |
| - }, |
61 |
| - 'underscore partials can render JSON values': function (test) { |
62 |
| - test.expect(1); |
| 56 | + // pattern paths |
| 57 | + var pattern1Path = path.resolve( |
| 58 | + testPatternsPath, |
| 59 | + '00-atoms', |
| 60 | + '00-global', |
| 61 | + '00-helloworld-withdata.html' |
| 62 | + ); |
63 | 63 |
|
64 |
| - // pattern paths |
65 |
| - var pattern1Path = path.resolve( |
66 |
| - testPatternsPath, |
67 |
| - '00-atoms', |
68 |
| - '00-global', |
69 |
| - '00-helloworld-withdata.html' |
70 |
| - ); |
| 64 | + // set up environment |
| 65 | + var patternlab = new fakePatternLab(); // environment |
| 66 | + var assembler = new pa(); |
71 | 67 |
|
72 |
| - // set up environment |
73 |
| - var patternlab = new fakePatternLab(); // environment |
74 |
| - var assembler = new pa(); |
| 68 | + // do all the normal processing of the pattern |
| 69 | + var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab); |
| 70 | + assembler.process_pattern_recursive(pattern1Path, patternlab); |
75 | 71 |
|
76 |
| - // do all the normal processing of the pattern |
77 |
| - var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab); |
78 |
| - assembler.process_pattern_recursive(pattern1Path, patternlab); |
| 72 | + // test |
| 73 | + test.equals(helloWorldWithData.render(), 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol); |
| 74 | + test.done(); |
| 75 | + } |
| 76 | +}; |
79 | 77 |
|
80 |
| - // test |
81 |
| - test.equals(helloWorldWithData.render(), 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol); |
82 |
| - test.done(); |
83 |
| - } |
84 |
| - }; |
85 |
| -})(); |
| 78 | + |
| 79 | + |
| 80 | +// don't run these tests unless underscore is installed |
| 81 | +var engineLoader = require('../core/lib/pattern_engines'); |
| 82 | +if (!engineLoader.underscore) { |
| 83 | + console.log("Underscore engine not installed, skipping tests."); |
| 84 | + delete exports.engine_underscore; |
| 85 | +} |
0 commit comments