fix(test): Update to support latest version of markedjs #1434
fix(test): Update to support latest version of markedjs #1434
Conversation
Just to make sure someone sees this @scissorsneedfoodtoo @ShaunSHamilton |
@lasjorg Thanks, for the ping. Just to clarify, I see both versions pass all tests using both ways to import |
When you say both versions, are you talking about the old and new test scripts? If so I tried to explain it in the longer explanation. When using import on Codepen we fall back to using the version of markedjs that we load in So when that old version of markedjs is loaded the old test will still work even if the project is using version 4 of markedjs, as we will not be using that version (the one the project is using) for the internal tests but the old version loaded in As I said, it's confusing and hard to explain. |
No, |
To be clear, if you want to see the old test fail use the script element that loads markedjs version 4 in the HTML. When you use import we do not use that version internally for the tests so it doesn't fail the typeof check that it will when loading markedjs version 4 in the HTML. When loaded in the HTML or settings we do use that version internally. |
It's really hard to explain. So sorry about that.
When using |
That does clear that confusion up. Thank you, for bearing with me. Then, in this case:
Then I agree with this:
I do not understand why it would be preferable - both allow versioning? Also, it appears the CDN is ~1/3 the size of the npm package. |
Managing dependencies using package.json is far more maintainable and seeing as the version in Using a CDN link buried inside some code no one ever looks at is hardly a very maintainable approach to internal dependencies. |
Likely closing this in favor of #1435 but I will keep this open for now. |
@lasjorg, thanks for your patience, and for the very detailed breakdown of the problem, possible solutions, and the pros and cons of each solution. After reading through the discussion you had with @ShaunSHamilton, and trying this and your other PR, I believe adding Marked as an npm dependency is better in this case. Like you mentioned, it's more maintainable and easier to understand, even if it does increase the bundle size a bit. Will close this in favor of #1435. |
Pre-Submission Checklist
master
branch of freeCodeCamp/testable-projects-fccfix/
,feature/
, ortranslate/
(e.g.fix/signin-issue
)Type of Change
Checklist:
Description
Markdown projects are failing tests they shouldn't with the latest version 4 of markedjs when loaded using Codepen settings or a script element.
TL;DR explanation. We had a
typeof
check that was failing.typeof marked
can return 'function' or 'object' depending on the version of the library and how it is loaded.Forum: https://forum.freecodecamp.org/t/markdown-previewer-solution-fails-tests-5-and-6-despite-functioning-as-intended/484737
Example Codepen with the old and new versions of tests and library.
https://codepen.io/lasjorg/pen/jOGEqbL?editors=1010
Note that
marked.parse(props.markdown, { renderer: renderer })
(Line: 108) is used in this example.Very much not TL;DR explanation: I apologize in advance for the long and somewhat confusing explanation. Frankly, at this point, I'm a little confused myself.
When version 4 of markedjs is loaded using the JS section in the Codepen settings or as a script element
typeof marked
returns'object'
. Version 3 and below of markedjs returns'function'
.When using the import syntax on Codepen.
However, if you do the same console.log in the browser console manually before running the tests it will return
undefined
. It beingundefined
will (afaict) cause us to load our version of the library found insrc\index.js
when you run the test. Which is (or was) an old version that would also report typeof 'function'. As far as I can tell, it looks like when the camper uses the Codepen import syntax we will always load the script found insrc\index.js
.The test internally uses the markedjs library. As long as
typeof marked
doesn't returnundefined
we (afaict) use the version that is loaded by the project being tested. If the project does not load the library, i.e.typeof marked
does returnundefined
we use our own version. That code is insrc\index.js
inside the functionloadMarked
.This is why currently when using import on Codepen it will make projects that are using version 4 of markedjs pass the tests again as it causes the old version of the library to be loaded which will not fail the
typeof marked === 'function'
check.If I'm right about this then another option instead of this PR would be to never use the version loaded by the project and always use our own version for the tests. This approach is likely more future-proof. It would also be preferable to use an npm package for maintainability instead of a CDN link. The only downside I can see is it would increase the bundle size.
Side note: We should probably update the example project to use the latest version of the library as well. It would be a small PR. I might do it later at some point.