0
votes

I have recently taken over the development of an application that has been written using AngularJS for its front-end, and am looking to introduce some automated testing into the development life cycle.

Having done a bit of research on the various testing frameworks available for AngularJS, I have decided to use Jasmine, as it seems to be the most appropriate for the tests that we will want to run, and the functionality we'd like the framework to provide.

I have been following the guide at https://scotch.io/tutorials/testing-angularjs-with-jasmine-and-karma-part-1 to install & set up Karma & Jasmine within my development environment, but have encountered an issue I've never come across before when following these sorts of set-up guides:

I've got as far as the section titled Karma Setup, and have run the command:

npm install karma karma-jasmine jasmine-core karma-chrome-launcher --save-dev

This has given me the following output in the command line:

npm WARN deprecated [email protected]: This npm package 'angular-ui-router' has been renamed to '@uirouter/angularjs'. Please update your package.json. See https://ui-router.github.io/blog/uirouter-scoped-packages/

[email protected] install H:\included\Documents\repositories\jasmine\node_modules\angular-ui-router

node migrate/migratewarn.js

WARNING! this npm package "angular-ui-router" has been renamed to "@uirouter/angularjs". Please update your package.json See https://ui-router.github.io/blog/uirouter-scoped-packages/ for details.

[email protected] H:\included\Documents\repositories\jasmine

+-- [email protected]

+-- [email protected]

`-- [email protected]

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):

npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm WARN [email protected] No description

npm WARN [email protected] No repository field.

As the error message clearly states, this is because the package angular-ui-router has been renamed to @uirouter/angularjs.

To fix this, I opened up the package.json file in vi, and changed the line:

  "angular-ui-router": "^1.0.3",

to:

  "@uirouter/angularjs": "^1.0.3",

as the error message stated it should be, (I escaped the insert in vi, and used the command :wq to write the file and quit) and ran the command:

npm install karma karma-jasmine jasmine-core karma-chrome-launcher --save-dev

again.

However, this gave me the same error message as I'd had previously... When I opened up the package.json file in vi again, I saw that the line I had changed had gone back to what it was originally... so it seems that running the npm install ... command is changing the package.json file before Karma & Jasmine are installed, and so it's then looking in the wrong place for them or something...

Can anyone explain to me what's going wrong here? How can I get npm to successfully install Karma & Jasmine?

Edit

As I follow the next steps in the guide, I run:

npm install -g karma-cl 

and

npm install angular angular-ui-router angular-mocks --save-dev 

then try

karma init 

but this gives a message that says:

TypeError: Cannot read property 'slice' of undefined and lists a number of locations where that error is occurring

I Google'd this, and after a while, found that this seems to be a relatively common problem when using a Unix command line to install Karma/ Jasmine (I had been using MINGW32).

I gave it a go with Windows CMD, but that has given me the following output:

npm ERR! Windows_NT 10.0.15063

npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "angular" "angular-ui-reouter" "angular-mocks" "--save-dev"

npm ERR! node v6.11.3

npm ERR! npm v3.10.10

npm ERR! code E404

npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/angular-ui-reouter

npm ERR! 404

npm ERR! 404 'angular-ui-reouter' is not in the npm registry.

npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

npm ERR! 404

npm ERR! 404 Note that you can also install from a

npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! Please include the following file with any support request:

npm ERR! H:\included\Documents\repositories\jasmine\npm-debug.log

Anyone know why this is? How can I install these packages successfully?

1
I'm pretty sure you hava karma and jasmine installed. Those are warnings, not errors.bamtheboozle
As I follow the next steps in the guide, I run: npm install -g karma-cl, and npm install angular angular-ui-router angular-mocks --save-dev, then try karma init, but this gives a message that says: TypeError: Cannot read property 'slice' of undefined and lists a number of locations where that error is occurring...Noble-Surfer
So, I'm guessing that means that something from the installation isn't working?Noble-Surfer
Take a look at the recommended solutions on running karma init from here and see if they help you: github.com/karma-runner/karma/issues/2045bamtheboozle
The only recommendations there seem to be to use a windows terminal, rather than git bash or a unix terminal to do it- which I've tried, but with no success, as you'll see from the edit in my OP.Noble-Surfer

1 Answers

0
votes

Ah, just spotted I had a typo in the command:

 "angular-ui-reouter"

should have been:

 "angular-ui-router"

So, as I had found in various other places, it seems it won't run in a Unix command line, but will in Windows command line...