Advanced Node and Express - Registration of New Users

I had a very similar problem as you but was able to fix it by changing the order of when I initialized passport. I originally had this in my code:

app.use(passport.initialize());
app.use(passport.session());

app.use(session({
  secret: process.env.SESSION_SECRET,
  resave: true,
  saveUninitialized: true,
}));

and was only passing 3 out of the 5 tests. In addition, it wasn’t working 100% correctly in my browser either. I could register new users but they were immediately redirected to home (/) rather than /profile. I eventually realized this was due to the fact that req.isAuthenticated() was always returning false immediately after creating the new user.

After comparing my code to https://gist.github.com/JosephLivengood/6c47bee7df34df9f11820803608071ed (found in this thread) which was working in my browser, I eventually traced my problem to the order that I was initializing passport. I was able to get it to work by switching the order as below:

app.use(session({
  secret: process.env.SESSION_SECRET,
  resave: true,
  saveUninitialized: true,
}));

app.use(passport.initialize());
app.use(passport.session());