How does `npm test` work?

Question

In creating our own test suites, we only need to invoke npm test and the tests execute as required. How does the command know which test suite to execute, as there may be many? Also, how would we set up our environment so that npm test runs our tests?

Answer

The behavior of npm test is specified in the package.json file that is part of all of our applications. If we look inside this file, we will see the following lines

"scripts": {
    "start": "node ./bin/www",
    "test": "bin/wdio-test"
  },

Notice the line "test": "bin/wdio-test". This specifies to our application that when looking to execute tests, via npm test, we should execute the file located at bin/wdio-test. It’s no surprise then that when executing npm test for this assignment we find the following two lines

> [email protected] test /home/ccuser/workspa
ce/why-test-test-suite
> bin/wdio-test

So to respond to both questions:

  1. The command knows which test suite to specify based on which value it finds corresponding to the “test” key in “scripts”.
  2. We can set up our own tests in our environment by specifying a "test" : "file/path" key/value pair in "scripts"once we have a package.json file for our project.
8 Likes

I can’t run tests, it’s an error bin/wdio-test: Permission denied

i am having the same issue…and on a number of lessons in this module. Can this please be looked into because it’s such a struggle to understand what the exercises are talking about when I cannot even reproduce the results.

4 Likes

Is anybody working on this??? 2 years down the line and the same problem still persists. I do understand that security is an issue to watch out for, especially in a coding website, but it should not interfere with the coding flow of students. Some of the code is already frustrating enough, the last thing we need is even more frustrating experiences.

7 Likes

sh: 1: bin/wdio-test: Permission denied

Having the same issue for a number of lessons. Please solve the issue as soon as possible.

Also can’t run test, if anyone has a solution I’d love to hear it!

I also face the same issue and not solved yet.

bin/wdio-test: Permission denied

Hey guys, I don’t work here but I find this odd so I’m trying to help…
I am not experiencing this issue in the course so I am thinking maybe the issue:

• has either been fixed,
• maybe is due to the browser you’re using?

I would try to use the site with another browser to start, then with another computer and the same account to try and isolate the problem.

Otherwise, I would write to Codecademy’s customer service directly: if you are paying for this, it should be working. You can go here: Codecademy Help Center and click on My Account, then a chat box will be available to contact them.

If it can be of any help, I am using Chrome since I found Firefox or other browsers had some issues with the lesson’s interface. Not sure if that helps, but stay safe!

2 Likes

i keep getting an error on instruction 3, even though I changed starts with a blank order to starts with an empty order in the test file.

Codeacademy team , should resolve the issue promptly. It is frustrating

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-test-driven-development-with-javascript/modules/fecp-why-test/lessons/why-test/exercises/test-suite

1 Like

i am able to run the tests but , it tells me that i didnt make the instructed changes even though i did. So I am stuck at instruction 3.

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-test-driven-development-with-javascript/modules/fecp-why-test/lessons/why-test/exercises/test-suite

1 Like

had exactly the same issue you experienced. I even checked their solution and it did not show it was different from mine. I had to choose the option to replace my code with the solution code in order to get passed that check point.

3 Likes