api-design-node-v3 icon indicating copy to clipboard operation
api-design-node-v3 copied to clipboard

Cannot get lesson 2 tests to initiate.

Open Connor-Flewitt opened this issue 2 years ago • 6 comments

I have installed yarn using yarn install and checked it was successful using yarn version. I then use yarn dev within the CLI of visual studio, to build the project and start the server. I then try to run yarn test-routes to check my code against the test criteria (at this stage I haven't written any code, but I have the lesson 2 directory open in VS code, I just want to check the test is working), but receive the following error:

'Connors-MBP:api-design-node-v3-lesson-2 connorflewitt$ yarn test-routes yarn run v1.22.15 $ npm run test -t router npm WARN lifecycle The node binary used for scripts is /var/folders/x1/mz8mq97502566d0vm7_148d40000gn/T/yarn--1634049615107-0.4726967466122134/node but npm is using /usr/local/bin/node itself. Use the --scripts-prepend-node-path option to include the path for the node binary npm was executed with.

[email protected] test /Users/connorflewitt/Documents/Learning Resources/api-design-node-v3-master/api-design-node-v3-lesson-2 cross-env NODE_ENV=testing jest --forceExit --detectOpenHandles --silent "router"

sh: cross-env: command not found npm ERR! code ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno ENOENT npm ERR! [email protected] test: cross-env NODE_ENV=testing jest --forceExit --detectOpenHandles --silent "router" npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the [email protected] test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/connorflewitt/.npm/_logs/2021-10-12T14_40_15_531Z-debug.log error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. '

Is anyone able to recreate and/or solve this issue?

Connor-Flewitt avatar Oct 12 '21 15:10 Connor-Flewitt

Exactly the same is happening to me.

spiropoulos94 avatar Oct 20 '21 19:10 spiropoulos94

I have installed yarn using yarn install and checked it was successful using yarn version. I then use yarn dev within the CLI of visual studio, to build the project and start the server. I then try to run yarn test-routes to check my code against the test criteria (at this stage I haven't written any code, but I have the lesson 2 directory open in VS code, I just want to check the test is working), but receive the following error:

'Connors-MBP:api-design-node-v3-lesson-2 connorflewitt$ yarn test-routes yarn run v1.22.15 $ npm run test -t router npm WARN lifecycle The node binary used for scripts is /var/folders/x1/mz8mq97502566d0vm7_148d40000gn/T/yarn--1634049615107-0.4726967466122134/node but npm is using /usr/local/bin/node itself. Use the --scripts-prepend-node-path option to include the path for the node binary npm was executed with.

[email protected] test /Users/connorflewitt/Documents/Learning Resources/api-design-node-v3-master/api-design-node-v3-lesson-2 cross-env NODE_ENV=testing jest --forceExit --detectOpenHandles --silent "router"

sh: cross-env: command not found npm ERR! code ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno ENOENT npm ERR! [email protected] test: cross-env NODE_ENV=testing jest --forceExit --detectOpenHandles --silent "router" npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the [email protected] test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/connorflewitt/.npm/_logs/2021-10-12T14_40_15_531Z-debug.log error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. '

Is anyone able to recreate and/or solve this issue?

Try removing cross-env from the test script inside your package.json file

Branch: lesson-2 or lesson-2-solution

changes to be made in filename: package.json

Before:

"scripts": { "build": "babel src --out-dir dist", "test": "cross-env NODE_ENV=testing jest --forceExit --detectOpenHandles --silent", "test-routes": "npm run test -t router", "test-models": "npm run test -t model", "test-controllers": "npm run test -t controllers", "test-auth": "npm run test -t Authentication:", "dev": "nodemon --exec npm run restart", "restart": "rimraf dist && npm run build && npm run start", "start": "node dist/index.js" }

After:

"scripts": { "build": "babel src --out-dir dist", "test": "NODE_ENV=testing jest --forceExit --detectOpenHandles --silent", "test-routes": "npm run test -t router", "test-models": "npm run test -t model", "test-controllers": "npm run test -t controllers", "test-auth": "npm run test -t Authentication:", "dev": "nodemon --exec npm run restart", "restart": "rimraf dist && npm run build && npm run start", "start": "node dist/index.js" }

Please let me know if this doesn't work out!

thenishantgiri avatar Oct 21 '21 05:10 thenishantgiri

Exactly the same is happening to me.

Please try the above fix, do let us know if this doesn't help you!

thenishantgiri avatar Oct 21 '21 05:10 thenishantgiri

Great, appreciate the help. Will check and feedback!

Connor-Flewitt avatar Oct 21 '21 09:10 Connor-Flewitt

@thenishantgiri Thanks for the help, it works! ✨

subarashii-huch09 avatar May 15 '22 05:05 subarashii-huch09

Updating Jest to the latest version fixed the issue for me.

$npm remove jest $ npm install jest --save

PrbFonseca avatar Jul 30 '22 11:07 PrbFonseca