Skip to content

Commit b380391

Browse files
committed
finish coverage for data link issue
closes #653
1 parent 05c38b6 commit b380391

File tree

5 files changed

+53
-35
lines changed

5 files changed

+53
-35
lines changed

core/lib/patternlab.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var diveSync = require('diveSync'),
2424
jsonCopy = require('./json_copy'),
2525
ui = require('./ui_builder'),
2626
ui_builder = new ui(),
27+
pe = require('./pattern_exporter'),
28+
pattern_exporter = new pe(),
2729
PatternGraph = require('./pattern_graph').PatternGraph;
2830

2931
//register our log events
@@ -150,7 +152,6 @@ var patternlab_engine = function (config) {
150152
'use strict';
151153

152154
var pa = require('./pattern_assembler'),
153-
pe = require('./pattern_exporter'),
154155
lh = require('./lineage_hunter'),
155156
sm = require('./starterkit_manager'),
156157
Pattern = require('./object_factory').Pattern,
@@ -160,7 +161,6 @@ var patternlab_engine = function (config) {
160161
patternlab.engines = patternEngines;
161162

162163
var pattern_assembler = new pa(),
163-
pattern_exporter = new pe(),
164164
lineage_hunter = new lh();
165165

166166
patternlab.package = fs.readJSONSync(path.resolve(__dirname, '../../package.json'));
@@ -581,7 +581,6 @@ var patternlab_engine = function (config) {
581581
}
582582
}
583583

584-
585584
//render all patterns last, so lineageR works
586585
patternsToBuild.forEach(pattern => renderSinglePattern(pattern, head));
587586

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="{{styleModifier}}">
2-
{{> test-nav }}
2+
{{> test-link }}
33
</div>
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
{
2-
"brad" : {
3-
"url" : "link.twitter-brad"
4-
},
5-
"dave" : {
6-
"url" : "link.twitter-dave"
7-
},
8-
"brian" : {
9-
"url" : "link.twitter-brian"
10-
}
2+
"url" : "link.test-foo"
113
}

test/patternlab_tests.js

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,73 @@
11
'use strict';
22

3-
var tap = require('tap');
4-
var rewire = require("rewire");
3+
const tap = require('tap');
4+
const rewire = require("rewire");
5+
const _ = require('lodash');
6+
const fs = require('fs-extra');
57
var config = require('./util/patternlab-config.json');
68

79
var plEngineModule = rewire('../core/lib/patternlab');
810

911
//set up a global mocks - we don't want to be writing/rendering any files right now
10-
var uiBuilderMock = {
12+
const uiBuilderMock = {
1113
buildFrontend: function (patternlab) { }
1214
};
1315

16+
const fsMock = {
17+
outputFileSync: function (path, content) { /* INTENTIONAL NOOP */},
18+
readJSONSync: function(path, encoding) {
19+
return fs.readJSONSync(path, encoding);
20+
},
21+
removeSync: function(path) { fs.removeSync(path); },
22+
emptyDirSync: function(path) { fs.emptyDirSync(path); },
23+
readFileSync: function(path, encoding) { return fs.readFileSync(path, encoding); },
24+
}
25+
1426
//set our mocks in place of usual require()
1527
plEngineModule.__set__({
16-
'ui_builder': uiBuilderMock
28+
'ui_builder': uiBuilderMock,
29+
'fs': fsMock
1730
});
1831

19-
var pl = new plEngineModule(config);
20-
32+
tap.test('buildPatternData - should merge all JSON files in the data folder except listitems', function(test){
33+
var data_dir = './test/files/_data/';
2134

22-
// tap.test('buildPatternData - should merge all JSON files in the data folder except listitems', function(test){
23-
// var fs = require('fs-extra');
24-
// var plMain = require('../core/lib/patternlab');
25-
// var data_dir = './test/files/_data/';
26-
//
27-
// var dataResult = plMain.build_pattern_data(data_dir, fs);
28-
// test.equals(dataResult.data, "test");
29-
// test.equals(dataResult.foo, "bar");
30-
// test.equals(dataResult.test_list_item, undefined);
31-
// test.end();
32-
// });
35+
var dataResult = plEngineModule.build_pattern_data(data_dir, fs);
36+
test.equals(dataResult.data, "test");
37+
test.equals(dataResult.foo, "bar");
38+
test.equals(dataResult.test_list_item, undefined);
39+
test.end();
40+
});
3341

3442
tap.test('buildPatterns - should replace data link even when pattern parameter present', function(test) {
3543
//arrange
3644

45+
var patternExporterMock = {
46+
/*
47+
In this test, we actually take advantage of the pattern export functionality post-build to inspect what
48+
the contents of the patterns look like. This, coupled with a mocking of fs and the ui_builder, allow us to focus
49+
only on the order of events within build.
50+
*/
51+
export_patterns: function (patternlab) {
52+
var pattern = _.find(patternlab.patterns, (pattern) => {
53+
return pattern.patternPartial === 'test-paramParent';
54+
});
55+
//assert
56+
test.equals(pattern.patternPartialCode.indexOf('00-test-00-foo.rendered.html') > -1, true, 'data link should be replaced properly');
57+
}
58+
};
59+
60+
plEngineModule.__set__({
61+
'pattern_exporter': patternExporterMock
62+
});
63+
64+
config.patternExportPatternPartials = ['test-paramParent'];
65+
var pl = new plEngineModule(config);
66+
3767
//act
3868
pl.build(function() {
39-
40-
test.equals(1,1);
4169
test.end();
42-
4370
}, true);
4471

45-
//assert
4672

4773
});

test/util/patternlab-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@
6262
"markupOnly": ".markup-only"
6363
},
6464
"cleanOutputHtml": true,
65-
"exportToGraphViz": false
65+
"exportToGraphViz": false,
66+
"cleanPublic": true
6667
}

0 commit comments

Comments
 (0)