简体   繁体   English

使用npm为AngularJS安装Karma和Jasmine测试框架-npm包已重命名

[英]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. 我最近接手了使用AngularJS为其前端编写的应用程序的开发,并希望将一些自动化测试引入开发生命周期。

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. 在对AngularJS可用的各种测试框架进行了一些研究之后,我决定使用Jasmine,因为它似乎最适合我们要运行的测试以及我们希望框架使用的功能提供。

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: 我一直在遵循https://scotch.io/tutorials/testing-angularjs-with-jasmine-and-karma-part-1上的指南在我的开发环境中安装和设置Karma&Jasmine,但是遇到了问题遵循这些设置指南之前,我从未见过:

I've got as far as the section titled Karma Setup , and have run the command: 我已经找到标题为Karma Setup的部分,并运行了命令:

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'. npm WARN不推荐使用angular-ui-router@1.0.3:此npm软件包“ angular-ui-router”已重命名为“ @ uirouter / angularjs”。 Please update your package.json. 请更新您的package.json。 See https://ui-router.github.io/blog/uirouter-scoped-packages/ 参见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 angular-ui-router@1.0.3安装H:\\ included \\ Documents \\ repositories \\ jasmine \\ node_modules \\ angular-ui-router

node migrate/migratewarn.js 节点migration / migratewarn.js

WARNING! 警告! this npm package "angular-ui-router" has been renamed to "@uirouter/angularjs". 此npm软件包“ angular-ui-router”已重命名为“ @ uirouter / angularjs”。 Please update your package.json See https://ui-router.github.io/blog/uirouter-scoped-packages/ for details. 请更新您的package.json有关详细信息,请参见https://ui-router.github.io/blog/uirouter-scoped-packages/

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

+-- angular@1.6.6 +-角度@ 1.6.6

+-- angular-mocks@1.6.6 +-角mo@1.6.6

`-- angular-ui-router@1.0.3 `-angular-ui-router@1.0.3

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\\chokidar\\node_modules\\fsevents): npm警告可选的跳过选择性依赖性: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 notsup跳过可选依赖项:fsevents@1.1.2不受支持的平台:通缉{“ os”:“ darwin”,“ arch”:“ any”}(当前:{“ os”:“ win32”,“ arch”: “ x64”})

npm WARN jasmine@1.0.0 No description npm WARN jasmine@1.0.0没有描述

npm WARN jasmine@1.0.0 No repository field. npm WARN jasmine@1.0.0没有存储库字段。

As the error message clearly states, this is because the package angular-ui-router has been renamed to @uirouter/angularjs . 如错误消息清楚指出的那样,这是因为软件包angular-ui-router已重命名为@uirouter/angularjs

To fix this, I opened up the package.json file in vi, and changed the line: 为了解决这个问题,我在vi中打开了package.json文件,并更改了这一行:

  "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: 如错误消息所述,(我在vi中转义了转义,并使用了:wq命令写入文件并退出)并运行了以下命令:

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... 但是,这给了我与以前相同的错误消息...当我再次在vi中打开package.json文件时,我看到我已更改的行已恢复为原来的样子。因此似乎运行npm install ...命令会在安装Karma和Jasmine之前更改package.json文件,因此它在错误的位置查找了它们或其他东西。

Can anyone explain to me what's going wrong here? 谁能向我解释这里出了什么问题? How can I get npm to successfully install Karma & Jasmine? 如何获得npm以成功安装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 TypeError:无法读取未定义的属性“切片”,并列出了发生此错误的多个位置

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). 我在Google上搜索了一段时间,发现使用Unix命令行安装Karma / Jasmine(我一直在使用MINGW32)时,这似乎是一个相对常见的问题。

I gave it a go with Windows CMD, but that has given me the following output: 我通过Windows CMD进行了尝试,但这给了我以下输出:

npm ERR! npm ERR! Windows_NT 10.0.15063 Windows_NT 10.0.15063

npm ERR! 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" argv“ C:\\ Program Files \\ nodejs \\ node.exe”“ C:\\ Program Files \\ nodejs \\ node_modules \\ npm \\ bin \\ npm-cli.js”“安装”“ angular”“ angular-ui-reouter”“” angular -mocks“” --save-dev“

npm ERR! npm ERR! node v6.11.3 节点v6.11.3

npm ERR! npm ERR! npm v3.10.10 npm v3.10.10

npm ERR! npm ERR! code E404 代码E404

npm ERR! npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/angular-ui-reouter 404注册表在https://registry.npmjs.org/angular-ui-reouter上返回了404 for GET

npm ERR! npm ERR! 404 404

npm ERR! npm ERR! 404 'angular-ui-reouter' is not in the npm registry. 404'angular-ui-reouter'不在npm注册表中。

npm ERR! npm ERR! 404 You should bug the author to publish it (or use the name yourself!) 404您应该请作者打扰以发布它(或使用您自己的名字!)

npm ERR! npm ERR! 404 404

npm ERR! npm ERR! 404 Note that you can also install from a 404请注意,您也可以从

npm ERR! npm ERR! 404 tarball, folder, http url, or git url. 404 tarball,文件夹,http url或git url。

npm ERR! npm ERR! Please include the following file with any support request: 请在任何支持请求中包括以下文件:

npm ERR! npm ERR! H:\\included\\Documents\\repositories\\jasmine\\npm-debug.log 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... 因此,正如我在其他地方发现的那样,它似乎不会在Unix命令行中运行,但会在Windows命令行中运行...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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