diff --git a/.node-version b/.node-version deleted file mode 100644 index 8089590..0000000 --- a/.node-version +++ /dev/null @@ -1 +0,0 @@ -4.3.0 diff --git a/lib/handler.js b/lib/handler.js index 5b76f3c..25be99d 100644 --- a/lib/handler.js +++ b/lib/handler.js @@ -12,7 +12,7 @@ module.exports = function(viewConfig) { } } // aug with globals: - const obj = aug({}, viewConfig.data, viewConfig.options.globals); + const obj = aug({}, viewConfig.data, viewConfig.groupedData, viewConfig.options.globals); let result; try { diff --git a/test/test.views.js b/test/test.views.js index a72291b..0f15ec4 100644 --- a/test/test.views.js +++ b/test/test.views.js @@ -137,6 +137,53 @@ lab.test('globals', async() => { await server.stop(); }); +lab.test('grouped', async() => { + const server = new Hapi.Server({ + debug: { request: '*', log: 'hapi-views' } + }); + server.method('yaml', (request, yamlFile) => { + return new Promise((resolve) => { + return resolve({ test1: true }); + }); + }); + // start server + await server.register([ + require('vision'), + { + plugin: require('../'), + options: { + dataPath: `${process.cwd()}/test/yaml`, + routes: { + '/yaml': { + view: 'yaml', + groupedData: { + grouped: true + }, + data: { + yaml1: 'yaml()', + } + } + }, + globals: { + yaml2: { property: 1235 } + } + } + } + ]); + server.views({ + engines: { html: require('handlebars') }, + path: `${__dirname}/views` + }); + const response = await server.inject({ url: '/yaml' }); + const context = response.request.response.source.context; + expect(context).to.equal({ + yaml1: { test1: true }, + yaml2: { property: 1235 }, + grouped: true + }); + await server.stop(); +}); + lab.test('onError', async() => { const server = new Hapi.Server({ debug: { log: 'hapi-views', request: '*' },