forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkModifiedPatterns_tests.js
More file actions
119 lines (98 loc) · 3.49 KB
/
markModifiedPatterns_tests.js
File metadata and controls
119 lines (98 loc) · 3.49 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
var tap = require('tap');
var rewire = require('rewire');
var Pattern = require('../core/lib/object_factory').Pattern;
var CompileState = require('../core/lib/object_factory').CompileState;
var PatternGraph = require('../core/lib/pattern_graph').PatternGraph;
var engineLoader = require('../core/lib/pattern_engines');
const markModifiedPatterns = rewire('../core/lib/markModifiedPatterns');
const config = require('./util/patternlab-config.json');
const fsMock = {
readFileSync: function(path, encoding, cb) {
return '';
},
};
function emptyPatternLab() {
return {
graph: PatternGraph.empty(),
};
}
const public_dir = './test/public';
tap.only(
'markModifiedPatterns - finds patterns modified since a given date',
function(test) {
//arrange
markModifiedPatterns.__set__('fs', fsMock);
var patternlab = emptyPatternLab();
patternlab.config = config;
patternlab.config.paths.public.patterns = public_dir + '/patterns';
patternlab.config.outputFileSuffixes = {
rendered: '',
markupOnly: '.markup-only',
};
var pattern = new Pattern('00-test/01-bar.mustache');
pattern.extendedTemplate = undefined;
pattern.template = 'bar';
pattern.lastModified = new Date('2016-01-31').getTime();
// Initially the compileState is clean,
// but we would change this after detecting that the file was modified
pattern.compileState = CompileState.CLEAN;
patternlab.patterns = [pattern];
var lastCompilationRun = new Date('2016-01-01').getTime();
var modifiedOrNot = markModifiedPatterns(lastCompilationRun, patternlab);
test.same(
modifiedOrNot.modified.length,
1,
'The pattern was modified after the last compilation'
);
// Reset the compile state as it was previously set by pattern_assembler.mark_modified_patterns
pattern.compileState = CompileState.CLEAN;
lastCompilationRun = new Date('2016-12-31').getTime();
modifiedOrNot = markModifiedPatterns(lastCompilationRun, patternlab);
test.same(
modifiedOrNot.notModified.length,
1,
"Pattern was already compiled and hasn't been modified since last compile"
);
test.end();
}
);
tap.test(
'markModifiedPatterns - finds patterns when modification date is missing',
function(test) {
//arrange
var patternlab = emptyPatternLab();
patternlab.partials = {};
patternlab.data = { link: {} };
patternlab.config = { logLevel: 'quiet' };
patternlab.config.outputFileSuffixes = { rendered: '' };
var pattern = new Pattern('00-test/01-bar.mustache');
pattern.extendedTemplate = undefined;
pattern.template = 'bar';
pattern.lastModified = undefined;
patternlab.patterns = [pattern];
let p = markModifiedPatterns(1000, patternlab);
test.same(p.modified.length, 1);
test.end();
}
);
// This is the case when we want to force recompilation
tap.test('markModifiedPatterns - finds patterns via compile state', function(
test
) {
//arrange
var patternlab = emptyPatternLab();
patternlab.partials = {};
patternlab.data = { link: {} };
patternlab.config = { logLevel: 'quiet' };
patternlab.config.outputFileSuffixes = { rendered: '' };
var pattern = new Pattern('00-test/01-bar.mustache');
pattern.extendedTemplate = undefined;
pattern.template = 'bar';
pattern.lastModified = 100000;
pattern.compileState = CompileState.NEEDS_REBUILD;
patternlab.patterns = [pattern];
let p = markModifiedPatterns(1000, patternlab);
test.same(p.modified.length, 1);
test.end();
});