当我运行e2e测试的dockerized版本时,我想选择文件src/enironments/environment.docker.ts
。
我在angular.json中添加了一个新的e2e部分
"myapp-e2e": {
...
},
"myapp-e2e-docker": {
"root": "e2e",
"sourceRoot": "e2e",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "myapp:serve:docker"
}
}
}
我已在我的服务部分中添加了配置:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "myapp:build"
},
"configurations": {
"production": {
"browserTarget": "myapp:build:production"
},
"docker": {
"browserTarget": "myapp:build:docker"
}
}
}
以及我的构建部分的配置:
"docker": {
...
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.docker.ts"
}
]
}
然后我像这样调用我的e2e conf
ng e2e myapp-e2e-docker
它似乎能达到我的期望。例如,如果我拼写了environment.docker.ts文件的名称,它将抱怨找不到它。但是,然后,在运行时读取环境的内容时,我总是从src/environments/environment.ts
这是某种错误吗? ng serve
工具的功能似乎不适用于ng e2e
。
我的package.json文件:
"devDependencies": {
"@angular-devkit/build-angular": "0.12.1",
"@angular/language-service": "6.1.0",
"@types/jasmine": "3.0.0",
"@types/jasminewd2": "2.0.6",
"@types/node": "6.0.60",
"codelyzer": "4.2.1",
"jasmine-core": "3.3.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "3.1.1",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "2.0.4",
"karma-jasmine": "2.0.1",
"karma-jasmine-html-reporter": "1.4.0",
"protractor": "5.3.0",
"ts-node": "7.0.1",
"tslint": "5.3.2",
"typescript": "2.9.2"
}
答案 0 :(得分:0)
这需要两个间接级别。这就是我所做的(全部在angular.json中,希望我所有这些XPath都正确):
在/projects/app/architect/build/configurations
下添加以下内容:
"test": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.e2e.ts"
}
]
}
然后在/projects/app/architect/serve/configurations
下添加以下内容:
"test": {
"browserTarget": "app:build:test"
},
最后是/projects/app-e2e/architect/e2e/configurations
下的以下内容:
"test": {
"devServerTarget": "app:serve:test"
}
然后我通过ng e2e --configuration=test
中的e2e
脚本使用package.json
运行测试