@@ -14,6 +14,9 @@ function emptyPatternLab() {
1414 }
1515}
1616
17+ const patterns_dir = './test/files/_patterns' ;
18+ const public_dir = './test/public' ;
19+
1720tap . test ( 'process_pattern_recursive recursively includes partials' , function ( test ) {
1821
1922 //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
2326 var pa = require ( '../core/lib/pattern_assembler' ) ;
2427 var plMain = require ( '../core/lib/patternlab' ) ;
2528 var pattern_assembler = new pa ( ) ;
26- var patterns_dir = './test/files/_patterns' ;
27- var public_dir = './test/public' ;
2829 var patternlab = emptyPatternLab ( ) ;
2930 patternlab . config = fs . readJSONSync ( './patternlab-config.json' ) ;
3031 patternlab . config . paths . source . patterns = patterns_dir ;
@@ -662,14 +663,24 @@ tap.test('addPattern - adds pattern template to patternlab partial object if ext
662663 test . end ( ) ;
663664} ) ;
664665
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 ) ;
666678 //arrange
667- var pattern_assembler = new pa ( ) ;
679+ var pattern_assembler = new pattern_assembler_mock ( ) ;
668680 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' } ;
673684
674685 var pattern = new Pattern ( '00-test/01-bar.mustache' ) ;
675686 pattern . extendedTemplate = undefined ;
@@ -681,17 +692,19 @@ tap.test('findModifiedPatterns - finds patterns modified since a given date', fu
681692 patternlab . patterns = [ pattern ] ;
682693
683694 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 ) ;
685696
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" ) ;
687698
699+ // Reset the compile state as it was previously set by pattern_assembler.mark_modified_patterns
700+ pattern . compileState = CompileState . CLEAN ;
688701 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" ) ;
691704 test . end ( ) ;
692- } )
705+ } ) ;
693706
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 ) {
695708 //arrange
696709 var pattern_assembler = new pa ( ) ;
697710 var patternlab = emptyPatternLab ( ) ;
@@ -706,13 +719,13 @@ tap.test('findModifiedPatterns - finds patterns when modification date is missin
706719 pattern . lastModified = undefined ;
707720 patternlab . patterns = [ pattern ] ;
708721
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 ) ;
711724 test . end ( ) ;
712725} ) ;
713726
714727// 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 ) {
716729 //arrange
717730 var pattern_assembler = new pa ( ) ;
718731 var patternlab = emptyPatternLab ( ) ;
@@ -728,8 +741,8 @@ tap.test('findModifiedPatterns - finds patterns via compile state', function(tes
728741 pattern . compileState = CompileState . NEEDS_REBUILD ;
729742 patternlab . patterns = [ pattern ] ;
730743
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 ) ;
733746 test . end ( ) ;
734747} ) ;
735748
0 commit comments