1
1
"use strict" ;
2
2
3
+ var test = require ( 'tape' ) ;
3
4
var path = require ( 'path' ) ;
4
5
var pa = require ( '../core/lib/pattern_assembler' ) ;
5
6
var testPatternsPath = path . resolve ( __dirname , 'files' , '_underscore-test-patterns' ) ;
6
7
var eol = require ( 'os' ) . EOL ;
7
8
9
+ // don't run tests unless underscore is installed
10
+ var engineLoader = require ( '../core/lib/pattern_engines' ) ;
11
+ if ( ! engineLoader . underscore ) {
12
+ test . only ( 'Underscore engine not installed, skipping tests' , function ( test ) {
13
+ test . end ( ) ;
14
+ } ) ;
15
+ }
16
+
8
17
// fake pattern lab constructor:
9
18
// sets up a fake patternlab object, which is needed by the pattern processing
10
19
// apparatus.
@@ -30,67 +39,64 @@ function fakePatternLab() {
30
39
return fpl ;
31
40
}
32
41
33
- exports [ 'engine_underscore' ] = {
34
- 'hello world underscore pattern renders' : function ( test ) {
35
- test . expect ( 1 ) ;
36
-
37
- var patternPath = path . resolve (
38
- testPatternsPath ,
39
- '00-atoms' ,
40
- '00-global' ,
41
- '00-helloworld.html'
42
- ) ;
43
-
44
- // do all the normal processing of the pattern
45
- var patternlab = new fakePatternLab ( ) ;
46
- var assembler = new pa ( ) ;
47
- var helloWorldPattern = assembler . process_pattern_iterative ( patternPath , patternlab ) ;
48
- assembler . process_pattern_recursive ( patternPath , patternlab ) ;
49
-
50
- test . equals ( helloWorldPattern . render ( ) , 'Hello world!' + eol ) ;
51
- test . done ( ) ;
52
- } ,
53
- 'underscore partials can render JSON values' : function ( test ) {
54
- test . expect ( 1 ) ;
55
-
56
- // pattern paths
57
- var pattern1Path = path . resolve (
58
- testPatternsPath ,
59
- '00-atoms' ,
60
- '00-global' ,
61
- '00-helloworld-withdata.html'
62
- ) ;
63
-
64
- // set up environment
65
- var patternlab = new fakePatternLab ( ) ; // environment
66
- var assembler = new pa ( ) ;
67
-
68
- // do all the normal processing of the pattern
69
- var helloWorldWithData = assembler . process_pattern_iterative ( pattern1Path , patternlab ) ;
70
- assembler . process_pattern_recursive ( pattern1Path , patternlab ) ;
71
-
72
- // test
73
- test . equals ( helloWorldWithData . render ( ) , 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol ) ;
74
- test . done ( ) ;
75
- } ,
76
- 'findPartial return the ID of the partial, given a whole partial call' : function ( test ) {
77
- var engineLoader = require ( '../core/lib/pattern_engines' ) ;
78
- var underscoreEngine = engineLoader . underscore ;
79
-
80
- test . expect ( 1 ) ;
81
-
82
- // do all the normal processing of the pattern
83
- // test
84
- test . equals ( underscoreEngine . findPartial ( "<%= _.renderNamedPartial('molecules-details', obj) %>" ) , 'molecules-details' ) ;
85
- test . done ( ) ;
86
- }
87
- } ;
88
-
89
-
90
-
91
- // don't run these tests unless underscore is installed
92
- var engineLoader = require ( '../core/lib/pattern_engines' ) ;
93
- if ( ! engineLoader . underscore ) {
94
- console . log ( "Underscore engine not installed, skipping tests." ) ;
95
- delete exports . engine_underscore ;
96
- }
42
+ test ( 'hello world underscore pattern renders' , function ( test ) {
43
+ test . plan ( 1 ) ;
44
+
45
+ var patternPath = path . resolve (
46
+ testPatternsPath ,
47
+ '00-atoms' ,
48
+ '00-global' ,
49
+ '00-helloworld.html'
50
+ ) ;
51
+
52
+ // do all the normal processing of the pattern
53
+ var patternlab = new fakePatternLab ( ) ;
54
+ var assembler = new pa ( ) ;
55
+ var helloWorldPattern = assembler . process_pattern_iterative ( patternPath , patternlab ) ;
56
+ //test.comment(helloWorldPattern);
57
+ assembler . process_pattern_recursive ( patternPath , patternlab ) ;
58
+
59
+ test . equals ( helloWorldPattern . render ( ) , 'Hello world!' + eol ) ;
60
+ test . end ( ) ;
61
+
62
+ } ) ;
63
+
64
+ test ( 'underscore partials can render JSON values' , function ( test ) {
65
+
66
+ test . plan ( 1 ) ;
67
+
68
+ // pattern paths
69
+ var pattern1Path = path . resolve (
70
+ testPatternsPath ,
71
+ '00-atoms' ,
72
+ '00-global' ,
73
+ '00-helloworld-withdata.html'
74
+ ) ;
75
+
76
+ // set up environment
77
+ var patternlab = new fakePatternLab ( ) ; // environment
78
+ var assembler = new pa ( ) ;
79
+
80
+ // do all the normal processing of the pattern
81
+ var helloWorldWithData = assembler . process_pattern_iterative ( pattern1Path , patternlab ) ;
82
+ assembler . process_pattern_recursive ( pattern1Path , patternlab ) ;
83
+
84
+ // test
85
+ test . equals ( helloWorldWithData . render ( ) , 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol ) ;
86
+ test . end ( ) ;
87
+
88
+ } ) ;
89
+
90
+ test ( 'findPartial return the ID of the partial, given a whole partial call' , function ( test ) {
91
+ var engineLoader = require ( '../core/lib/pattern_engines' ) ;
92
+ var underscoreEngine = engineLoader . underscore ;
93
+
94
+ test . plan ( 1 ) ;
95
+
96
+ // do all the normal processing of the pattern
97
+ // test
98
+ test . equals ( underscoreEngine . findPartial ( "<%= _.renderNamedPartial('molecules-details', obj) %>" ) , 'molecules-details' ) ;
99
+ test . end ( ) ;
100
+
101
+ } ) ;
102
+
0 commit comments