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: file creation bug on tests. #1667
base: 4.x
Are you sure you want to change the base?
Conversation
@@ -1,6 +1,15 @@ | |||
define(['handlebars.runtime'], function(Handlebars) { | |||
Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; | |||
return templates['non.default.extension'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { | |||
return "<div>This is a test</div>"; | |||
return templates['example_2'] = template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { |
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.
Used existing example_2.hbs
artifact instead of non.default.extension.hbs
artifact. That's the reason there's a diff here and also the reason why non.default.extension.hbs
was removed.
@@ -307,7 +307,7 @@ describe('precompiler', function() { | |||
Precompiler.loadTemplates( | |||
{ files: [__dirname + '/artifacts'], extension: 'hbs' }, | |||
function(err, opts) { | |||
equal(opts.templates.length, 2); | |||
equal(opts.templates.length, 1); |
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.
As non.default.extension.hbs
artifact was removed in this PR, the count is now back to 1.
FWIW, I ran The tests all passed as expected, and the |
Hmm, I think this change is a little confusing and changes what is being tested. In the original test:
Contains the sourcemap:
And
With the new test:
We're now testing the sourcemap has the correct config, not the template. That might well be a valid test, but it's a different test to the one that was there before Nothing to do with this PR, |
This is a bi-product of passing a string via cli to the the handlebars precompiler vs. reading from a template file.
IMO, this is a better unit test than the previous one as it asserts the content of the source map. We can improve on this by adding another assertion to test that the source map is correctly referenced within the compiled template. This will require us to switch from passing a string to the complier via the cli to reading from a template file. Let me know your thoughts. Happy to close the gap as per the above comments. |
I disagree 🙂 Handlebars isn't responsible for the content of the source map being correct, that's the job of the source-map module. The original test checked that the handlebars template had the correct sourcemap string, which is the behaviour specific to handlebars. A second thing to test would be that the linked source map file actually exists, but I see no reason to verify the contents. TBH I think the correct fix for this issue is Nils' suggestion. |
I've used the tmp dir approach to fix this locally and am going to push it to unblock the release. If you would like to update this PR to add an additional test to check that the sourcemap file is created, and make the other modifications here, will merge after release :) |
Quiet right; I'm convinced :) I'll update the tests accordingly. |
Do we still need this PR or can it be closed? |
Let's keep this open as until I've had a chance to review what we landed in I hope to get it this weekend. |
@aorinevo Is this still relevant? |
Changes
grunt test:bin
some files are created that fail CI if not removed. For each test, if a file is created it is cleaned up after the test run in complete.Notes