-
Notifications
You must be signed in to change notification settings - Fork 2k
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
In spec tests, use expectTemplate over equals and shouldThrow #1683
Conversation
Looks like diff --git a/spec/env/common.js b/spec/env/common.js
index 5997322..1a78619 100644
--- a/spec/env/common.js
+++ b/spec/env/common.js
@@ -183,7 +183,7 @@ HandlebarsTestBench.prototype.withMessage = function(message) {
};
HandlebarsTestBench.prototype.toCompileTo = function(expectedOutputAsString) {
- expect(this._compileAndExecute()).to.equal(expectedOutputAsString);
+ expect(this._compileAndExecute()).to.equal(expectedOutputAsString, this.message);
};
// see chai "to.throw" (https://www.chaijs.com/api/bdd/#method_throw) |
First of all, I wouldn't say that this change has little benefit. I have often looked at test cases and had a hard time to understand what was actually tested, especially with the I think replacing all calls (also to Of course, the thing with tests is, that if you want to ensure backwards compatibility, you shouldn't change them. But on the other hand, it will make the code much more readable. The important thing is that they are really semantically equal to the old version. I haven't had a detailed look at your PR yet, but please proceed with replacing |
Yes, that's right. I don't know why I didn't use it. Maybe do this as a separate commit so that it can be more easily reverted. I would even discard the third parameter of |
I should probably also share my vision about the spec and about language test-cases: My long-term goal which also addresses #1277, is to write a specification text, but also include test-cases in yaml form (independent of any language). An example is this file, but this is just an early thought. It would be cool to have some kind of IDE support to write those examples, but not strictly necessary. Helpers are, of course, difficult to describe that way, but this can probably be solved similar to the lambdas in the mustache-spec. I want to mention this, because rewriting all tests using I should probably start setting up another VuePress site containing the language spec. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that was a lot of work. Sadly also a lot of work to review... Before merging, I want to have a look at each test, but today, I only came as far as the end of basic.js
. I have added some comments and change requests.
Those are not things that you have done wrong, but rather things that can be improved further, now that you replaced everything by expectTemplate
. I'll add another review later on, but for now, I just want my review saved...
Well I just felt a little bad waltzing in here and changing the git-blame on the entire test suite, that's all :)
Should be pretty safe. I could try to write some code that verified the inputs to CompilerContext were binary-equal, but that seems like overkill.
Done.
That would be great! I'll have to stick to my Frankenstein creation in [0] in the meantime, of course. I hope you'll also throw up a page with a list of all the different implementations at some point, if there isn't already. They can be hard to track down sometimes.
Feel free to ping me when you need a bunch of javascript converted to PHP. For C, I have to resort to this abomination [2]. A quick overview of my recent commits. In the interest of avoiding transcription errors, I wrote a converter [1] to convert There are currently individual commits for:
Of course, feel free to request any changes, rebases, rewords, squashes, merges, etc. I'm going to try and do another manual review of the whole thing, but it'll probably take a while. |
@nknapp Sorry there wasn't any context, typing up my previous post took a while, I should have prepared it beforehand.
Yeah, I was a little worried doing most of the work in advance that the review burden would be too high to have it merged :S |
it('partials with undefined context', function() {
var string = 'Dudes: {{>dude dudes}}';
var partial = '{{foo}} Empty';
var hash = {};
shouldCompileToWithPartials(
string,
[hash, {}, { dude: partial }],
true,
'Dudes: Empty'
);
});
EDIT: I'm just dumb it was referring to the partial context, not the root context. |
944a0e8
to
dd909e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I didn't make it the whole way through. I found some places where variables should be inlined. But altogether I like it very much.
Kudos to you, that's a lot of changes that you committed there. I'll continue my review during the next days (hopefully).
Apart from the review, I have been wondering about these lines: https://github.com/handlebars-lang/handlebars.js/blob/master/spec/builtins.js#L228-L243 It would be really cool to get completely remove "compileWithPartials", but this call cannot be replaced easier: I am thinking about adding a new method to
Do you have any preference in this? The first one is more explicite, and since you are not using JavaScript, if would probably be more useful to you. The second one is more flexible, in case other use cases come along. I think I would tend to use |
@nknapp I would lean towards the former. If you wanted something more generic, using a regex would allow a bit more flexibility while still being used easily from other languages. |
Looks like the build failed due to a timeout in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed two more files.
I really didn't realize up-front how much work this is. I think next time it would be better to do things like this in multiple PRs with changing only some files.
Good. I will see if I change it, but rather in a separate PR. |
I'll see to that in the end, when I have reviewed all files. Maybe it helps to just increase the timeout. |
Currently using using my fork: https://github.com/jbboehr/handlebars.js/tree/remove-equals-4.x Awaiting PR: handlebars-lang/handlebars.js#1683 * Rewrote everything in TypeScript * Switched the license to `AGPL-3.0-or-later`. The specification data is still licensed under the `MIT` license, as it is extracted from `handlebars.js` * `description` now includes all `describe($description, ...)` from the handlebars test suite * `exception` can now be either `true`, a string, or a regex. * `message` used to be the exception message, but will now be any extra message noted in the handlebars.js test suite * `options` was renamed to `runtimeOptions` to differentiate from `compileOptions` * Using a new version format `104.7.6` which is: `(myMajor * 100 + handlebarsMajor) + '.' + (myMinor * 100 + handlebarsMinor) + '.' + (myPatch * 100 + handlebarsPatch)` * `number` is now included in tests (besides the first implied `00`) that have multiple cases * `compat` is removed in favor of `compileOptions.compat` * `globalPartials`, `globalDecorators`, and `globalHelpers` are now removed and merged into `partials`, `decorators`, and `helpers` instead Closes #7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have to review 4 files. I have added a small comment, but this is something that could have been better before. You don't have to fix it. I can do that later as well (but I might forget about it, so I wanted to take a note).
CompilerContext.compileWithPartial = CompilerContext.compile; | ||
expectTemplate('{{> dude}}') | ||
.withPartials({ dude: 'fail' }) | ||
.toThrow(Error, /The partial dude could not be compiled/); | ||
handlebarsEnv.compile = compile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resetting the functions would be better in a finally-block.
So, I hate to change a bunch of code for relatively little benefit, but I have a project that exports the specification tests as JSON [0] and, well, it would make my life a lot easier if
expectTemplate
was used instead ofequals
orshouldThrow
in the test suite, where possible.I would also convert
shouldCompileTo
if you'd like, but I figured I'd keep the changes to a minimum for now.I added two methods,
withHelpers
andwithPartials
toHandlebarsTestBench
only because it let me port a bunch of tests with fewer changes. If you'd prefer, I would remove those and convert the tests to usewithHelper
andwithPartial
directly.I tried to keep the changes generally linear so it would be easier to review. Let me know if there's anything you'd like changed.