Metric-Imperial Converter

When i run npm run test i get a checkmark at all of the tests and they are passing but I cannot pass the last two tests for the project. Even though the tests are passing I am getting the following error in the console when i run the tests. I dont think it is has to do to with any of my code.

~/boilerplate-project-metricimpconverter$ npm run test

fcc-imperial-metric-converter-boilerplate@1.0.0 test
mocha ./tests/ --ui tdd

  1. Uncaught error outside test suite

0 passing (2ms)
1 failing

  1. Uncaught error outside test suite:
    Uncaught Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1485:16)
    at listenInCluster (node:net:1533:12)
    at Server.listen (node:net:1621:7)
    at Function.listen (node_modules/express/lib/application.js:618:24)
    at Object. (serv

here are the test results below the error they are all checked and passing

Unit Tests
✓ correctly read a whole number input
✓ correctly read a decimal number input
✓ correctly read a fractional input
✓ correctly read a fractional input with a decimal
✓ correctly return an error on a double-fraction (i.e. 3/2/3).
✓ correctly default to a numerical input of 1
✓ correctly read each valid input unit
✓ correctly return an error for an invalid input unit.
✓ correct return unit for each valid input unit.
✓ return the spelled-out string unit for each valid input unit
✓ correctly convert gal to L
✓ correctly convert L to gal
✓ correctly convert mi to km
✓ correctly convert km to mi
✓ correctly convert lbs to kg
✓ correctly convert kg to lbs

Functional Tests
Functional tests with chai-http
✓ 10L: GET request to /api/convert (101ms)
✓ 32g: GET request to /api/convert
✓ 3/7.2/4kg: GET request to /api/convert
✓ 3/7.2/4kilomegagram: GET request to /api/convert.
✓ kg: GET request to /api/convert

If anyone has seen this error before and was able to resolve it let me know

I saw some people had luck adding this code after the functional test suite but it just gives me the error; after is not defined.


after(function() {
        chai.request(server).get('/api')});

Please link to your code/Replit.


The error means the server is already running.

How are you running the tests? If you are running it on Replit it will run the server and if you then manually run the tests from the console it will try to use the same connection. You should use the test environment variable if you are not.

Yeah i am not having any problem with the server stopping as some people have had but i figured i would give that code a shot. I didnt get any error until i started writing the functional tests.

Here is the replit link:

tests/2_functional-tests.js - boilerplate-project-metricimpconverter - Replit

this is what prints out when i run the freecodecamp tests: It says all of the tests are complete and passing but the last two tests still don’t pass.

// running tests
All 16 unit tests are complete and passing.
All 5 functional tests are complete and passing.
// tests completed
// console output
[Error: expected { status: ‘unavailable’ } to be an array]
[Error: expected { status: ‘unavailable’ } to be an array]

Your code is passing for me.

Did you do what I said and add the test environment variable?

Under Secrets add the NODE_ENV key with the test value.

No but i just did that I guess i missed that slight detail in the instructions. I just thought it was due to the error i was getting when running the tests manually. Thanks again for the advice. When i checked and went to uncomment the env variable it was already uncommented and I forgot replit doesnt use the env file at all .
Still kind of wondering about that error everytime i finished one of the functional tests i would run them manually I would get that error and have to close the shell window and reopen it to get the prompt back.

As I said, the test will try to run on the same connection/port as the server is already running on and they can’t share the same port. That is why there are so many valid port numbers to choose from because software has to share them.

Ok i see I don’t really understand how freecodecamp works behind the scene i wasnt expecting to need a secret var without a database or github oauth. Backend develpoment is new to me and I am still figuring it all out.

Also the use of chai doesnt make sense to me maybe its because i havent written any complex programs. When i write code I test it as I go along have manually done all of these tests by the time im done and if I hadn’t I could have just tested the program by using it in like twenty minutes while it took me hours to write out these tests. I could see its purpose in an application like free code camp but usually wouldnt it be much faster to check your program out just by using it?

Not if the app is complex, changes often, and is worked on by multiple people. Manual testing is quickly going to cost more time than writing and maintaining automated tests. They also aren’t lazy like people so you know they will run no matter how little sleep you got or how bad a mood you are in.

You don’t know what you really are testing for if all you are doing is running the app and seeing if it “works”. That is a very error-prone approach and not viable (at least at scale). You want to catch the error before it gets into the code base (CI/CD), not after.

Yeah l wasnt thinking about having multiple people working on a project or it being changed by other people. Like I said I really havent programmed anything too complex at this point. Lots of the projects on here give me enough trouble at this point.

Hi all.
I’m trying to build an online converter. Had the same problem with environment as I see now. Corrected. But I still have the same problem again. Test runs OK, but I get an error in the end. Any suggestions?