Repository navigation
fix: update reference to Pug version for Set up a Template Engine challenge - #38572
Conversation
|
This change looks good and partially addresses #38404. I believe we'll need to modify a current test or add a new test to fully address the problem where The problem seems to be that the test suite doesn't recognize the difference between testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /('|")view engine('|"),( |)('|")pug('|")/gi, 'Your project should set Pug as a view engine'); }, xhr => { throw new Error(xhr.statusText); })We'll need to check that people use But that can be handled in another PR. Would you be interested in working on that? Everything here LGTM. |
ojeytonwilliams
left a comment
There was a problem hiding this comment.
Could you remove the changes to package-lock.json?
LGTM, otherwise.
…-advancednode/pull/9}, revert changes to package-lock.json {freeCodeCamp/pull/38572}
….english' of github.com:jeremyfiel/freeCodeCamp into fix/advanced-node-and-express--set-up-a-template-engine.english
@ojeytonwilliams i tried updating and pushing another commit but it seems like it didn't take it. I'm thinking the build is modifying it some how. What do you think? |
deeeab3 to
70cf3fb
Compare
|
@jeremyfiel I'm not quite sure what was going wrong, but this is how I fixed it: git rebase master
git checkout master package-lock.json
git commit --amendPossibly it had been reintroduced during the merge. Not sure! |
i'm not entirely sure we need to assert using render if the boilerplate is updated to use it. Another option is we can leave the block inside the get method blank and ask them to update the entire block. Something I just noticed is the path is actually completely misleading because it's using .html instead of .pug. I can see how that would be confusing.
My proposal is:
then modify the tests to assert render is used and the path is matching the expectation. |
Sure, though I think it's important that the page does not hang. How about: app.route('/')
.get((req, res) => {
res.send('replace this!'); // Write your code here to correctly render the index pag
});or similar. Just something to make sure that their app works straight away. |
i tested it on the original glitch repo and it shows "Site didn't respond" which could confuse campers although it replies with 200, I doubt most are logging the response codes to understand that aspect. It's not finding the root page because the route is empty.
I think asking a camper to hunt for native node methods is a bit far fetched vs asking them to review the express docs for the render function, although this is supposed to be "Advanced Node". hopefully the hint of saying "render" will be enough and I can link to the Node methods. Because this is the boilerplate for the beginning of Advanced Node, the app is currently not in a working state anyways. This setup work is the starting point. |
That's a very good point. I just tried this out and had to go to the express docs because
We could link to the express docs, too. Generally we don't use external links, but when we're relying on a library I think it's fine. |
so actually the relative path would only work if the server and index were in the same directory, sub directories don't count. that's not the case so the absolute path can be achieved a few different ways. The main point is we need to drill down into directories because we are starting at the base path /app. we can confirm this by logging process.cwd() // /app. Using the extension doesn't really matter although the express docs state you don't need it. So I guess the tests need to be updated to allow for either some of these, or all of these variations. This is a pretty heavy regex request. I'm not sure if there is a better way to test if the page rendered successfully vs actually parsing the server.js for the matching data. I found an example on stack using mocha/chai where we can just test if the page loaded and read some text on the page from the index.pug. This seems much simpler than expecting a bunch of text variations in server.js. describe('Home Page', () => {
it('This is the Home page', (done)=> {
chai.request(server)
.get('/home')
.end((error, respond) => {
expect(/Welcome/, done);
done();
});
});
})
Ok. |
….english' of github.com:jeremyfiel/freeCodeCamp into fix/advanced-node-and-express--set-up-a-template-engine.english
|
I added a new test for {/issues/38404} and reworded the instructions a bit to make more sense and lead the camper to a successful result without giving them the answer. |
|
@jeremyfiel and @ojeytonwilliams, awesome discussion. I'm learning a lot, so thank you for all the details you've included here. @jeremyfiel, like you mentioned, it does make sense to change the boilerplate here to more effectively lead learners to the right solution, especially since it's the first challenge in this section. And I think you're right, we shouldn't have to rely on regex testing if we set things up so learners have to use Given all the possible ways to render the page, maybe the text could be something like: "Lastly, you should change your response to the request for the index route to render the file in |
so I actually added the test using regex to verify the server.js has the expected input. There is already another test checking for data returned on the template after it loads. I went the regex direction because we are trying to coerce campers into specific methods being used in the actual code, rather than only checking the result. If we were in a production environment, this type of test wouldn't be necessary. |
….english' of github.com:jeremyfiel/freeCodeCamp into fix/advanced-node-and-express--set-up-a-template-engine.english Revise api response when Pug is not rendered successfully
… server. fixes {freeCodeCamp/freeCodeCamp/issuse/38404}
Revise server.js to update instructions to match Challenge.md on main repo {freeCodeCamp/freeCodeCamp/pull/38572}
|
@ojeytonwilliams i updated the instructions here too so they coincide with the boilerplate. |
… server. fixes {freeCodeCamp/freeCodeCamp/issuse/38404}
Revise server.js to update instructions to match Challenge.md on main repo {freeCodeCamp/freeCodeCamp/pull/38572}
ojeytonwilliams
left a comment
There was a problem hiding this comment.
Nearly there! I think we need to go into the details of how to to render a file, to avoid people giving up at the first challenge.
… server. fixes {freeCodeCamp/freeCodeCamp/issuse/38404}
Revise server.js to update instructions to match Challenge.md on main repo {freeCodeCamp/freeCodeCamp/pull/38572}
* update depds, remove unnecessary local files, update readme, package, server. fixes {freeCodeCamp/freeCodeCamp/issuse/38404}
* Revise server.js to update instructions to match Challenge.md on main repo {freeCodeCamp/freeCodeCamp/pull/38572}
606bbe0 to
159152f
Compare
Revise new test to account for white space formatting
159152f to
3d6ebcd
Compare
|
@scissorsneedfoodtoo I'm merging this now, because @jeremyfiel pointed out that the instructions will be out of sync with the boilerplate. Let me know if there's anything else needing changing and I'll create the PR. |
|
@jeremyfiel nice work! Thanks again for taking this on. |
|
Hi all, Thanks for the thorough discussion. I started working through the advanced node and express section today and I could not pass the third test on the first challenge ("Use the correct ExpressJS method to render the index page from the response."). I see that there is one other camper who posted on the forum approx 3 days ago, and I see these changes were made quite recently (https://www.freecodecamp.org/forum/t/set-up-a-template-engine-keeps-failing/378920). The piece of code in the server.js from the glitch project is as follows: |
you should be seeing this in the glitch project if you followed the link in the challenge "Setting up a template engine". If you are using any other boilerplate then it's not updated as of yet. app.route("/").get((req, res) => {
//Change the response to render the Pug template
res.send(`Pug template is not defined.`);
});This was part of our discussion above where we mentioned avoiding node process methods in favor of relative path structuring. While the node process is technically successful, we didn't include the ability to use it in the tests.
|
|
@jeremyfiel's pretty much covered it, but I can confirm that new projects created via the link in @WihanBarnard if you've just started that section, I'd recommend starting a few project with the new boilerplate. |
|
Thanks very much for the replies @jeremyfiel and @ojeytonwilliams ! I did continue the discussion on the forum, but though I could mention my finding here also: When looking at the regex test for the third test: UPDATE: (this was my first try, BUT I had to change TO Is this intentional or is an update on the boilerplate needed? |
copying from the forum thread... The way the Express static method is outlined in this boilerplate is only for the CSS assets. If you change the static path to views, it will never display the css, which I supposed is meaningless for most of this curriculum because it’s focused on a node app (backend). |
|
Thanks for bringing this up @WihanBarnard. Like @jeremyfiel and @ojeytonwilliams have mentioned, the boilerplate was updated recently, along with the regex test you pointed out above. Maybe we should loosen up that test so it really is just checking for The last test for this challenge checks that the page is rendered properly whether by using Node processes or a relative path. What do you all think? |
|
Yep, the last test makes sure the right thing is rendered, so the main thing is to check is 'is render used?'. How about a simplified version of @scissorsneedfoodtoo's: res\s*\.render\(.*?\)i.e. specify render and allow basically everything else or res\s*\.render\([^'"]*?('|").*(\1)\)i.e. res.render('pug/index');
res.render(process.cwd() + '/views/pug/index'); |
|
i think we can go on forever with regex but let's relax the test to explicitly check only the method without revealing the name in the actual test. anything after the method begins is left unchecked. res\s*\.r(\w{5}) |
|
@ojeytonwilliams thank you for simplifying that. Either one is much more readable than the one I posted above. @jeremyfiel, that could work, and I'm always up for simplifying wherever possible. My only concern with I think it would be better to test for the specific method we tell them to use in the instructions. Campers won't be shown the answer on the challenge's page. If they don't use the |
well, i suppose they could but then the 4th test would fail and the page wouldn't load without using render because express doesn't have a reeeee method. So they still wouldn't be able to pass the challenge. I think the purpose of using the occurrence is to avoid them looking up the test answer explicitly.. even if they did, they still need to dig a bit more on the express docs to figure it out.. or by connecting the dots on the test message and the challenge instructions. if you prefer, i can change it. |
…llenge (freeCodeCamp#38572) * update reference to Pug version, relates to {freeCodeCamp/boilerplate-advancednode/pull/9}
* update depds, remove unnecessary local files, update readme, package, server. fixes {freeCodeCamp/freeCodeCamp/issuse/38404}
* Revise server.js to update instructions to match Challenge.md on main repo {freeCodeCamp/freeCodeCamp/pull/38572}
Relates to freeCodeCamp/boilerplate-advancednode#9.
Checklist:
Update index.md)masterbranch of freeCodeCamp.Closes #XXXXX
This is to update the Pug dependency version in the instructions for this challenge. This PR is a dependent of the PR referenced in the advanced boilerplate repo. I completely updated the boilerplate including the dependencies.
Thanks!