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(docstring.feature): extend DocString.feature tests to cover failing scenario #416

Merged
merged 3 commits into from
Jul 19, 2020

Conversation

ralphsaunders
Copy link
Contributor

Test case for reported issue #415

DocString.feature will fail when ES6 template literals are present in the DocString.

Open to suggestions/support on how this can be fixed.

…ng scenario

DocString.feature will fail when ES6 template literals are present in the DocString.
@lgandecki
Copy link
Collaborator

Thanks for this :) It's always helpful to start with a failing test.
If no one else picks it up I will try. Should be doable, although it might be a bit tricky.

@badeball
Copy link
Owner

badeball commented Jul 16, 2020

I believe the following patch will suffice. Using single- or double-quotes is per js-string-escape' specs.

diff --git a/lib/featuresLoader.js b/lib/featuresLoader.js
index 266db34..a380f23 100644
--- a/lib/featuresLoader.js
+++ b/lib/featuresLoader.js
@@ -61,9 +61,9 @@ const createCucumber = (
             .find(fileSteps => fileSteps[filePath])
             [filePath].join("\n")}
             
-        createTestsFromFeature('${path.basename(filePath)}', \`${jsStringEscape(
+        createTestsFromFeature('${path.basename(filePath)}', "${jsStringEscape(
         spec
-      )}\`);
+      )}");
         })
         `

@lgandecki
Copy link
Collaborator

nice! @ralphsaunders are you able to test that?

Suggested fix. Unfortunately test case still fails.

re #415
@ralphsaunders
Copy link
Contributor Author

Unfortunately @lgandecki @badeball the suggested change is failing the test case. I did notice the create cucumber fn returns an ES6 template literal itself but unsure if that's really the problem.

I read the js-string-escape implementation and saw it has ES5 support. ES6 introduced template literals so I suppose the escaping rules may need to be extended to catch the two character sequence ${ (relevant spec).

js-string-escape does have a relevant issue raised. Perhaps we could find an alternative package if js-string-escape is as dead as it first appears?

@badeball
Copy link
Owner

My bad, I had just left out the most important case. Try this and if it works, then there's no need to wait for their maintainer to do anything.

diff --git a/lib/featuresLoader.js b/lib/featuresLoader.js
index 266db34..a380f23 100644
--- a/lib/featuresLoader.js
+++ b/lib/featuresLoader.js
@@ -61,9 +61,9 @@ const createCucumber = (
             .find(fileSteps => fileSteps[filePath])
             [filePath].join("\n")}
             
-        createTestsFromFeature('${path.basename(filePath)}', \`${jsStringEscape(
+        createTestsFromFeature('${path.basename(filePath)}', "${jsStringEscape(
         spec
-      )}\`);
+      )}");
         })
         `
     )
diff --git a/lib/loader.js b/lib/loader.js
index 6edabd1..5945928 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -15,7 +15,7 @@ const createCucumber = (filePath, cucumberJson, spec, toRequire, name) =>
   window.cucumberJson = ${JSON.stringify(cucumberJson)};
   describe(\`${name}\`, function() {
     ${toRequire.join("\n")}
-    createTestsFromFeature('${filePath}', \`${jsStringEscape(spec)}\`);
+    createTestsFromFeature('${filePath}', "${jsStringEscape(spec)}");
   });
   `;

@badeball
Copy link
Owner

badeball commented Jul 18, 2020

Btw, I believe JSON is practically a subset of JS, except for two peculiar unicode characters, so it should be pretty straight forward to remove that dependency entirely.

Edit: To extend on this: I mean that you can just use JSON.stringify(myString) to obtain nearly the same thing.

@ralphsaunders
Copy link
Contributor Author

Ah I hadn't read your first diff properly @badeball and so missed there was another way specs were loaded in. Adjusting both as the new test case passing! :)

@lgandecki lgandecki merged commit bc6dfb3 into badeball:master Jul 19, 2020
@lgandecki
Copy link
Collaborator

great, thank you guys :)

@lgandecki
Copy link
Collaborator

🎉 This PR is included in version 2.5.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants