Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions functions/helloworld/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,15 @@ exports.helloError3 = function helloError3 (event, callback) {
};
// [END functions_helloworld_error_3]
/* eslint-enable */

// [START functions_helloworld_template]
const pug = require('pug');

// Renders the index.pug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: redundant comment

exports.helloTemplate = (req, res) => {
// Render the index.pug file
const html = pug.renderFile('./index.pug');

res.send(html).end();
};
// [END functions_helloworld_template]
9 changes: 9 additions & 0 deletions functions/helloworld/index.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
doctype html
html(lang="en")
head
title= pageTitle
body
h1 Cloud Functions Template Sample
p.
Pug is a terse and simple templating language with a
strong focus on performance and powerful features.
1 change: 1 addition & 0 deletions functions/helloworld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@google-cloud/debug-agent": "1.0.0",
"pug": "2.0.0-beta.12",
"safe-buffer": "5.0.1"
},
"devDependencies": {
Expand Down
14 changes: 14 additions & 0 deletions functions/helloworld/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,17 @@ test.serial(`helloError3: callback shoud return an errback value`, (t) => {
t.deepEqual(callback.callCount, 1);
t.deepEqual(callback.firstCall.args, [expectedMsg]);
});

test.serial(`helloTemplate: should render the html`, async (t) => {
const req = {};
const res = {};
res.send = sinon.stub().returnsThis();
res.end = sinon.stub().returnsThis();

program.helloTemplate(req, res);

t.is(res.send.callCount, 1);
t.is(res.send.getCall(0).args.length, 1);
t.is(res.send.getCall(0).args[0].includes('<h1>Cloud Functions Template Sample</h1>'), true);
t.is(res.end.callCount, 1);
});
Loading