Skip to content

Commit 5cc8703

Browse files
committed
chore(unit tests): WIP tests
1 parent 3100402 commit 5cc8703

File tree

2 files changed

+59
-92
lines changed

2 files changed

+59
-92
lines changed

test/index_tests.js

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const tap = require('tap');
22
const rewire = require("rewire");
33
const _ = require('lodash');
44
const fs = require('fs-extra');
5+
const get = require('../core/lib/get');
56

67
const util = require('./util/test_utils.js');
78
const entry = rewire('../core/index');
@@ -22,7 +23,7 @@ const uiBuilderMock = function () {
2223

2324
const fsMock = {
2425
outputFileSync: function (path, content) { /* INTENTIONAL NOOP */},
25-
readJSONSync: function(path, encoding) {
26+
readJSONSync: function (path, encoding) {
2627
return fs.readJSONSync(path, encoding);
2728
},
2829
removeSync: function (path) { fs.removeSync(path); },
@@ -44,25 +45,63 @@ tap.test('getDefaultConfig - should return the default config object', function
4445
test.end();
4546
});
4647

47-
tap.test('buildPatterns - should replace data link even when pattern parameter present', function (test) {
48+
tap.test('buildPatterns', function () {
4849
//arrange
49-
test.plan(2);
5050

5151
var patternExporterMock = {
5252
/*
53-
In this test, we actually take advantage of the pattern export functionality post-build to inspect what
53+
In this suite, we actually take advantage of the pattern export functionality post-build to inspect what
5454
the contents of the patterns look like. This, coupled with a mocking of fs and the ui_builder, allow us to focus
5555
only on the order of events within build.
5656
*/
5757
export_patterns: function (patternlab) {
58-
var pattern = _.find(patternlab.patterns, (p) => {
59-
return p.patternPartial === 'test-paramParent';
58+
59+
tap.test('replace data link even when pattern parameter present', function (test) {
60+
var pattern = get('test-paramParent', patternlab);
61+
test.equals(util.sanitized(pattern.extendedTemplate), '<div class="foo"> <a href="{{url}}">Cool Dude</a> </div>', 'partial inclusion completes');
62+
test.equals(pattern.patternPartialCode.indexOf('00-test-00-foo.rendered.html') > -1, true, 'data link should be replaced properly');
63+
test.end();
64+
});
65+
66+
tap.test('parameter hunter finds partials with their own parameters and renders them too', function (test) {
67+
var pattern = get('test-c', patternlab);
68+
test.equals(util.sanitized(pattern.extendedTemplate), util.sanitized(`<b>c</b>
69+
<b>b</b>
70+
<i>b!</i>
71+
<b>a</b>
72+
<i>a!</i>`));
73+
test.end();
74+
});
75+
76+
tap.test('parameter hunter finds and extends templates with mixed parameter and global data', function (test) {
77+
var pattern = get('test-sticky-comment', patternlab);
78+
test.equals(util.sanitized(pattern.patternPartialCode), util.sanitized(`<h1>Bar</h1><p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>`));
79+
test.end();
6080
});
6181

62-
//assert
63-
test.equals(util.sanitized(pattern.extendedTemplate), '<div class="foo"> <a href="{{url}}">Cool Dude</a> </div>', 'partial inclusion completes');
64-
test.equals(pattern.patternPartialCode.indexOf('00-test-00-foo.rendered.html') > -1, true, 'data link should be replaced properly');
65-
test.end();
82+
tap.test('parameter hunter parses parameters with unquoted keys and unquoted values', function (test) {
83+
var pattern = get('test-sticky-comment', patternlab);
84+
test.equals(util.sanitized(pattern.patternPartialCode), util.sanitized(`<h1>Bar</h1><p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>`));
85+
test.end();
86+
});
87+
88+
89+
90+
////////////// FAILING /////////////////
91+
92+
tap.test('parameter hunter finds and extends templates with verbose partials', function (test) {
93+
var pattern = get('test-sticky-comment-verbose', patternlab);
94+
test.equals(util.sanitized(pattern.patternPartialCode), util.sanitized(`<h1></h1><p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>`));
95+
test.end();
96+
});
97+
98+
tap.test('parameter hunter finds and extends templates with fully-pathed partials', function (test) {
99+
var pattern = get('test-sticky-comment-full', patternlab);
100+
test.equals(util.sanitized(pattern.patternPartialCode), util.sanitized(`<h1></h1><p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>`));
101+
test.end();
102+
});
103+
104+
66105
}
67106
};
68107

@@ -74,5 +113,11 @@ tap.test('buildPatterns - should replace data link even when pattern parameter p
74113
var pl = new entry(testConfig);
75114

76115
//act
77-
return pl.build({cleanPublic: true});
116+
return pl.build({
117+
cleanPublic: true,
118+
data: {
119+
foo: 'Bar',
120+
description: 'Baz'
121+
}
122+
});
78123
});

test/parameter_hunter_tests.js

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -39,85 +39,7 @@ tap.test('parameter hunter finds and extends templates', function (test) {
3939
}).catch(test.threw);
4040
});
4141

42-
tap.only('parameter hunter finds partials with their own parameters and renders them too', function (test) {
43-
//arrange
44-
const pl = util.fakePatternLab(testPatternsPath);
45-
46-
var aPatternPath = path.join('00-test', '539-a.mustache');
47-
var aPattern = loadPattern(aPatternPath, pl);
48-
49-
var bPatternPath = path.join('00-test', '539-b.mustache');
50-
var bPattern = loadPattern(bPatternPath, pl);
51-
52-
var cPatternPath = path.join('00-test', '539-c.mustache');
53-
var cPattern = loadPattern(cPatternPath, pl);
54-
55-
var p1 = processIterative(aPattern, pl);
56-
var p2 = processIterative(bPattern, pl);
57-
var p3 = processIterative(cPattern, pl);
58-
var p4 = parameter_hunter.find_parameters(cPattern, pl);
59-
60-
Promise.all([p1, p2, p3, p4]).then(() => {
61-
62-
//act
63-
// parameter_hunter.find_parameters(bPattern, pl).then(() => {
64-
// //assert
65-
// test.equals(util.sanitized(bPattern.extendedTemplate),
66-
// util.sanitized(`<b>b</b>
67-
// {{ #b }}
68-
// <i>b!</i>
69-
// {{ /b }}
70-
// <b>a</b>
71-
// <i>a!</i>`));
72-
// test.end();
73-
// });
74-
// });
75-
76-
77-
//act
78-
parameter_hunter.find_parameters(cPattern, pl).then(() => {
79-
//assert
80-
test.equals(util.sanitized(cPattern.extendedTemplate),
81-
util.sanitized(`<b>c</b>
82-
<b>b</b>
83-
<i>b!</i>
84-
<b>a</b>
85-
<i>a!</i>`));
86-
test.end();
87-
});
88-
});
89-
});
90-
91-
92-
tap.test('parameter hunter finds and extends templates with mixed parameter and global data', function (test) {
93-
//arrange
94-
const pl = util.fakePatternLab(testPatternsPath, {
95-
data: {
96-
foo: 'Bar',
97-
description: 'Baz'
98-
}
99-
});
100-
101-
var commentPath = path.join('00-test', 'comment.mustache');
102-
var commentPattern = loadPattern(commentPath, pl);
103-
104-
var testPatternPath = path.join('00-test', 'sticky-comment.mustache');
105-
var testPattern = loadPattern(testPatternPath, pl);
106-
107-
var p1 = processIterative(commentPattern, pl);
108-
var p2 = processIterative(testPattern, pl);
109-
110-
Promise.all([p1, p2]).then(() => {
111-
//act
112-
parameter_hunter.find_parameters(testPattern, pl).then(() => {
113-
//assert
114-
test.equals(util.sanitized(testPattern.extendedTemplate), util.sanitized('<h1>Bar</h1><p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>'));
115-
test.end();
116-
});
117-
});
118-
});
119-
120-
tap.test('parameter hunter finds and extends templates with verbose partials', function (test) {
42+
tap.only('parameter hunter finds and extends templates with verbose partials', function (test) {
12143
//arrange
12244
const pl = util.fakePatternLab(testPatternsPath);
12345

@@ -136,8 +58,8 @@ tap.test('parameter hunter finds and extends templates with verbose partials', f
13658
//assert
13759
test.equals(util.sanitized(testPattern.extendedTemplate), util.sanitized('<h1></h1><p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>'));
13860
test.end();
139-
});
140-
});
61+
}).catch(test.threw);
62+
}).catch(test.threw);
14163
});
14264

14365
tap.test('parameter hunter finds and extends templates with fully-pathed partials', function(test) {

0 commit comments

Comments
 (0)