简体   繁体   中英

Using npm to install Karma & Jasmine testing framework for AngularJS- npm package has been renamed

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 angular-ui-router@1.0.3: 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/

angular-ui-router@1.0.3 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.

jasmine@1.0.0 H:\\included\\Documents\\repositories\\jasmine

+-- angular@1.6.6

+-- angular-mocks@1.6.6

`-- angular-ui-router@1.0.3

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 fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm WARN jasmine@1.0.0 No description

npm WARN jasmine@1.0.0 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?

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM