1

I want to pick file src/enironments/environment.docker.ts when I run a dockerized version of my e2e testing.

I have added a new e2e section to angular.json

"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"
      }
    }
  }

I have added a configuration to my serve section:

    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "myapp:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "myapp:build:production"
        },
        "docker": {
          "browserTarget": "myapp:build:docker"
        }
      }
    }

And a configuration to my build section:

        "docker": {
          ...
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.docker.ts"
            }
          ]
        }

Then I invoke my e2e conf like so

ng e2e myapp-e2e-docker

It seem to do what I expect. If, for example, I misspell the name of the environment.docker.ts file it will complain that it can not find it. But then, reading the content of the environment at run-time, I always find the values from src/environments/environment.ts

Is this some kind of bug? It looks like that the features for the ng serve facility are not available for the ng e2e.

My package.json file:

"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"
}
user275475
  • 41
  • 5

1 Answers1

3

This takes a couple of levels of indirection. Here is what I did (all in angular.json, and hopefully I got all these XPaths correct):

Add the following under /projects/app/architect/build/configurations:

"test": {
  "fileReplacements": [
    {
      "replace": "src/environments/environment.ts",
      "with": "src/environments/environment.e2e.ts"
    }
  ]
}

Then add the following under /projects/app/architect/serve/configurations:

"test": {
  "browserTarget": "app:build:test"
},

And finally the following under /projects/app-e2e/architect/e2e/configurations:

"test": {
  "devServerTarget": "app:serve:test"
}

Then I run the test with ng e2e --configuration=test via the e2e script in my package.json

  • I tried this in Angular 10.0.14, and this does not seem to work.Btw your e2e is in different project "app-e2e". So do I need to specify the project as well with the ng e2e command in your above example? – Anil Kumar B Feb 17 '21 at 12:57