File tree Expand file tree Collapse file tree 4 files changed +84
-6
lines changed Expand file tree Collapse file tree 4 files changed +84
-6
lines changed Original file line number Diff line number Diff line change @@ -373,16 +373,16 @@ const patternlab_module = function(config) {
373
373
374
374
this . events . on ( 'patternlab-pattern-change' , ( ) => {
375
375
if ( ! patternlab . isBusy ) {
376
- options . cleanPublic = false ;
377
376
return this . build ( options ) ;
378
377
}
379
378
return Promise . resolve ( ) ;
380
379
} ) ;
381
380
382
381
this . events . on ( 'patternlab-global-change' , ( ) => {
383
382
if ( ! patternlab . isBusy ) {
384
- options . cleanPublic = true ; //rebuild everything
385
- return this . build ( options ) ;
383
+ return this . build (
384
+ Object . assign ( { } , options , { cleanPublic : true } ) // rebuild everything
385
+ ) ;
386
386
}
387
387
return Promise . resolve ( ) ;
388
388
} ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
- const fs = require ( 'fs-extra' ) ;
3
2
const CompileState = require ( './object_factory' ) . CompileState ;
4
3
4
+ //this is mocked in unit tests
5
+ let fs = require ( 'fs-extra' ) ; //eslint-disable-line prefer-const
6
+
5
7
/**
6
8
* For detecting changed patterns.
7
9
* @constructor
@@ -73,7 +75,7 @@ ChangesHunter.prototype = {
73
75
* @param {string } file
74
76
*/
75
77
checkLastModified : function ( currentPattern , file ) {
76
- if ( file ) {
78
+ if ( file && fs . pathExistsSync ( file ) ) {
77
79
try {
78
80
const stat = fs . statSync ( file ) ;
79
81
Original file line number Diff line number Diff line change @@ -178,7 +178,15 @@ module.exports = function(relPath, patternlab) {
178
178
//find any pattern parameters that may be in the current pattern
179
179
currentPattern . parameteredPartials = currentPattern . findPartialsWithPatternParameters ( ) ;
180
180
181
- [ templatePath , jsonFilename , listJsonFileName ] . forEach ( file => {
181
+ [
182
+ templatePath ,
183
+ `${ jsonFilename } .json` ,
184
+ `${ jsonFilename } .yml` ,
185
+ `${ jsonFilename } .yaml` ,
186
+ `${ listJsonFileName } .json` ,
187
+ `${ listJsonFileName } .yml` ,
188
+ `${ listJsonFileName } .yaml` ,
189
+ ] . forEach ( file => {
182
190
changes_hunter . checkLastModified ( currentPattern , file ) ;
183
191
} ) ;
184
192
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const tap = require ( 'tap' ) ;
4
+ const rewire = require ( 'rewire' ) ;
5
+
6
+ const ch = rewire ( '../core/lib/changes_hunter' ) ;
7
+
8
+ const fsMock = {
9
+ statSync : function ( ) {
10
+ return {
11
+ mtime : {
12
+ getTime : ( ) => {
13
+ console . log ( '????' ) ;
14
+ return 100 ;
15
+ } ,
16
+ } ,
17
+ } ;
18
+ } ,
19
+ pathExistsSync : ( ) => {
20
+ return true ;
21
+ } ,
22
+ } ;
23
+
24
+ //set our mocks in place of usual require()
25
+ ch . __set__ ( {
26
+ fs : fsMock ,
27
+ } ) ;
28
+
29
+ const changes_hunter = new ch ( ) ;
30
+
31
+ tap . test ( 'checkLastModified - sets lastModified to fileTime ' , function ( test ) {
32
+ //arrange
33
+ const mockPattern = { lastModified : 0 } ;
34
+ //act
35
+ changes_hunter . checkLastModified ( mockPattern , { } ) ;
36
+
37
+ //assert
38
+ test . equals ( mockPattern . lastModified , 100 ) ;
39
+ test . end ( ) ;
40
+ } ) ;
41
+
42
+ tap . test (
43
+ 'checkLastModified - does not alter pattern if file not found' ,
44
+ function ( test ) {
45
+ //arrange
46
+ const mockPattern = { lastModified : 1010 } ;
47
+ //act
48
+ changes_hunter . checkLastModified ( mockPattern , null ) ;
49
+
50
+ //assert
51
+ test . equals ( mockPattern . lastModified , 1010 ) ;
52
+ test . end ( ) ;
53
+ }
54
+ ) ;
55
+
56
+ tap . test (
57
+ 'checkLastModified - uses pattern.lastModified if greater than file time' ,
58
+ function ( test ) {
59
+ //arrange
60
+ const mockPattern = { lastModified : 101 } ;
61
+ //act
62
+ changes_hunter . checkLastModified ( mockPattern , { } ) ;
63
+
64
+ //assert
65
+ test . equals ( mockPattern . lastModified , 101 ) ;
66
+ test . end ( ) ;
67
+ }
68
+ ) ;
You can’t perform that action at this time.
0 commit comments