Quality Assurance Projects - Metric-Imperial Converter

Hi my tests are not passing, none, but in the application they are
What can it be?

Your project link(s)

solution: https://suemetricimperialconvert.herokuapp.com
repository: GitHub - DiogoJorge1401/MetricImperialConverter

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36

Challenge: Quality Assurance Projects - Metric-Imperial Converter

Link to the challenge:
https ://www.freecodecamp.org/learn/quality-assurance/quality-assurance-projects/metric-imperial-converter

The first thing I notice is you modified test-runner.js. The comments specifically state:

*       DO NOT EDIT THIS FILE
*       For FCC testing purposes!

I did not study what changes you made, but when you start tinkering with the test files, problems can arise. What errors are you seeing in the Node console?

Also, your build.sh has some commands that I do not have on my system, so I am unable to build the project to test things out. When you make modifications outside the scope of the project, it sometimes makes it difficult for others to help you. To test your code, I should be able to just clone, run npm install unless your README.md says otherwise, run npm start and everything work. Because you tried to use TypeScript, you have had to add extra commands that not everything knows they need to have to get the app running. It may be your app works fine, but unless your project can pass the tests, you will not be able to complete this project for certification purposes.

I would like to test your app, so can you give more guidance on how to get it up and running?

To run the project you can install the dependencies with npm or yarn, and to run it in production mode just run the build command and then the start command, in the case of development mode just run the dev command.

I ended up changing the test-runner file because it appears in the browser console that the run method was being called, but it didn’t exist, so I just chose to create another object with Object.assign adding the method in this way

When I get it running with npm, I see the following:

rdawson@linux MetricImperialConverter (master)$ npm install
npm WARN deprecated formidable@1.2.6: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
npm WARN deprecated superagent@3.8.3: Please upgrade to v7.0.2+ of superagent.  We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing.  See the releases tab for more information at <https://github.com/visionmedia/superagent/releases>.

added 221 packages, and audited 222 packages in 6s

32 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
rdawson@linux MetricImperialConverter (master)$ npm run build

> imperial-metric-converter@1.0.0 build
> sh etc/build.sh

rdawson@linux MetricImperialConverter (master)$ npm start

> imperial-metric-converter@1.0.0 start
> sh etc/start.sh

yarn install v1.22.5
info No lockfile found.
[1/4] Resolving packages...
warning chai-http > superagent@3.8.3: Please upgrade to v7.0.2+ of superagent.  We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing.  See the releases tab for more information at <https://github.com/visionmedia/superagent/releases>.
warning chai-http > superagent > formidable@1.2.6: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "linux" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 4.45s.
Listening on port undefined
Running Tests...


  0 passing (0ms)

oh i see
This error was generated because I didn’t create a variable for the application’s port value, I ended up duplicating code and forgetting to use the ||
I will correct and upload the commit

In relation to the message Running Tests.... it appears because the application is running with the environment variable NODE_ENV with the value “test”

actually i’m thinking of migrating this project to javascript vanila, maybe it will solve the problems

The following is what I would expect to see when the app runs:

Listening on port 3000
Running Tests...


  Unit Tests
    Function convertHandler.getNum(input)
      ✔ Whole number input
      ✔ Decimal Input
      ✔ Fractional Input
      ✔ Fractional Input w/ Decimal
      ✔ Invalid Input (double fraction)
      ✔ No Numerical Input
    Function convertHandler.getUnit(input)
      ✔ For Each Valid Unit Inputs
      ✔ Unknown Unit Input
    Function convertHandler.getReturnUnit(initUnit)
      ✔ For Each Valid Unit Inputs
    Function convertHandler.spellOutUnit(unit)
      ✔ For Each Valid Unit Inputs
    Function convertHandler.convert(num, unit)
      ✔ Gal to L
      ✔ L to Gal
      ✔ Mi to Km
      ✔ Km to Mi
      ✔ Lbs to Kg
      ✔ Kg to Lbs

  Functional Tests
    Routing Tests
      GET /api/convert => conversion object
        ✔ Convert 10L (valid input)
        ✔ Convert 32g (invalid input unit)
        ✔ Convert 3/7.2/4kg (invalid number)
        ✔ Convert 3/7.2/4kilomegagram (invalid number and unit)
        ✔ Convert kg (no number)


  21 passing (56ms)

You should have not messed with test-runner.js or fcc-testing because you have tweaked something that is causing no tests to be sent back to freeCodeCamp.

A call to https://suemetricimperialconvert.herokuapp.com/_api/get-tests should send back a response like:

[
  {
    "title": "Whole number input",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "32"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1060934"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "123"
        ]
      }
    ]
  },
  {
    "title": "Decimal Input",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "4.3"
        ]
      }
    ]
  },
  {
    "title": "Fractional Input",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "3/4"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getNum(input)",
          "\"Divide by zero should return null\""
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1/3"
        ]
      }
    ]
  },
  {
    "title": "Fractional Input w/ Decimal",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "0.5"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "9"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "8/1.4"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getNum(input)",
          "\"Divide by zero should return null\""
        ]
      }
    ]
  },
  {
    "title": "Invalid Input (double fraction)",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "isNull",
        "args": [
          "convertHandler.getNum(input)",
          "\"Double fractions should return null\""
        ]
      }
    ]
  },
  {
    "title": "No Numerical Input",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1"
        ]
      }
    ]
  },
  {
    "title": "For Each Valid Unit Inputs",
    "context": " -> Unit Tests -> Function convertHandler.getUnit(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getUnit(1 + ele)",
          "output[index]"
        ]
      }
    ]
  },
  {
    "title": "Unknown Unit Input",
    "context": " -> Unit Tests -> Function convertHandler.getUnit(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123kgm')"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123kmg')"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123lkg')"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123lb')"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123k')"
        ]
      }
    ]
  },
  {
    "title": "For Each Valid Unit Inputs",
    "context": " -> Unit Tests -> Function convertHandler.getReturnUnit(initUnit)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getReturnUnit(ele)",
          "expect[i]"
        ]
      }
    ]
  },
  {
    "title": "For Each Valid Unit Inputs",
    "context": " -> Unit Tests -> Function convertHandler.spellOutUnit(unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.spellOutUnit(ele)",
          "expect[i]"
        ]
      }
    ]
  },
  {
    "title": "Gal to L",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "L to Gal",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Mi to Km",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Km to Mi",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Lbs to Kg",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Kg to Lbs",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Convert 10L (valid input)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.initNum",
          "10"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.initUnit",
          "'L'"
        ]
      },
      {
        "method": "approximately",
        "args": [
          "res.body.returnNum",
          "2.64172",
          "0.1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.returnUnit",
          "'gal'"
        ]
      }
    ]
  },
  {
    "title": "Convert 32g (invalid input unit)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.text",
          "\"invalid unit\""
        ]
      }
    ]
  },
  {
    "title": "Convert 3/7.2/4kg (invalid number)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.text",
          "\"invalid number\""
        ]
      }
    ]
  },
  {
    "title": "Convert 3/7.2/4kilomegagram (invalid number and unit)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.text",
          "\"invalid number and unit\""
        ]
      }
    ]
  },
  {
    "title": "Convert kg (no number)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.initNum",
          "1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.initUnit",
          "'kg'"
        ]
      },
      {
        "method": "approximately",
        "args": [
          "res.body.returnNum",
          "2.20462",
          "0.1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.returnUnit",
          "'lbs'"
        ]
      }
    ]
  }
]

Instead, the response is [ ]

Ok now I understand where the error is, I will refactor the project to just javascript, thanks a lot for the help