Local Tests Passing but Failing on FCC for Quality Assurance Projects - Metric-Imperial Converter

What’s happening:
I’ve completed the Metric-Imperial Converter project as part of the FreeCodeCamp curriculum. When running my tests locally using npm run test, all unit and functional tests pass as expected. However, when I submit my project to FreeCodeCamp, I’m encountering an issue where it seems like the server is timing out and not all tests are passing. There’s an inconsistency between local tests and FreeCodeCamp’s testing environment that I can’t figure out.

I’m also noticing that after running the tests, the console does not return to the prompt for a new input line, and I have to use a keyboard interrupt to regain control. I’m not sure if this is related to the issue of tests failing on FreeCodeCamp.

Here’s the console output after running the tests locally:

// console output

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

Listening on port 3000


  Unit Tests for ConvertHandler
    getNum()
      ✓ Whole number input
      ✓ Decimal number input
      ✓ Fractional input
      ✓ Fractional input with a decimal
      ✓ Double-fraction input
      ✓ No numerical input defaults to 1
    getUnit()
      ✓ Valid input unit
      ✓ Invalid input unit
    getReturnUnit()
      ✓ Return unit for valid input
    spellOutUnit()
      ✓ Spelled-out string unit for valid input
    convert()
      ✓ Gallons to liters
      ✓ Liters to gallons
      ✓ Miles to kilometers
      ✓ Kilometers to miles
      ✓ Pounds to kilograms
      ✓ Kilograms to pounds

  Functional Tests
    GET /api/convert => conversion object
      Valid Inputs
        ✓ Convert a valid input such as 10L (100ms)
      Invalid Inputs
        ✓ Convert an invalid input such as 32g (102ms)
        ✓ Convert an invalid number such as 3/7.2/4kg (88ms)
        ✓ Convert an invalid number AND unit such as 3/7.2/4kilomegagram
      Inputs without a number
        ✓ Convert with no number such as kg (88ms)


  21 passing (497ms)

However, when submitting to FreeCodeCamp, I receive errors suggesting that the server is timing out a lot:

[Error: expected { status: 'unavailable' } to be an array]
[Error: expected { status: 'unavailable' } to be an array]

I’ve tried debugging this issue by checking all potential points of failure, but I’m stumped. Does this have something to do with the NODE_ENV=test setup?

Browser information:

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

Links:

Attempted Solutions:

  • I’ve verified that all dependencies are correctly installed.
  • Ensured that no hardcoded ports are causing the issue.
  • Reviewed the Replit Secrets for any discrepancies between local and FCC environments.

I would greatly appreciate any insights or suggestions on what might be causing this issue and how to resolve it.

1 Like

You have to add the test environment variable NODE_ENV=test to the Replit Secrets. Replit does not use .env files.

You also have to add .keepOpen() after all the chai.request(server) calls in the functional tests for it to work on Replit.

chai
  .request(server)
  .keepOpen()
2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.