Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 2c04ac1

Browse files
committed
Beef up all the unit tests -- use the new oPattern factories rather than
faking oPatterns with incomplete object literals. This is a nice way to do it because it gives us a more accurate model of what happens at runtime, but also because we now really need oPatterns to be able to detect PatternEngines based on their file extensions for accurate testing.
1 parent b37e5d7 commit 2c04ac1

File tree

4 files changed

+221
-194
lines changed

4 files changed

+221
-194
lines changed

test/lineage_hunter_tests.js

Lines changed: 36 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,34 @@
22
"use strict";
33

44
var lh = require('../builder/lineage_hunter');
5+
var of = require('../builder/object_factory');
6+
var extend = require('util')._extend;
7+
8+
// fake pattern creators
9+
function createFakeEmptyErrorPattern() {
10+
return new of.oPattern(
11+
'/home/fakeuser/pl/source/_patterns/01-molecules/01-toast/00-error.mustache', // abspath
12+
'01-molecules\\01-toast', // subdir
13+
'00-error.mustache', // filename,
14+
null // data
15+
);
16+
}
517

618
exports['lineage hunter '] = {
719
'test lineage hunter finds lineage' : function(test){
820

921
//setup current pattern from what we would have during execution
10-
var currentPattern = {
11-
"name": "02-organisms-00-global-00-header",
12-
"subdir": "02-organisms\\00-global",
13-
"filename": "00-header.mustache",
14-
"data": null,
22+
var currentPattern = new of.oPattern(
23+
'/home/fakeuser/pl/source/_patterns/02-organisms/00-global/00-header.mustache', // abspath
24+
'02-organisms\\00-global', // subdir
25+
'00-header.mustache', // filename,
26+
null // data
27+
);
28+
extend(currentPattern, {
1529
"template": "<!-- Begin .header -->\r\n<header class=\"header cf\" role=\"banner\">\r\n\t{{> atoms-logo }}\r\n\t<a href=\"#\" class=\"nav-toggle nav-toggle-search icon-search\"><span class=\"is-vishidden\">Search</span></a>\r\n\t<a href=\"#\" class=\"nav-toggle nav-toggle-menu icon-menu\"><span class=\"is-vishidden\">Menu</span></a>\r\n\t{{> molecules-primary-nav }}\r\n\t{{> molecules-search }}\r\n</header>\r\n<!-- End .header -->\r\n",
16-
"patternPartial": "<!-- Begin .header -->\r\n<header class=\"header cf\" role=\"banner\">\r\n<a href=\"/\"><img src=\"../../images/logo.png\" class=\"logo\" alt=\"Logo Alt Text\" /></a>\t<a href=\"#\" class=\"nav-toggle nav-toggle-search icon-search\"><span class=\"is-vishidden\">Search</span></a>\r\n\t<a href=\"#\" class=\"nav-toggle nav-toggle-menu icon-menu\"><span class=\"is-vishidden\">Menu</span></a>\r\n<nav id=\"nav\" class=\"nav\">\r\n\t<ul>\r\n\t\t<li><a href=\"#\">Home</a></li>\r\n\t\t<li><a href=\"#\">About</a></li>\r\n\t\t<li><a href=\"#\">Blog</a></li>\r\n\t\t<li><a href=\"#\">Contact</a></li>\r\n\t</ul>\r\n</nav><!--end .nav-->\r\n<form action=\"#\" method=\"post\" class=\"inline-form search-form\"> \r\n <fieldset>\r\n\t <legend class=\"is-vishidden\">Search</legend>\r\n\t <label for=\"search-field\" class=\"is-vishidden\">Search</label>\r\n\t <input type=\"search\" placeholder=\"Search\" id=\"search-field\" class=\"search-field\" />\r\n\t <button class=\"search-submit\">\r\n\t \t<span class=\"icon-search\" aria-hidden=\"true\"></span>\r\n\t \t<span class=\"is-vishidden\">Search</span>\r\n\t </button>\r\n </fieldset>\r\n</form></header>\r\n<!-- End .header -->\r\n",
17-
"patternName": "header",
18-
"patternLink": "02-organisms-00-global-00-header/02-organisms-00-global-00-header.html",
19-
"patternGroup": "organisms",
20-
"patternSubGroup": "organisms\\00-global",
21-
"flatPatternPath": "02-organisms\\00-global",
22-
"patternState": "",
23-
"lineage": [],
24-
"lineageIndex": [],
25-
"lineageR": [],
26-
"lineageRIndex": []
27-
};
30+
"patternPartial": "<!-- Begin .header -->\r\n<header class=\"header cf\" role=\"banner\">\r\n<a href=\"/\"><img src=\"../../images/logo.png\" class=\"logo\" alt=\"Logo Alt Text\" /></a>\t<a href=\"#\" class=\"nav-toggle nav-toggle-search icon-search\"><span class=\"is-vishidden\">Search</span></a>\r\n\t<a href=\"#\" class=\"nav-toggle nav-toggle-menu icon-menu\"><span class=\"is-vishidden\">Menu</span></a>\r\n<nav id=\"nav\" class=\"nav\">\r\n\t<ul>\r\n\t\t<li><a href=\"#\">Home</a></li>\r\n\t\t<li><a href=\"#\">About</a></li>\r\n\t\t<li><a href=\"#\">Blog</a></li>\r\n\t\t<li><a href=\"#\">Contact</a></li>\r\n\t</ul>\r\n</nav><!--end .nav-->\r\n<form action=\"#\" method=\"post\" class=\"inline-form search-form\"> \r\n <fieldset>\r\n\t <legend class=\"is-vishidden\">Search</legend>\r\n\t <label for=\"search-field\" class=\"is-vishidden\">Search</label>\r\n\t <input type=\"search\" placeholder=\"Search\" id=\"search-field\" class=\"search-field\" />\r\n\t <button class=\"search-submit\">\r\n\t \t<span class=\"icon-search\" aria-hidden=\"true\"></span>\r\n\t \t<span class=\"is-vishidden\">Search</span>\r\n\t </button>\r\n </fieldset>\r\n</form></header>\r\n<!-- End .header -->\r\n"
31+
});
32+
2833
var patternlab = {
2934
patterns: [
3035
{
@@ -97,24 +102,12 @@
97102

98103
'test lineage hunter finds lineage with spaced pattern parameters' : function(test){
99104
//setup current pattern from what we would have during execution
100-
var currentPattern = {
101-
"name": "01-molecules-01-toast-00-error",
102-
"subdir": "01-molecules\\01-toast",
103-
"filename": "00-error.mustache",
104-
"data": null,
105+
var currentPattern = createFakeEmptyErrorPattern();
106+
extend(currentPattern, {
105107
"template": "{{> atoms-error(message: 'That\'s no moon...') }}",
106-
"patternPartial": "{{> atoms-error(message: 'That\'s no moon...') }}",
107-
"patternName": "error",
108-
"patternLink": "01-molecules-01-toast-00-error/01-molecules-01-toast-00-error.html",
109-
"patternGroup": "molecules",
110-
"patternSubGroup": "molecules\\01-toast",
111-
"flatPatternPath": "01-molecules\\01-toast",
112-
"patternState": "",
113-
"lineage": [],
114-
"lineageIndex": [],
115-
"lineageR": [],
116-
"lineageRIndex": []
117-
};
108+
"patternPartial": "{{> atoms-error(message: 'That\'s no moon...') }}"
109+
});
110+
118111
var patternlab = {
119112
patterns: [
120113
{
@@ -149,24 +142,12 @@
149142

150143
'test lineage hunter finds lineage with unspaced pattern parameters' : function(test){
151144
//setup current pattern from what we would have during execution
152-
var currentPattern = {
153-
"name": "01-molecules-01-toast-00-error",
154-
"subdir": "01-molecules\\01-toast",
155-
"filename": "00-error.mustache",
156-
"data": null,
145+
var currentPattern = createFakeEmptyErrorPattern();
146+
extend(currentPattern, {
157147
"template": "{{>atoms-error(message: 'That\'s no moon...')}}",
158148
"patternPartial": "{{>atoms-error(message: 'That\'s no moon...')}}",
159-
"patternName": "error",
160-
"patternLink": "01-molecules-01-toast-00-error/01-molecules-01-toast-00-error.html",
161-
"patternGroup": "molecules",
162-
"patternSubGroup": "molecules\\01-toast",
163-
"flatPatternPath": "01-molecules\\01-toast",
164-
"patternState": "",
165-
"lineage": [],
166-
"lineageIndex": [],
167-
"lineageR": [],
168-
"lineageRIndex": []
169-
};
149+
});
150+
170151
var patternlab = {
171152
patterns: [
172153
{
@@ -203,24 +184,11 @@
203184

204185
'test lineage hunter does not apply lineage twice' : function(test){
205186
//setup current pattern from what we would have during execution
206-
var currentPattern = {
207-
"name": "01-molecules-01-toast-00-error",
208-
"subdir": "01-molecules\\01-toast",
209-
"filename": "00-error.mustache",
210-
"data": null,
187+
var currentPattern = createFakeEmptyErrorPattern();
188+
extend(currentPattern, {
211189
"template": "{{>atoms-error(message: 'That\'s no moon...')}}",
212-
"patternPartial": "{{>atoms-error(message: 'That\'s no moon...')}}",
213-
"patternName": "error",
214-
"patternLink": "01-molecules-01-toast-00-error/01-molecules-01-toast-00-error.html",
215-
"patternGroup": "molecules",
216-
"patternSubGroup": "molecules\\01-toast",
217-
"flatPatternPath": "01-molecules\\01-toast",
218-
"patternState": "",
219-
"lineage": [],
220-
"lineageIndex": [],
221-
"lineageR": [],
222-
"lineageRIndex": []
223-
};
190+
"patternPartial": "{{>atoms-error(message: 'That\'s no moon...')}}"
191+
});
224192
var patternlab = {
225193
patterns: [
226194
{
@@ -254,7 +222,7 @@
254222
test.equals(JSON.parse(patternlab.patterns[0].lineageR).lineagePattern, 'molecules-error');
255223

256224
test.done();
257-
},
225+
}
258226

259227

260228
};

test/list_item_hunter_tests.js

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,31 @@
22
"use strict";
33

44
var lih = require('../builder/list_item_hunter');
5+
var of = require('../builder/object_factory');
6+
var extend = require('util')._extend;
7+
8+
// fake pattern creators
9+
function createFakeListPattern(customProps) {
10+
var inputs = {
11+
abspath: '/home/fakeuser/pl/source/_patterns/01-molecules/01-lists/00-list.mustache',
12+
subdir: '01-molecules\\01-lists',
13+
filename: '00-list.mustache',
14+
data: {}
15+
};
16+
var pattern = new of.oPattern(inputs.abspath, inputs.subdir, inputs.filename, inputs.data);
17+
18+
return extend(pattern, customProps);
19+
}
520

621
exports['list_item_hunter'] = {
722
'process_list_item_partials finds and outputs basic repeating blocks' : function(test){
823
//arrange
924
//setup current pattern from what we would have during execution
10-
var currentPattern = {
11-
"template": "{{#listItems.two}}{{ title }}{{/listItems.two}}",
12-
"extendedTemplate" : "{{#listItems.two}}{{ title }}{{/listItems.two}}",
13-
"key": "test-patternName",
14-
"jsonFileData" : {}
15-
};
25+
var currentPattern = createFakeListPattern({
26+
"template": "{{#listItems.two}}{{ title }}{{/listItems.two}}",
27+
"extendedTemplate": "{{#listItems.two}}{{ title }}{{/listItems.two}}",
28+
"key": "test-patternName"
29+
});
1630

1731
var patternlab = {
1832
"listitems": {
@@ -51,12 +65,11 @@
5165
'process_list_item_partials listitems with lowercase name' : function(test){
5266
//arrange
5367
//setup current pattern from what we would have during execution
54-
var currentPattern = {
55-
"template": "{{#listitems.two}}{{ title }}{{/listitems.two}}",
56-
"extendedTemplate" : "{{#listitems.two}}{{ title }}{{/listitems.two}}",
57-
"key": "test-patternName",
58-
"jsonFileData" : {}
59-
};
68+
var currentPattern = createFakeListPattern({
69+
"template": "{{#listitems.two}}{{ title }}{{/listitems.two}}",
70+
"extendedTemplate" : "{{#listitems.two}}{{ title }}{{/listitems.two}}",
71+
"key": "test-patternName"
72+
});
6073

6174
var patternlab = {
6275
"listitems": {
@@ -95,12 +108,11 @@
95108
'process_list_item_partials finds partials and outputs repeated renders' : function(test){
96109
//arrange
97110
//setup current pattern from what we would have during execution
98-
var currentPattern = {
99-
"template": "{{#listItems.two}}{{ title }}{{/listItems.two}}",
100-
"extendedTemplate" : "{{#listItems.two}}{{> test-simple }}{{/listItems.two}}",
101-
"key": "test-patternName",
102-
"jsonFileData" : {}
103-
};
111+
var currentPattern = createFakeListPattern({
112+
"template": "{{#listItems.two}}{{ title }}{{/listItems.two}}",
113+
"extendedTemplate" : "{{#listItems.two}}{{> test-simple }}{{/listItems.two}}",
114+
"key": "test-patternName"
115+
});
104116

105117
var patternlab = {
106118
"listitems": {
@@ -145,19 +157,17 @@
145157
},
146158

147159
'process_list_item_partials finds verbose partials and outputs repeated renders' : function(test){
148-
var pattern1 = {
160+
var pattern1 = createFakeListPattern({
149161
"template": "{{#listItems.one}}{{> 00-test/00-foo }}{{/listItems.one}}",
150162
"extendedTemplate" : "{{#listItems.one}}{{> 00-test/00-foo }}{{/listItems.one}}",
151-
"key": "test-patternName1",
152-
"jsonFileData" : {}
153-
};
163+
"key": "test-patternName1"
164+
});
154165

155-
var pattern2 = {
166+
var pattern2 = createFakeListPattern({
156167
"template": "{{#listItems.two}}{{> 00-test/01-bar.mustache }}{{/listItems.two}}",
157168
"extendedTemplate" : "{{#listItems.two}}{{> 00-test/01-bar.mustache }}{{/listItems.two}}",
158-
"key": "test-patternName2",
159-
"jsonFileData" : {}
160-
};
169+
"key": "test-patternName2"
170+
});
161171

162172
var patternlab = {
163173
"listitems": {
@@ -181,20 +191,16 @@
181191
},
182192
"config": {"debug": false},
183193
"patterns": [
184-
{
185-
"template": "{{ title }}",
186-
"extendedTemplate" : "{{ title }}",
187-
"subdir": "00-test",
188-
"fileName": "00-foo",
189-
"jsonFileData" : {}
190-
},
191-
{
192-
"template": "{{ title }}",
193-
"extendedTemplate" : "{{ title }}",
194-
"subdir": "00-test",
195-
"fileName": "01-bar",
196-
"jsonFileData" : {}
197-
}
194+
of.oPattern.create(null, "00-test", "00-foo", null, {
195+
"template": "{{ title }}",
196+
"extendedTemplate": "{{ title }}",
197+
"jsonFileData": {}
198+
}),
199+
of.oPattern.create(null, "00-test", "00-bar", null, {
200+
"template": "{{ title }}",
201+
"extendedTemplate": "{{ title }}",
202+
"jsonFileData": {}
203+
})
198204
]
199205
};
200206

0 commit comments

Comments
 (0)