Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 653 integration test #654

Merged
merged 2 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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'));
Expand Down Expand Up @@ -580,7 +581,6 @@ var patternlab_engine = function (config) {
}
}


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

Expand All @@ -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();
Expand Down
11 changes: 9 additions & 2 deletions test/files/_data/listitems.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

Empty file.
Empty file.
3 changes: 3 additions & 0 deletions test/files/_patterns/00-test/paramMiddle.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="{{styleModifier}}">
{{> test-link }}
</div>
3 changes: 3 additions & 0 deletions test/files/_patterns/00-test/paramParent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"url" : "link.test-foo"
}
1 change: 1 addition & 0 deletions test/files/_patterns/00-test/paramParent.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{> test-paramMiddle(styleModifier: "foo") }}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added test/files/viewall.mustache
Empty file.
66 changes: 62 additions & 4 deletions test/patternlab_tests.js
Original file line number Diff line number Diff line change
@@ -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);


});
67 changes: 67 additions & 0 deletions test/util/patternlab-config.json
Original file line number Diff line number Diff line change
@@ -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
}