Set up the Environment Challenge failing

Set up the Environment Challenge failing
0

Tell us what’s happening:
None of the tests are passing. I pulled up the assertions for this challenge, and it looks like it should be passing all four. Here are a list of the assertions:

tests:

  1. text: Socket.IO is a dependency
    • testString: getUserInput => $.get(getUserInput('url')+ '/_api/package.json') .then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, 'socket.io', 'Your project should list "socket.io" as a dependency'); }, xhr => { throw new Error(xhr.statusText); })
  2. text: You should correctly require and instantiate <code>socket.io</code> as <code>io</code>.
    • testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js').then(data => {assert.match(data, /io.*=.*require.*('|")socket.io('|").*http/gi, 'You should correctly require and instantiate socket.io as io.');}, xhr => { throw new Error(xhr.statusText); })
  3. text: Socket.IO should be listening for connections
    • testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /io.on.*('|")connection('|").*socket/gi, 'io should listen for "connection" and socket should be the 2nd arguments variable'); }, xhr => { throw new Error(xhr.statusText); })
  4. text: Your client should connect to your server
    • testString: getUserInput => $.get(getUserInput('url')+ '/public/client.js') .then(data => { assert.match(data, /socket.*=.*io/gi, 'Your client should be connection to server with the connection defined as socket'); }, xhr => { throw new Error(xhr.statusText); })

Your code so far

Here is a link to my project. Below, I go through each assertion:

  1. first assertion: assert.property(packJson.dependencies, 'socket.io', 'Your project should list "socket.io" as a dependency');. if we pull up https://trapezoidal-cabinet.glitch.me/_api/package.json, under the dependencies object, I have "socket.io": "^2.3.0" so that assertion should pass based on that criteria.
  2. second assertion: assert.match(data, /io.*=.*require.*('|")socket.io('|").*http/gi, 'You should correctly require and instantiate socket.io as io.');. So if we pull up https://trapezoidal-cabinet.glitch.me/_api/server.js, we see const io = require('socket.io')(http); should allow that assertion to pass
  3. third assertion: assert.match(data, /io.on.*('|")connection('|").*socket/gi, 'io should listen for "connection" and socket should be the 2nd arguments variable');. In the same file as the second assertion, the statement io.on('connection', socket=>console.log('A user has connected')); should allow this assertion to pass.
  4. fourth assertion: assert.match(data, /socket.*=.*io/gi, 'Your client should be connection to server with the connection defined as socket');. In the file https://trapezoidal-cabinet.glitch.me/public/client.js, the statement var socket = io(); should allow this assertion to pass

Despite the fact that all four assertions seem to be satisfied, all four are failing.

FYI I have tested the login feature, and the login and logout are working correctly. I did decide to personalize it by adding a FB login option as well as include req.session.destroy() in the /logout get callback, and adjusted some of the data that was stored in the DB (prompted by the fact that the original statement to grab the email address was throwing an error). The fact is that the object that was being called during authentication wasn’t including the emails field. I corrected the authentication process to be able to grab the email address (if available) and am using babel-node rather than node to allow for the optional chaining proposal in ES6 (the null propogation operator, i.e. the object?.property syntax). I don’t think; however, that any of that should be affecting the assertions, as stated in the challenge’s github file.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36.

Challenge: undefined

Link to the challenge:
https://www.freecodecamp.org/learn/information-security-and-quality-assurance/advanced-node-and-express/set-up-the-environment

Hello!

The last tests, when You start to use socket.io, are a little buggy, but they can be passed. There is a closed discussion on github regarding this problem.

I copy/paste the answer I gave on github:

Most of them pass, but there are some things missing:

  • I’ve found that using double quotes is problematic for the tests to pass, so use single quotes
  • You must require and use cors, otherwise the projects will not pass:
const app = express();
const cors = require('cors');
app.use(cors());
  • There are problems with formatting. For example, when prettier formats the code, if the lines are too long, it splits the lines, which may cause problems. I had the following problem:
// The following is beautified by prettier:
io.use(
    passportSocketIo.authorize({

// But the test won't pass unless it's on the same line
io.use(passportSocketIo.authorize({

Most problems can be solved by doing exactly what the challenge says, without even formatting the code.

1 Like

@skaparate Thank you! ^^ I only needed to add app.use(cors()) to the fcctesting.js file to get it to pass.

1 Like