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
Removes escaping of double-quotes around string value #4224
Conversation
Seeing as the tests pass with and without this patch, I'm pretty sure the tests are not really setting up the inputs and outputs correctly. The tests look reasonable and I'm not seeing what's wrong with them, but if someone wants to point me at the problem, I can patch those too. |
Oh I see it. Umm, I think a lot of the variable tests may not be properly setting up the inputs and outputs. The tests are actually mocking the return value of In effect, we're declaring that Should probably not be mocking (stubbing?) |
Removed the stub for But if I remove the |
Ok, this test exposes the problem on the master branch:
|
There we go. Now the string syntax tests are calling the functions being tested. |
I would check the populate call for a fulfillment just for the sake of completeness and verification that the
|
@HyperBrain I just tried that but get,
|
@lorengordon Can you check if at the top of the file there is a This enables promise handling and testing, exactly as from my example above. The trick is, that you validate the promise, before you "then" it. "fulfilled" is only available when chai-as-promised is loaded as chai plugin. This also enabled rejection testing with |
This is the only line that contains
|
Ok, then replace it with:
and we should have full chai promise support afterwards. |
Ok, this diff works using the approach you proposed: diff --git a/lib/classes/Variables.test.js b/lib/classes/Variables.test.js
index 19943db7..10286531 100644
--- a/lib/classes/Variables.test.js
+++ b/lib/classes/Variables.test.js
@@ -3,7 +3,7 @@
const path = require('path');
const proxyquire = require('proxyquire');
const YAML = require('js-yaml');
-const expect = require('chai').expect;
+const chai = require('chai');
const Variables = require('../../lib/classes/Variables');
const Utils = require('../../lib/classes/Utils');
const Serverless = require('../../lib/Serverless');
@@ -14,6 +14,10 @@ const AwsProvider = require('../plugins/aws/provider/awsProvider');
const BbPromise = require('bluebird');
const os = require('os');
+chai.use(require('chai-as-promised'));
+
+const expect = chai.expect;
+
describe('Variables', () => {
describe('#constructor()', () => {
const serverless = new Serverless();
@@ -182,11 +186,12 @@ describe('Variables', () => {
serverless.variables.loadVariableSyntax();
- return serverless.variables.populateProperty(property).then(newProperty => {
- expect(newProperty).to.equal('my stage is prod');
-
- return BbPromise.resolve();
- });
+ return expect(serverless.variables.populateProperty(property)).to.be.fulfilled
+ .then(newProperty => {
+ expect(newProperty).to.equal('my stage is prod');
+ });
});
it('should call getValueFromSource if no overwrite syntax provided', () => { |
You can even dismiss the
Sorry for the lots of single small comments from my side 😃 |
@HyperBrain I did remove that in the actual commit, and I modified the diff in the comment after the fact... And no problem on the comments, I appreciate the pointers! Very new to javascript and much of this promise stuff escapes me! |
dca0069
to
9746de3
Compare
@lorengordon thanks for that! I see that you've modified some of our tests, but I think it's best if we add a separate test case that specifically tests this edge case. Imo it'd be better to keep our tests focused and high in quality. Other than that, I've tried your reproduction steps, and they work as expected. 👍 |
@eahefnawy The tests I modified were invalid. They didn't actually test the primary condition they claimed to test. One of the tests already claimed to be checking for exactly what this patch fixes. I fixed the invalid tests. Now they actually do what they describe. Please take another look at the modified tests and the discussion above. Also, I'm afraid several other tests in this module may suffer from the same circular logic. 😢 |
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.
Thanks for providing this fix @lorengordon 👍
I just tested it and it works great! I also looked into the tests and they look legit 💯
Also, I'm afraid several other tests in this module may suffer from the same circular logic. 😢
Yes, that's also smth. I'm afraid of. Maybe it's a good idea to revisit the tests here soon.
What did you implement:
When using the new string syntax for a variable, a double-quoted string would be rendered with the double-quotes escaped around the value.
How can we verify it:
serverless.yml:
Rendered cfn template without the patch:
Rendered cfn template with the patch:
Todos:
Is this ready for review?: YES
Is it a breaking change?: NO