@@ -318,3 +318,77 @@ test.cb('generates error if template has an error', (t) => {
318318
319319 project . compile ( )
320320} )
321+
322+ test . cb ( 'generates error if template has no path' , ( t ) => {
323+ const locals = { }
324+ const contentful = new Contentful ( {
325+ accessToken : process . env . accessToken ,
326+ spaceId : process . env . spaceId ,
327+ addDataTo : locals ,
328+ contentTypes : [
329+ {
330+ name : 'cats' ,
331+ id : 'cat' ,
332+ filters : {
333+ limit : 2 ,
334+ order : 'sys.createdAt'
335+ } ,
336+ template : {
337+ output : ( item ) => `cats/${ item . fields . name } .html`
338+ }
339+ }
340+ ]
341+ } )
342+
343+ const projectPath = path . join ( __dirname , 'fixtures/template' )
344+ const project = new Spike ( {
345+ root : projectPath ,
346+ reshape : standard ( { locals } ) ,
347+ entry : { main : [ path . join ( projectPath , 'main.js' ) ] } ,
348+ plugins : [ contentful ]
349+ } )
350+
351+ project . on ( 'error' , ( error ) => {
352+ t . regex ( error . toString ( ) , / E r r o r : c a t s .t e m p l a t e m u s t h a v e a " p a t h " p r o p e r t y / )
353+ rimraf . sync ( path . join ( projectPath , 'public' ) )
354+ t . end ( )
355+ } )
356+ project . compile ( )
357+ } )
358+
359+ test . cb ( 'generates error if template has no output function' , ( t ) => {
360+ const locals = { }
361+ const contentful = new Contentful ( {
362+ accessToken : process . env . accessToken ,
363+ spaceId : process . env . spaceId ,
364+ addDataTo : locals ,
365+ contentTypes : [
366+ {
367+ name : 'cats' ,
368+ id : 'cat' ,
369+ filters : {
370+ limit : 2 ,
371+ order : 'sys.createdAt'
372+ } ,
373+ template : {
374+ path : 'template.html'
375+ }
376+ }
377+ ]
378+ } )
379+
380+ const projectPath = path . join ( __dirname , 'fixtures/template' )
381+ const project = new Spike ( {
382+ root : projectPath ,
383+ reshape : standard ( { locals } ) ,
384+ entry : { main : [ path . join ( projectPath , 'main.js' ) ] } ,
385+ plugins : [ contentful ]
386+ } )
387+
388+ project . on ( 'error' , ( error ) => {
389+ t . regex ( error . toString ( ) , / E r r o r : c a t s .t e m p l a t e m u s t h a v e a n " o u t p u t " f u n c t i o n / )
390+ rimraf . sync ( path . join ( projectPath , 'public' ) )
391+ t . end ( )
392+ } )
393+ project . compile ( )
394+ } )
0 commit comments