@@ -76,7 +76,21 @@ describe('base plugin', function() {
7676 it ( 'provides access to the oringal default values' , function ( ) {
7777 var Plugin = Subject . extend ( {
7878 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+ }
8094 }
8195 } ) ;
8296
@@ -85,20 +99,80 @@ describe('base plugin', function() {
8599 } ) ;
86100
87101 var context = {
102+ revisionData : { revisionKey : '111' } ,
88103 config : {
89104 build : {
90105 distFiles : function ( context , pluginHelper ) {
91106 var arr = pluginHelper . readConfigDefault ( 'distFiles' ) ;
92107 arr . push ( 'index.json' ) ;
93108 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' ;
94123 }
95124 }
96125 }
97126 } ;
98127
99128 plugin . beforeHook ( context ) ;
100- assert . deepEqual ( plugin . defaultConfig . distFiles , [ 'index.html' , 'assets/logo.png' ] ) ;
101129 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' ) ;
102133 } ) ;
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+ } )
103177 } ) ;
104178} ) ;
0 commit comments