@@ -31,6 +31,8 @@ const mockOra = {
3131
3232jest . mock ( 'ora' , ( ) => jest . fn ( ( ) => mockOra ) ) ;
3333
34+ process . env . FORBIDDEN_ELEMENT = 'Cadmium' ;
35+
3436const Sourcebit = require ( './sourcebit' ) ;
3537
3638beforeEach ( ( ) => {
@@ -89,9 +91,8 @@ describe('`bootstrapAll()`', () => {
8991 await sourcebit . bootstrapAll ( ) ;
9092 } ) ;
9193
92- test ( 'passes an `options` block plugins' , async ( ) => {
94+ test ( 'passes an `options` block to plugins' , async ( ) => {
9395 const mockPluginBase = {
94- name : 'sourcebit-mock-plugin1' ,
9596 options : {
9697 forbiddenElement : {
9798 default : 'Arsenic'
@@ -104,20 +105,23 @@ describe('`bootstrapAll()`', () => {
104105 } ;
105106 const mockPlugin1 = {
106107 ...mockPluginBase ,
108+ name : 'sourcebit-mock-plugin1' ,
107109 bootstrap : jest . fn ( ( { options } ) => {
108110 expect ( options . forbiddenElement ) . toEqual ( mockPluginBase . options . forbiddenElement . default ) ;
109111 expect ( options . requiredElement ) . toEqual ( mockPluginBase . options . requiredElement . default ) ;
110112 } )
111113 } ;
112114 const mockPlugin2 = {
113115 ...mockPluginBase ,
116+ name : 'sourcebit-mock-plugin2' ,
114117 bootstrap : jest . fn ( ( { options } ) => {
115118 expect ( options . forbiddenElement ) . toEqual ( 'Cadmium' ) ;
116119 expect ( options . requiredElement ) . toEqual ( 'Calcium' ) ;
117120 } )
118121 } ;
119122 const mockPlugin3 = {
120123 ...mockPluginBase ,
124+ name : 'sourcebit-mock-plugin3' ,
121125 bootstrap : jest . fn ( ( { options } ) => {
122126 expect ( options . forbiddenElement ) . toEqual ( mockPluginBase . options . forbiddenElement . default ) ;
123127 expect ( options . requiredElement ) . toEqual ( 'Magnesium' ) ;
@@ -154,6 +158,50 @@ describe('`bootstrapAll()`', () => {
154158 await sourcebit3 . bootstrapAll ( ) ;
155159 } ) ;
156160
161+ test ( 'uses the value of an environment variable named after the `env` option as a default value' , async ( ) => {
162+ const mockPluginBase = {
163+ options : {
164+ forbiddenElement : {
165+ env : 'FORBIDDEN_ELEMENT' ,
166+ default : 'Arsenic'
167+ }
168+ }
169+ } ;
170+ const mockPlugin1 = {
171+ ...mockPluginBase ,
172+ name : 'sourcebit-mock-plugin1' ,
173+ bootstrap : jest . fn ( ( { options } ) => {
174+ expect ( options . forbiddenElement ) . toEqual ( process . env . FORBIDDEN_ELEMENT ) ;
175+ } )
176+ } ;
177+ const mockPlugin2 = {
178+ ...mockPluginBase ,
179+ name : 'sourcebit-mock-plugin2' ,
180+ bootstrap : jest . fn ( ( { options } ) => {
181+ expect ( options . forbiddenElement ) . toEqual ( 'Einsteinium' ) ;
182+ } )
183+ } ;
184+ const config1 = {
185+ plugins : [ { module : mockPlugin1 } ]
186+ } ;
187+ const config2 = {
188+ plugins : [
189+ {
190+ module : mockPlugin2 ,
191+ options : { forbiddenElement : 'Einsteinium' }
192+ }
193+ ]
194+ } ;
195+ const sourcebit1 = new Sourcebit ( ) ;
196+ const sourcebit2 = new Sourcebit ( ) ;
197+
198+ sourcebit1 . loadPlugins ( config1 . plugins ) ;
199+ sourcebit2 . loadPlugins ( config2 . plugins ) ;
200+
201+ await sourcebit1 . bootstrapAll ( ) ;
202+ await sourcebit2 . bootstrapAll ( ) ;
203+ } ) ;
204+
157205 test ( 'passes a `getPluginContext` method to plugins' , async ( ) => {
158206 mockCache = {
159207 'sourcebit-mock-plugin1' : {
0 commit comments