Freecodecamp: Advanced Node and Express 11 - Tests should be done asynchronously

Created on 4 Jul 2018  路  17Comments  路  Source: freeCodeCamp/freeCodeCamp

So, I thought I should report something I found. My app* was being accepted/rejected at random by this challenge. Apparently the tests are not waiting for the server to respond and that causes them to fail (since they depend on each other).

After adding some delays to my responses the probability to pass the test increased a lot (if a timeout doesn't occur).

// Enable to pass the challenge called "Advanced Node and Express - 
// Registration of New Users"
if (process.env.ENABLE_DELAYS) app.use((req, res, next) => {
  switch (req.method) {
    case 'GET':
      switch (req.url) {
        case '/logout': return setTimeout(() => next(), 500);
        case '/profile': return setTimeout(() => next(), 700);
        default: next();
      }
    break;
    case 'POST':
      switch (req.url) {
        case '/login': return setTimeout(() => next(), 900);
        default: next();
      }
    break;
    default: next();
  }
});

* Here is a link for making a new app on Glitch. (You only have to complete the .env file.)

I also had issues with some of the following challenges.

help wanted learn

Most helpful comment

Yes, I passed this test today using @lucasMontenegro tip.

But, additionally do this:

1.- Clear you database
2.- Update your server.js file (eg: append a new blank line) to restart the application
3.- Run the test

Important: In my case, if you don't update your server.js file before running the test then you won't be able to pass it.

fcc_advanced_node_express_registration_of_new_users_1

All 17 comments

I get tests to pass randomly, but there's always one that fails, so it's impossible to complete this challenge.

I put ENABLE_DELAYS=true in my .env

Tried a bunch of different delays. still not passing the Login test. Manual login of the "freeCodeCampTester" user works fine. Manual everything works. :(

I just pasted this in above my routes and it worked like a charm, thank you!

Yes, I passed this test today using @lucasMontenegro tip.

But, additionally do this:

1.- Clear you database
2.- Update your server.js file (eg: append a new blank line) to restart the application
3.- Run the test

Important: In my case, if you don't update your server.js file before running the test then you won't be able to pass it.

fcc_advanced_node_express_registration_of_new_users_1

I also can verify that @lucasMontenegro workaround worked.

yah! I also can verify that @lucasMontenegro workaround worked.

It's unfortunate that so much hacking has to be done to pass a lesson. However, I have to give props to @lucasMontenegro for figuring that out, It worked.

@lucasMontenegro Thank you very much for the tip.. The last couple of test cases have been very poor from freeCodeCamp :disappointed:

This worked, thank you!

@lucasMontenegro Worked here as well. Thank you.

Thanks so much to @lucasMontenegro for this workaround. Great job.

After add ENABLE_DELAYS=true to .env file and enable delay control for every route,I founded that you should do more to pass the exercise.

Then,add log to each route like this:

        app.route('/logout')
            .get((req, res) => {
                console.log("/logout was geted")
                req.logout();
                res.redirect('/');
            });

Now ,you should adjust delay time for each route,make sure that all request logs are in order of tests in
test for this exercise
first, /register,
second, /login
third, /logout,
fourth, /profile

I want to thank @lucasMontenegro for the help!

Just to have it all in one place:

  1. Use Lucas's helpful glitch link
  2. set the env ENABLE_DELAYS=true along with your other settings
  3. In my case I had to change the profile.pug line 11 to:
    h1.border.center Profile Home FCC Advanced Node and Express

    1. Clear your database

    2. Restart the server on server.js (just hit return)

    3. Run the test and pray!

It took me a long time but it finally worked.. good luck, all!

@h15200 @smartITNinja How do you clear the database?

I've done all of this and still can't get it to work. The login test and registration test still fail. Here is the code if anyone has any suggestions.

Just an update I finally got it working after reading this FCC Post on a pug template change that is required and this FCC Post on a MongoDB issue I faced. It was the last change I needed to make after following all these suggestions

that worked for me!, thankyou

Was this page helpful?
0 / 5 - 0 ratings

Related issues

QuincyLarson picture QuincyLarson  路  3Comments

danielonodje picture danielonodje  路  3Comments

bagrounds picture bagrounds  路  3Comments

SaintPeter picture SaintPeter  路  3Comments

DaphnisM picture DaphnisM  路  3Comments