forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatternlab_tests.js
More file actions
73 lines (59 loc) · 2.25 KB
/
patternlab_tests.js
File metadata and controls
73 lines (59 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
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 data_dir = './test/files/_data/';
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);
});