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

Failing test for async nested extension #1362

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
88 changes: 88 additions & 0 deletions tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,94 @@
finish(done);
});

it('should allow async custom tag within sync custom tag compilation', function(done) {
function TestSyncExtension() {
this.tags = ['testsync'];

this.parse = function(parser, nodes) {
var content;
var tag;
parser.advanceAfterBlockEnd();

content = parser.parseUntilBlocks('endtestsync');
tag = new nodes.CallExtension(this, 'run', null, [content]);
parser.advanceAfterBlockEnd();

return tag;
};

this.run = function(context, content) {
// Reverse the string
return content().split('').reverse().join('');
};
}

function TestAsyncExtension() {
this.tags = ['testasync'];

this.parse = function(parser, nodes) {
var content;
var tag;
parser.advanceAfterBlockEnd();

content = parser.parseUntilBlocks('endtestasync');
tag = new nodes.CallExtensionAsync(this, 'run', null, [content]);
parser.advanceAfterBlockEnd();

return tag;
};

this.run = function(context, body, callback) {
// Uppercase the string
setTimeout(() => {
callback(null, body().toUpperCase());
}, 1);
};
}

// First prove it works normally
render(
'{% testasync %}abcdefghi{% endtestasync %}',
null,
{
extensions: { TestAsyncExtension: new TestAsyncExtension()},
autoescape: true
},
function(err1, res1) {
expect(res1).to.be('ABCDEFGHI');

render(
'{% testsync %}abcdefghi{% endtestsync %}',
null,
{
extensions: { TestSyncExtension: new TestSyncExtension()},
autoescape: true
},
function(err2, res2) {
expect(res2).to.be('ihgfedcba');

// Then fails with custom tag
render(
'{% testsync %}{% testasync %}abcdefghi{% endtestasync %}{% endtestsync %}',
null,
{
extensions: {
TestExtension: new TestAsyncExtension(),
TestSyncExtension: new TestSyncExtension()
},
autoescape: true
},
function(err3, res3) {
expect(res3).to.be('IHGFEDCBA');
finish(done);
}
);
}
);
}
);
});

it('should autoescape by default', function(done) {
equal('{{ foo }}', {
foo: '"\'<>&'
Expand Down