Skip to content

Commit a0f9a65

Browse files
drewwestrickjescalan
authored andcommitted
Added tests for no path and no output function (#77)
1 parent 29e0710 commit a0f9a65

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

test/index.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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(), /Error: cats.template must have a "path" property/)
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(), /Error: cats.template must have an "output" function/)
390+
rimraf.sync(path.join(projectPath, 'public'))
391+
t.end()
392+
})
393+
project.compile()
394+
})

0 commit comments

Comments
 (0)