diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js
index f8e99e96b..3a5c03f75 100644
--- a/core/lib/patternlab.js
+++ b/core/lib/patternlab.js
@@ -22,6 +22,10 @@ var diveSync = require('diveSync'),
packageInfo = require('../../package.json'),
plutils = require('./utilities'),
jsonCopy = require('./json_copy'),
+ ui = require('./ui_builder'),
+ ui_builder = new ui(),
+ pe = require('./pattern_exporter'),
+ pattern_exporter = new pe(),
PatternGraph = require('./pattern_graph').PatternGraph;
//register our log events
@@ -148,9 +152,7 @@ var patternlab_engine = function (config) {
'use strict';
var pa = require('./pattern_assembler'),
- pe = require('./pattern_exporter'),
lh = require('./lineage_hunter'),
- ui = require('./ui_builder'),
sm = require('./starterkit_manager'),
Pattern = require('./object_factory').Pattern,
CompileState = require('./object_factory').CompileState,
@@ -159,7 +161,6 @@ var patternlab_engine = function (config) {
patternlab.engines = patternEngines;
var pattern_assembler = new pa(),
- pattern_exporter = new pe(),
lineage_hunter = new lh();
patternlab.package = fs.readJSONSync(path.resolve(__dirname, '../../package.json'));
@@ -580,7 +581,6 @@ var patternlab_engine = function (config) {
}
}
-
//render all patterns last, so lineageR works
patternsToBuild.forEach(pattern => renderSinglePattern(pattern, head));
@@ -606,7 +606,7 @@ var patternlab_engine = function (config) {
}
patternlab.isBusy = true;
buildPatterns(deletePatternDir);
- new ui().buildFrontend(patternlab);
+ ui_builder.buildFrontend(patternlab);
printDebug();
patternlab.isBusy = false;
callback();
diff --git a/test/files/_data/listitems.json b/test/files/_data/listitems.json
index efcd8b4f1..3187a7a8d 100644
--- a/test/files/_data/listitems.json
+++ b/test/files/_data/listitems.json
@@ -1,4 +1,11 @@
{
- "test_list_item" : "izzn thizzle"
+ "1": {
+ "title": "Nullizzle shizznit velizzle, hizzle, suscipit own yo', gravida vizzle, arcu."
+ },
+ "2": {
+ "title": "Veggies sunt bona vobis, proinde vos postulo"
+ },
+ "3": {
+ "title": "Bacon ipsum dolor sit amet turducken strip steak beef ribs shank"
+ }
}
-
diff --git a/test/files/_meta/_00-head.mustache b/test/files/_meta/_00-head.mustache
new file mode 100644
index 000000000..e69de29bb
diff --git a/test/files/_meta/_01-foot.mustache b/test/files/_meta/_01-foot.mustache
new file mode 100644
index 000000000..e69de29bb
diff --git a/test/files/_patterns/00-test/paramMiddle.mustache b/test/files/_patterns/00-test/paramMiddle.mustache
new file mode 100644
index 000000000..31169fb7e
--- /dev/null
+++ b/test/files/_patterns/00-test/paramMiddle.mustache
@@ -0,0 +1,3 @@
+
+ {{> test-link }}
+
diff --git a/test/files/_patterns/00-test/paramParent.json b/test/files/_patterns/00-test/paramParent.json
new file mode 100644
index 000000000..d913cc535
--- /dev/null
+++ b/test/files/_patterns/00-test/paramParent.json
@@ -0,0 +1,3 @@
+{
+ "url" : "link.test-foo"
+}
diff --git a/test/files/_patterns/00-test/paramParent.mustache b/test/files/_patterns/00-test/paramParent.mustache
new file mode 100644
index 000000000..bf4e84562
--- /dev/null
+++ b/test/files/_patterns/00-test/paramParent.mustache
@@ -0,0 +1 @@
+{{> test-paramMiddle(styleModifier: "foo") }}
diff --git a/test/files/partials/general-footer.mustache b/test/files/partials/general-footer.mustache
new file mode 100644
index 000000000..e69de29bb
diff --git a/test/files/partials/general-header.mustache b/test/files/partials/general-header.mustache
new file mode 100644
index 000000000..e69de29bb
diff --git a/test/files/partials/patternSection.mustache b/test/files/partials/patternSection.mustache
new file mode 100644
index 000000000..e69de29bb
diff --git a/test/files/partials/patternSectionSubtype.mustache b/test/files/partials/patternSectionSubtype.mustache
new file mode 100644
index 000000000..e69de29bb
diff --git a/test/files/viewall.mustache b/test/files/viewall.mustache
new file mode 100644
index 000000000..e69de29bb
diff --git a/test/patternlab_tests.js b/test/patternlab_tests.js
index 84eb81d2f..0ea02de9b 100644
--- a/test/patternlab_tests.js
+++ b/test/patternlab_tests.js
@@ -1,15 +1,73 @@
'use strict';
-var tap = require('tap');
+const tap = require('tap');
+const rewire = require("rewire");
+const _ = require('lodash');
+const fs = require('fs-extra');
+var config = require('./util/patternlab-config.json');
+
+var plEngineModule = rewire('../core/lib/patternlab');
+
+//set up a global mocks - we don't want to be writing/rendering any files right now
+const uiBuilderMock = {
+ buildFrontend: function (patternlab) { }
+};
+
+const fsMock = {
+ outputFileSync: function (path, content) { /* INTENTIONAL NOOP */},
+ readJSONSync: function(path, encoding) {
+ return fs.readJSONSync(path, encoding);
+ },
+ removeSync: function(path) { fs.removeSync(path); },
+ emptyDirSync: function(path) { fs.emptyDirSync(path); },
+ readFileSync: function(path, encoding) { return fs.readFileSync(path, encoding); },
+}
+
+//set our mocks in place of usual require()
+plEngineModule.__set__({
+ 'ui_builder': uiBuilderMock,
+ 'fs': fsMock
+});
tap.test('buildPatternData - should merge all JSON files in the data folder except listitems', function(test){
- var fs = require('fs-extra');
- var plMain = require('../core/lib/patternlab');
var data_dir = './test/files/_data/';
- var dataResult = plMain.build_pattern_data(data_dir, fs);
+ var dataResult = plEngineModule.build_pattern_data(data_dir, fs);
test.equals(dataResult.data, "test");
test.equals(dataResult.foo, "bar");
test.equals(dataResult.test_list_item, undefined);
test.end();
});
+
+tap.test('buildPatterns - should replace data link even when pattern parameter present', function(test) {
+ //arrange
+
+ var patternExporterMock = {
+ /*
+ In this test, we actually take advantage of the pattern export functionality post-build to inspect what
+ the contents of the patterns look like. This, coupled with a mocking of fs and the ui_builder, allow us to focus
+ only on the order of events within build.
+ */
+ export_patterns: function (patternlab) {
+ var pattern = _.find(patternlab.patterns, (pattern) => {
+ return pattern.patternPartial === 'test-paramParent';
+ });
+ //assert
+ test.equals(pattern.patternPartialCode.indexOf('00-test-00-foo.rendered.html') > -1, true, 'data link should be replaced properly');
+ }
+ };
+
+ plEngineModule.__set__({
+ 'pattern_exporter': patternExporterMock
+ });
+
+ config.patternExportPatternPartials = ['test-paramParent'];
+ var pl = new plEngineModule(config);
+
+ //act
+ pl.build(function() {
+ test.end();
+ }, true);
+
+
+});
diff --git a/test/util/patternlab-config.json b/test/util/patternlab-config.json
new file mode 100644
index 000000000..d13f33508
--- /dev/null
+++ b/test/util/patternlab-config.json
@@ -0,0 +1,67 @@
+{
+ "paths" : {
+ "source" : {
+ "root": "./test/files/",
+ "patterns" : "./test/files/_patterns/",
+ "data" : "./test/files/_data/",
+ "meta": "./test/files/_meta/",
+ "styleguide" : "./test/files/styleguide/",
+ "patternlabFiles" : "./test/files/",
+ "js" : "./test/files/js",
+ "images" : "./test/files/images",
+ "fonts" : "./test/files/fonts",
+ "css" : "./test/files/css/"
+ },
+ "public" : {
+ "root" : "./test/public/",
+ "patterns" : "./test/public/patterns/",
+ "data" : "./test/public/data/",
+ "styleguide" : "./test/public/styleguide/",
+ "js" : "./test/public/js",
+ "images" : "./test/public/images",
+ "fonts" : "./test/public/fonts",
+ "css" : "./test/public/css"
+ }
+ },
+ "styleGuideExcludes": [
+ "templates",
+ "pages"
+ ],
+ "defaultPattern": "all",
+ "ignored-extensions" : ["scss", "DS_Store", "less"],
+ "ignored-directories" : ["scss"],
+ "debug": false,
+ "ishControlsHide": {
+ "s": false,
+ "m": false,
+ "l": false,
+ "full": false,
+ "random": false,
+ "disco": false,
+ "hay": true,
+ "mqs": false,
+ "find": false,
+ "views-all": false,
+ "views-annotations": false,
+ "views-code": false,
+ "views-new": false,
+ "tools-all": false,
+ "tools-docs": false
+ },
+ "ishMinimum": "240",
+ "ishMaximum": "2600",
+ "patternStateCascade": ["inprogress", "inreview", "complete"],
+ "patternStates": {
+ },
+ "patternExportPatternPartials": [],
+ "patternExportDirectory": "./pattern_exports/",
+ "cacheBust": true,
+ "outputFileSuffixes": {
+ "rendered": ".rendered",
+ "rawTemplate": "",
+ "markupOnly": ".markup-only"
+ },
+ "cleanOutputHtml": true,
+ "exportToGraphViz": false,
+ "cleanPublic": true
+}