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

fix: return callback if called #4178

Merged
merged 1 commit into from
Mar 30, 2020
Merged

Conversation

curbengh
Copy link
Contributor

What does it do?

fix remaining alerts of lgtm.

  • file.js - since options is not used in the function, there's no need to handle it.
  • tag.js - return a callback if render() is called with a callback.

How to test

git clone -b callback-handling https://github.com/curbengh/hexo.git
cd hexo
npm install
npm test

Screenshots

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
curbengh Ming Di Leom
@curbengh curbengh requested a review from a team March 10, 2020 22:44
Comment on lines 237 to +240
return Promise.fromCallback(cb => { this.env.renderString(str, options, cb); })
.catch(err => Promise.reject(formatNunjucksError(err, str)))
.then(result => result.replace(rPlaceholder, (_, index) => cache[index]));
.then(result => result.replace(rPlaceholder, (_, index) => cache[index]))
.asCallback(callback);
Copy link
Member

Choose a reason for hiding this comment

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

SInce Promise.fromCallback is used, is it still necessary to use asCallback?

it('render() - callback', () => {
const tag = new Tag();
const callback = spy();
tag.register('test', () => 'foo');
return tag.render('{% test %}', callback()).then(result => {
result.should.eql('foo');
callback.calledOnce.should.be.true;
});
});

callback related test case is already added and it seems passed.

@SukkaW SukkaW merged commit ed98ae8 into hexojs:master Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants