ng e2e自定义配置未替换默认环境文件

时间:2019-04-29 17:57:33

标签: angular angular-cli angular-e2e angular-cli-v7

我正在使用自定义配置为我的angular-cli应用程序运行e2e测试。

我正在使用角度版本7,并已在angular.json中添加了自定义配置。我已经创建了一个环境文件,它将替换默认的环境文件。

我以以下方式运行e2e测试:

ng -e2e --configuration=test

这是我的environment.test.ts文件:

export const environment = {
  production: true,
  config: 'test'
};

这是我的angular.json摘录,其中包含test的配置:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "test-app": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [...],
            "styles": [...]
          },
          "configurations": {
            "test": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": true,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.test.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "test-app:build"
          },
          "configurations": {
            "test": {
              "browserTarget": "test-app:build:test"
            }
          }
        },
        "extract-i18n": {...},
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [],
            "styles": [...],
            "assets": [...]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        }
      }
    },
    "test-app-e2e": {
      "root": "e2e",
      "sourceRoot": "e2e",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "test-app:serve"
          },
          "configurations": {
            "test": {
              "protractorConfig": "./protractor.conf.test.js",
              "devServerTarget": ""
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["e2e/tsconfig.e2e.json"],
            "exclude": ["**/node_modules/**"]
          }
        }
      }
    }
  },
  "defaultProject": "test-app",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

我有一条日志消息,打印出环境config变量中的当前值,即使我使用带有测试配置的e2e测试运行它,它仍会打印出config变量的默认值,而不是{{1 }}是我期望的价值。

我想念什么?

0 个答案:

没有答案