Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] #250

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

[WIP] #250

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
8 changes: 7 additions & 1 deletion test/apps/async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ function create(hbs, env) {
app.use(cookieParser());

app.get('/', function (req, res) {
res.render('index', {
res.render('index-working', {
message: 'Hello,',
username: req.cookies.user
});
});
app.get('/broken', function (req, res) {
res.render('index-broken', {
message: 'Hello,',
username: req.cookies.user
});
Expand Down
18 changes: 18 additions & 0 deletions test/apps/async/views/index-broken.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{#contentFor "title"}}
{{message}} {{{user username}}}
{{/contentFor}}
<span id="text">This should welcome {{username}}.</span>
<a href="/user/{{username}}"></div>
<div class="pages">
{{#pages filter="tags:test"}}
<div class="page">
<span class="title">{{title}}</title>
<div class="top-comments">
{{#comments top="3" page=id}}
<p>{{user "egg"}}</p>
<span class="subject">{{subject}}</span>-<span class="auther">{{auther}}</span>
{{/comments}}
</div>
</div>
{{/pages}}
</div>
18 changes: 18 additions & 0 deletions test/apps/async/views/index-working.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{#contentFor "title"}}
{{message}} {{{user username}}}
{{/contentFor}}
<span id="text">This should welcome {{username}}.</span>
<a href="/user/{{username}}"></div>
<div class="pages">
{{#pages filter="tags:test"}}
<div class="page">
<span class="title">{{title}}</title>
<div class="top-comments">
{{#comments top="3" page=id}}
<p>{{user "egg"}}</p>
<span class="subject">{{subject}}</span>-<span class="auther">{{auther}}</span>
{{/comments}}
</div>
</div>
{{/pages}}
</div>
16 changes: 0 additions & 16 deletions test/apps/async/views/index.hbs

This file was deleted.

9 changes: 8 additions & 1 deletion test/apps/async/views/layout.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<html><title>{{{block "title"}}}</title><body>{{{body}}}</body></html>
<html>
<title>{{{block "title"}}}</title>

<body>
{{{body}}}
</body>

</html>
86 changes: 31 additions & 55 deletions test/asyncSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,40 @@ var hbs = require('..');
var asyncApp = require('./apps/async');
var resolver = require('../lib/resolver');

function makeUserRequest(app, user, cb) {
request(app)
.get('/')
.set('Cookie', 'user=' + user)
.end(function(err, res) {
if (err) cb(err);
if (res.text.search('Hello, ' + user) <= 0) {
return cb(new Error('Wrong template send for user ' + user + ': ' + res.text), user);
}
return cb(null, user, res.text);
});
}

function requestAll(app, users, cb) {
var status = {};
for(var i = 0; i < users.length; i++) {
status[users[i]] = 'Pending';
makeUserRequest(app, users[i], function(err, user) {
if (err) {
status[user] = 'Error: ' + err.message;
} else {
status[user] = 'Completed'
}
});
}
var checkTimer = setInterval(function() {
for(var i = 0; i < users.length; i++) {
if (status[users[i]] === 'Pending') {
return;
}
}
clearInterval(checkTimer);
cb(status);
}, 100);
}

describe('async', function() {
it('should render all async helpers', function(done) {
describe.only('async', function () {
it('should render nested async helpers', function (done) {
var app = asyncApp.create(hbs.create(), 'production');
requestAll(app, ['jt','anna','joe','jeff','jane'], function(results) {
assert.equal(results.jt, 'Completed');
assert.equal(results.anna, 'Completed');
assert.equal(results.joe, 'Completed');
assert.equal(results.jeff, 'Completed');
assert.equal(results.jane, 'Completed');
done();
});
request(app)
.get('/')
.set('Cookie', 'user=' + 'eggmonster')
.end(function (err, res) {
if (err) {
return done(err);
}
var rendered = res.text;
console.log(rendered);
assert.equal(false, resolver.hasResolvers(rendered));
assert.equal(-1, rendered.search('This should not show!'));
assert.equal(-1, rendered.search('__aSyNcId_'));
done();
});
});

it('should render nested async helpers', function(done) {
it('should render nested async helpers 2', function (done) {
var app = asyncApp.create(hbs.create(), 'production');
makeUserRequest(app, 'jt', function(err, user, results) {
if (err) {
return done(err);
}
assert.equal(false, resolver.hasResolvers(results));
assert.equal(-1, results.search('This should not show!'))
done();
});
request(app)
.get('/broken')
.set('Cookie', 'user=' + 'eggmonster')
.end(function (err, res) {
if (err) {
return done(err);
}
var rendered = res.text;
console.log(rendered);
assert.equal(false, resolver.hasResolvers(rendered));
assert.equal(-1, rendered.search('This should not show!'));
assert.equal(-1, rendered.search('__aSyNcId_'));
done();
});
});
});