@@ -70,7 +70,109 @@ describe('base plugin', function() {
70
70
plugin . log ( 'foo' , { verbose : true } ) ;
71
71
assert . deepEqual ( verboseUi . messages , [ '\u001b[34m| \u001b[39m' ] ) ;
72
72
} ) ;
73
-
74
73
} ) ;
75
74
75
+ describe ( 'plugin helper' , function ( ) {
76
+ it ( 'provides access to the oringal default values' , function ( ) {
77
+ var Plugin = Subject . extend ( {
78
+ defaultConfig : {
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
+ }
94
+ }
95
+ } ) ;
96
+
97
+ var plugin = new Plugin ( {
98
+ name : 'build'
99
+ } ) ;
100
+
101
+ var context = {
102
+ revisionData : { revisionKey : '111' } ,
103
+ config : {
104
+ build : {
105
+ distFiles : function ( context , pluginHelper ) {
106
+ var arr = pluginHelper . readConfigDefault ( 'distFiles' ) ;
107
+ arr . push ( 'index.json' ) ;
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' ;
123
+ }
124
+ }
125
+ }
126
+ } ;
127
+
128
+ plugin . beforeHook ( context ) ;
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' ) ;
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
+ } )
177
+ } ) ;
76
178
} ) ;
0 commit comments