forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine_underscore_tests.js
More file actions
163 lines (138 loc) · 4.12 KB
/
engine_underscore_tests.js
File metadata and controls
163 lines (138 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
'use strict';
var tap = require('tap');
var path = require('path');
var loadPattern = require('../core/lib/loadPattern');
var PatternGraph = require('../core/lib/pattern_graph').PatternGraph;
var testPatternsPath = path.resolve(
__dirname,
'files',
'_underscore-test-patterns'
);
var eol = require('os').EOL;
// don't run tests unless underscore is installed
var engineLoader = require('../core/lib/pattern_engines');
if (!engineLoader.underscore) {
tap.test('Underscore engine not installed, skipping tests', function(test) {
test.end();
});
return;
}
// fake pattern lab constructor:
// sets up a fake patternlab object, which is needed by the pattern processing
// apparatus.
function fakePatternLab() {
var fpl = {
graph: PatternGraph.empty(),
partials: {},
patterns: [],
footer: '',
header: '',
listitems: {},
data: {
link: {},
},
config: require('../patternlab-config.json'),
package: {},
};
// patch the pattern source so the pattern assembler can correctly determine
// the "subdir"
fpl.config.paths.source.patterns = testPatternsPath;
return fpl;
}
tap.test('hello world underscore pattern renders', function(test) {
test.plan(1);
var patternPath = path.resolve(
testPatternsPath,
'00-atoms',
'00-global',
'00-helloworld.html'
);
// do all the normal processing of the pattern
var patternlab = new fakePatternLab();
const helloWorldPattern = loadPattern(patternPath, patternlab);
return assembler
.process_pattern_iterative(helloWorldPattern, patternlab)
.then(() => {
assembler.process_pattern_recursive(patternPath, patternlab);
test.equals(helloWorldPattern.render(), 'Hello world!' + eol);
});
});
tap.test('underscore partials can render JSON values', function(test) {
test.plan(1);
// pattern paths
var pattern1Path = path.resolve(
testPatternsPath,
'00-atoms',
'00-global',
'00-helloworld-withdata.html'
);
// set up environment
var patternlab = new fakePatternLab(); // environment
// do all the normal processing of the pattern
const helloWorldWithData = loadPattern(pattern1Path, patternlab);
return assembler
.process_pattern_iterative(helloWorldWithData, patternlab)
.then(() => {
assembler.process_pattern_recursive(pattern1Path, patternlab);
// test
test.equals(
helloWorldWithData.render(),
'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol
);
});
});
tap.test(
'findPartial return the ID of the partial, given a whole partial call',
function(test) {
var engineLoader = require('../core/lib/pattern_engines');
var underscoreEngine = engineLoader.underscore;
test.plan(1);
// do all the normal processing of the pattern
// test
test.equals(
underscoreEngine.findPartial(
"<%= _.renderNamedPartial('molecules-details', obj) %>"
),
'molecules-details'
);
test.end();
}
);
tap.test(
'hidden underscore patterns can be called by their nice names',
function(test) {
const util = require('./util/test_utils.js');
//arrange
const testPatternsPath = path.resolve(
__dirname,
'files',
'_underscore-test-patterns'
);
const pl = util.fakePatternLab(testPatternsPath);
var hiddenPatternPath = path.join(
'00-atoms',
'00-global',
'_00-hidden.html'
);
var testPatternPath = path.join(
'00-molecules',
'00-global',
'00-hidden-pattern-tester.html'
);
var hiddenPattern = loadPattern(hiddenPatternPath, pl);
var testPattern = loadPattern(testPatternPath, pl);
return Promise.all([
pattern_assembler.process_pattern_iterative(hiddenPattern, pl),
pattern_assembler.process_pattern_iterative(testPattern, pl),
]).then(() => {
pattern_assembler.process_pattern_recursive(hiddenPatternPath, pl);
pattern_assembler.process_pattern_recursive(testPatternPath, pl);
//act
test.equals(
util.sanitized(testPattern.render()),
util.sanitized("Here's the hidden atom: [I'm the hidden atom\n]\n")
);
test.end();
});
}
);