将量角器测试项目从 javascript 移植到 typescript 的步骤 [英] Steps for porting protractor test project from javascript to typescript
问题描述
- 已安装节点并验证 npm 正在运行
- 在包 json依赖项"中添加以下内容:{},开发依赖":{"@angular/cli": "^7.0.4","@types/jasmine": "~2.5.45","@types/jasminewd2": "~2.0.3","@types/node": "~8.9.4","jasmine-core": "~2.99.1","jasmine-reporters": "^2.3.1","jasmine-spec-reporter": "~4.2.1","更漂亮": "1.14.3",量角器":~5.3.0","protractor-beautiful-reporter": "1.2.5","stylelint": "^9.5.0","stylelint-config-standard": "^18.2.0","stylelint-scss": "^3.3.0","ts-node": "~5.0.1","tsc": "^1.20150623.0","tslint": "~5.9.1",打字稿":~2.7.2"}}
- 运行 npm install
尝试运行 npm run protractor conf.js
Tried to run npm run protractor conf.js
我收到此错误:{ import { browser } from 'protractor';
^^^^^^^
I get this error:
{ import { browser } from 'protractor';
^^^^^^
语法错误意外的令牌导入.
Syntax error unexpected token import.
据我所知,这是因为项目没有被转译.
From my understanding this happens because the project was not transpiled.
这是我坚持的步骤.我试图运行 ng build,希望这会为我转换,但我得到另一个错误是我的项目没有角度.
This is the step that i am stuck at. I tried to run ng build, hoping that this will transpile for me,but I get another error that my project is not angular.
如有任何帮助,我们将不胜感激.
Any help would be appeciated.
推荐答案
首先你需要在你的 package.json
旁边有一个 tsconfig.json
.
At first you need a tsconfig.json
next to your package.json
.
tsconfig.json
看起来像这样(更多细节请参见 此处):
The tsconfig.json
can look like this (for more detail please see here):
{
"compilerOptions": {
"outDir": "dist/",
"target": "es5"
},
"include": [
"./src/**/*" <-- Dynamic path to your test files
]
}
要编译,我建议将以下内容添加到 package.json
中的 scripts
部分:
To compile i suggest to add following to the scripts
section in your package.json
:
...
"scripts": {
....
"compile": "./node_modules/.bin/tsc"
....
}
...
执行 npm run compile
后,您的项目中应该有一个 dist
目录.
After executing npm run compile
you should have a dist
directory in your project.
现在要执行测试,您需要将 conf.js
中测试文件的路径调整为如下所示:
Now to execute your tests you need to adjust the path to your test files in your conf.js
to from something like this:
./dist/sample-test.e2e.ts
到
./dist/sample-test.e2e.js
现在你应该可以再次执行你的测试了;-)
And now you should be able to execute your tests again ;-)
更新:安装Typescript
后,您的./node_modules/.bin
目录中有一个可执行文件,您需要将*.ts
文件编译为<代码>*.js.
Update:
After installing Typescript
you have an executable in your ./node_modules/.bin
directory, which you need to compile your *.ts
files to *.js
.
这篇关于将量角器测试项目从 javascript 移植到 typescript 的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!