@@ -14,6 +14,9 @@ function emptyPatternLab() {
14
14
}
15
15
}
16
16
17
+ const patterns_dir = './test/files/_patterns' ;
18
+ const public_dir = './test/public' ;
19
+
17
20
tap . test ( 'process_pattern_recursive recursively includes partials' , function ( test ) {
18
21
19
22
//tests inclusion of partial that will be discovered by diveSync later in iteration than parent
@@ -23,8 +26,6 @@ tap.test('process_pattern_recursive recursively includes partials', function(tes
23
26
var pa = require ( '../core/lib/pattern_assembler' ) ;
24
27
var plMain = require ( '../core/lib/patternlab' ) ;
25
28
var pattern_assembler = new pa ( ) ;
26
- var patterns_dir = './test/files/_patterns' ;
27
- var public_dir = './test/public' ;
28
29
var patternlab = emptyPatternLab ( ) ;
29
30
patternlab . config = fs . readJSONSync ( './patternlab-config.json' ) ;
30
31
patternlab . config . paths . source . patterns = patterns_dir ;
@@ -662,14 +663,24 @@ tap.test('addPattern - adds pattern template to patternlab partial object if ext
662
663
test . end ( ) ;
663
664
} ) ;
664
665
665
- tap . test ( 'findModifiedPatterns - finds patterns modified since a given date' , function ( test ) {
666
+ tap . test ( 'markModifiedPatterns - finds patterns modified since a given date' , function ( test ) {
667
+ const fs = require ( 'fs-extra' ) ;
668
+ // test/myModule.test.js
669
+ var rewire = require ( "rewire" ) ;
670
+
671
+ var pattern_assembler_mock = rewire ( "../core/lib/pattern_assembler" ) ;
672
+ var fsMock = {
673
+ readFileSync : function ( path , encoding , cb ) {
674
+ return "" ;
675
+ }
676
+ } ;
677
+ pattern_assembler_mock . __set__ ( "fs" , fsMock ) ;
666
678
//arrange
667
- var pattern_assembler = new pa ( ) ;
679
+ var pattern_assembler = new pattern_assembler_mock ( ) ;
668
680
var patternlab = emptyPatternLab ( ) ;
669
- patternlab . partials = { } ;
670
- patternlab . data = { link : { } } ;
671
- patternlab . config = { debug : false } ;
672
- patternlab . config . outputFileSuffixes = { rendered : '' } ;
681
+ patternlab . config = fs . readJSONSync ( './patternlab-config.json' ) ;
682
+ patternlab . config . paths . public . patterns = public_dir + "/patterns" ;
683
+ patternlab . config . outputFileSuffixes = { rendered : '' , markupOnly : '.markup-only' } ;
673
684
674
685
var pattern = new Pattern ( '00-test/01-bar.mustache' ) ;
675
686
pattern . extendedTemplate = undefined ;
@@ -681,17 +692,19 @@ tap.test('findModifiedPatterns - finds patterns modified since a given date', fu
681
692
patternlab . patterns = [ pattern ] ;
682
693
683
694
var lastCompilationRun = new Date ( "2016-01-01" ) . getTime ( ) ;
684
- var p = pattern_assembler . find_modified_patterns ( lastCompilationRun , patternlab ) ;
695
+ var modifiedOrNot = pattern_assembler . mark_modified_patterns ( lastCompilationRun , patternlab ) ;
685
696
686
- test . same ( p . length , 1 , "The pattern was modified after the last compilation" ) ;
697
+ test . same ( modifiedOrNot . modified . length , 1 , "The pattern was modified after the last compilation" ) ;
687
698
699
+ // Reset the compile state as it was previously set by pattern_assembler.mark_modified_patterns
700
+ pattern . compileState = CompileState . CLEAN ;
688
701
lastCompilationRun = new Date ( "2016-12-31" ) . getTime ( ) ;
689
- p = pattern_assembler . find_modified_patterns ( lastCompilationRun , patternlab ) ;
690
- test . same ( p . length , 0 , "Pattern was already compiled and hasn't been modified since last compile" ) ;
702
+ modifiedOrNot = pattern_assembler . mark_modified_patterns ( lastCompilationRun , patternlab ) ;
703
+ test . same ( modifiedOrNot . notModified . length , 1 , "Pattern was already compiled and hasn't been modified since last compile" ) ;
691
704
test . end ( ) ;
692
- } )
705
+ } ) ;
693
706
694
- tap . test ( 'findModifiedPatterns - finds patterns when modification date is missing' , function ( test ) {
707
+ tap . test ( 'markModifiedPatterns - finds patterns when modification date is missing' , function ( test ) {
695
708
//arrange
696
709
var pattern_assembler = new pa ( ) ;
697
710
var patternlab = emptyPatternLab ( ) ;
@@ -706,13 +719,13 @@ tap.test('findModifiedPatterns - finds patterns when modification date is missin
706
719
pattern . lastModified = undefined ;
707
720
patternlab . patterns = [ pattern ] ;
708
721
709
- let p = pattern_assembler . find_modified_patterns ( 1000 , patternlab ) ;
710
- test . same ( p . length , 1 ) ;
722
+ let p = pattern_assembler . mark_modified_patterns ( 1000 , patternlab ) ;
723
+ test . same ( p . modified . length , 1 ) ;
711
724
test . end ( ) ;
712
725
} ) ;
713
726
714
727
// This is the case when we want to force recompilation
715
- tap . test ( 'findModifiedPatterns - finds patterns via compile state' , function ( test ) {
728
+ tap . test ( 'markModifiedPatterns - finds patterns via compile state' , function ( test ) {
716
729
//arrange
717
730
var pattern_assembler = new pa ( ) ;
718
731
var patternlab = emptyPatternLab ( ) ;
@@ -728,8 +741,8 @@ tap.test('findModifiedPatterns - finds patterns via compile state', function(tes
728
741
pattern . compileState = CompileState . NEEDS_REBUILD ;
729
742
patternlab . patterns = [ pattern ] ;
730
743
731
- let p = pattern_assembler . find_modified_patterns ( 1000 , patternlab ) ;
732
- test . same ( p . length , 1 ) ;
744
+ let p = pattern_assembler . mark_modified_patterns ( 1000 , patternlab ) ;
745
+ test . same ( p . modified . length , 1 ) ;
733
746
test . end ( ) ;
734
747
} ) ;
735
748
0 commit comments