@@ -76,7 +76,21 @@ describe('base plugin', function() {
76
76
it ( 'provides access to the oringal default values' , function ( ) {
77
77
var Plugin = Subject . extend ( {
78
78
defaultConfig : {
79
- distFiles : [ 'index.html' , 'assets/logo.png' ]
79
+ distFiles : [ 'index.html' , 'assets/logo.png' ] ,
80
+ jsonBlueprint : {
81
+ link : {
82
+ selector : 'link' ,
83
+ attributes : [ 'rel' , 'href' ]
84
+ } ,
85
+ } ,
86
+ git : {
87
+ sha : function ( ) {
88
+ return '1' ;
89
+ }
90
+ } ,
91
+ revisionKey : function ( context ) {
92
+ return context . revisionData . revisionKey ;
93
+ }
80
94
}
81
95
} ) ;
82
96
@@ -85,20 +99,80 @@ describe('base plugin', function() {
85
99
} ) ;
86
100
87
101
var context = {
102
+ revisionData : { revisionKey : '111' } ,
88
103
config : {
89
104
build : {
90
105
distFiles : function ( context , pluginHelper ) {
91
106
var arr = pluginHelper . readConfigDefault ( 'distFiles' ) ;
92
107
arr . push ( 'index.json' ) ;
93
108
return arr ;
109
+ } ,
110
+ jsonBlueprint : function ( context , pluginHelper ) {
111
+ var blueprint = pluginHelper . readConfigDefault ( 'jsonBlueprint' ) ;
112
+ blueprint . link . attributes . push ( 'integrity' ) ;
113
+
114
+ return blueprint ;
115
+ } ,
116
+ sha : function ( context , pluginHelper ) {
117
+ var git = pluginHelper . readConfigDefault ( 'git' ) ;
118
+
119
+ return git . sha ( ) + '2' ;
120
+ } ,
121
+ revisionKey : function ( context , pluginHelper ) {
122
+ return pluginHelper . readConfigDefault ( 'revisionKey' ) + '222' ;
94
123
}
95
124
}
96
125
}
97
126
} ;
98
127
99
128
plugin . beforeHook ( context ) ;
100
- assert . deepEqual ( plugin . defaultConfig . distFiles , [ 'index.html' , 'assets/logo.png' ] ) ;
101
129
assert . deepEqual ( plugin . readConfig ( 'distFiles' ) , [ 'index.html' , 'assets/logo.png' , 'index.json' ] ) ;
130
+ assert . deepEqual ( plugin . readConfig ( 'jsonBlueprint' ) . link . attributes , [ 'rel' , 'href' , 'integrity' ] ) ;
131
+ assert . equal ( plugin . readConfig ( 'sha' ) , '12' ) ;
132
+ assert . equal ( plugin . readConfig ( 'revisionKey' ) , '111222' ) ;
102
133
} ) ;
134
+
135
+ it ( 'ensures default values do not get mutated' , function ( ) {
136
+ var Plugin = Subject . extend ( {
137
+ defaultConfig : {
138
+ distFiles : [ 'index.html' , 'assets/logo.png' ] ,
139
+ jsonBlueprint : {
140
+ link : {
141
+ selector : 'link' ,
142
+ attributes : [ 'rel' , 'href' ]
143
+ }
144
+ }
145
+ }
146
+ } ) ;
147
+
148
+ var plugin = new Plugin ( {
149
+ name : 'build'
150
+ } ) ;
151
+
152
+ var context = {
153
+ config : {
154
+ build : {
155
+ distFiles : function ( context , pluginHelper ) {
156
+ var arr = pluginHelper . readConfigDefault ( 'distFiles' ) ;
157
+ arr . push ( 'index.json' ) ;
158
+ return arr ;
159
+ } ,
160
+ jsonBlueprint : function ( context , pluginHelper ) {
161
+ var blueprint = pluginHelper . readConfigDefault ( 'jsonBlueprint' ) ;
162
+ blueprint . link . attributes . push ( 'integrity' ) ;
163
+
164
+ return blueprint ;
165
+ }
166
+ }
167
+ }
168
+ } ;
169
+
170
+ plugin . beforeHook ( context ) ;
171
+ plugin . readConfig ( 'distFiles' )
172
+ plugin . readConfig ( 'jsonBlueprint' )
173
+
174
+ assert . deepEqual ( plugin . defaultConfig . distFiles , [ 'index.html' , 'assets/logo.png' ] ) ;
175
+ assert . deepEqual ( plugin . defaultConfig . jsonBlueprint . link . attributes , [ 'rel' , 'href' ] ) ;
176
+ } )
103
177
} ) ;
104
178
} ) ;
0 commit comments