Skip to content

Commit 7c00838

Browse files
CharlesSuttiehansl
authored andcommitted
docs: update ci story
update the CircleCi and Travis configurations update ng test and ng e2e command flags for version 6 use headless chrome instead of chrome add guidance on ChromeDriver closes #10677
1 parent 6165cdf commit 7c00838

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

Diff for: docs/documentation/stories/continuous-integration.md

+48-32
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ set up Circle CI and Travis CI.
2323
Even though `ng test` and `ng e2e` already run on your environment, they need to be adjusted to
2424
run in CI environments.
2525

26-
When using Chrome in CI environments it has to be started without sandboxing.
27-
We can achieve that by editing our test configs.
26+
We'll use [Headless Chrome](https://developers.google.com/web/updates/2017/04/headless-chrome#cli) in CI environments. In some environments we need to start the browser without
27+
sandboxing or disable the gpu. Here we'll do both.
2828

29-
In `karma.conf.js`, add a custom launcher called `ChromeNoSandbox` below `browsers`:
29+
In `karma.conf.js`, add a custom launcher called `ChromeHeadlessCI` below `browsers`:
3030

3131
```
3232
browsers: ['Chrome'],
3333
customLaunchers: {
34-
ChromeNoSandbox: {
35-
base: 'Chrome',
36-
flags: ['--no-sandbox']
34+
ChromeHeadlessCI: {
35+
base: 'ChromeHeadless',
36+
flags: ['--no-sandbox', '--disable-gpu']
3737
}
3838
},
3939
```
4040

41-
Create a new file in the root of your project called `protractor-ci.conf.js`, that extends
41+
We'll override the `browsers` option from the command line to use our new configuration.
42+
43+
Create a new file in the `e2e` directory of your project called `protractor-ci.conf.js`, that extends
4244
the original `protractor.conf.js`:
4345

4446
```
@@ -47,22 +49,24 @@ const config = require('./protractor.conf').config;
4749
config.capabilities = {
4850
browserName: 'chrome',
4951
chromeOptions: {
50-
args: ['--no-sandbox']
52+
args: ['--headless', '--no-sandbox', '--disable-gpu']
5153
}
5254
};
5355
5456
exports.config = config;
5557
```
5658

57-
Now you can run the following commands to use the `--no-sandbox` flag:
59+
Now you can run the following commands to use the new configurations:
5860

5961
```
60-
ng test --no-watch --no-progress --browser=ChromeNoSandbox
61-
ng e2e --no-progress --config=protractor-ci.conf.js
62+
ng test --watch=false --progress=false --browsers=ChromeHeadlessCI
63+
ng e2e --protractor-config=./e2e/protractor-ci.conf.js
6264
```
6365

64-
For CI environments it's also a good idea to disable progress reporting (via `--no-progress`)
65-
to avoid spamming the server log with progress messages.
66+
For CI environments it's also a good idea to disable progress reporting (via `--progress=false`)
67+
to avoid spamming the server log with progress messages. We've added that option to `ng test`. An equivalent
68+
option has been requested for
69+
`ng e2e` [(#11412)](https://github.com/angular/angular-cli/issues/11412).
6670

6771

6872
## Using Circle CI
@@ -76,28 +80,27 @@ jobs:
7680
build:
7781
working_directory: ~/my-project
7882
docker:
83+
# specify the version you desire here
84+
# see https://hub.docker.com/r/circleci/node/tags/
7985
- image: circleci/node:8-browsers
8086
steps:
8187
- checkout
8288
- restore_cache:
83-
key: my-project-{{ .Branch }}-{{ checksum "package.json" }}
89+
key: my-project-{{ .Branch }}-{{ checksum "package-lock.json" }}
8490
- run: npm install
8591
- save_cache:
86-
key: my-project-{{ .Branch }}-{{ checksum "package.json" }}
92+
key: my-project-{{ .Branch }}-{{ checksum "package-lock.json" }}
8793
paths:
88-
- "node_modules"
89-
- run: xvfb-run -a npm run test -- --no-watch --no-progress --browser=ChromeNoSandbox
90-
- run: xvfb-run -a npm run e2e -- --no-progress --config=protractor-ci.conf.js
91-
94+
- "node_modules"
95+
- run: npm run test -- --watch=false --progress=false --browsers=ChromeHeadlessCI
96+
- run: npm run e2e -- --protractor-config=./e2e/protractor-ci.conf.js
9297
```
9398
9499
We're doing a few things here:
95100
-
96101
- `node_modules` is cached.
97-
- [npm run](https://docs.npmjs.com/cli/run-script) is used to run `ng` because `@angular/cli` is
102+
- we use [npm run](https://docs.npmjs.com/cli/run-script) to run `ng` because `@angular/cli` is
98103
not installed globally. The double dash (`--`) is needed to pass arguments into the npm script.
99-
- `xvfb-run` is used to run `npm run` to run a command using a virtual screen, which is needed by
100-
Chrome.
101104

102105
Commit your changes and push them to your repository.
103106

@@ -119,7 +122,7 @@ sudo: false
119122
language: node_js
120123
node_js:
121124
- "8"
122-
125+
123126
addons:
124127
apt:
125128
sources:
@@ -135,21 +138,34 @@ install:
135138
- npm install
136139
137140
script:
138-
# Use Chromium instead of Chrome.
139-
- export CHROME_BIN=chromium-browser
140-
- xvfb-run -a npm run test -- --no-watch --no-progress --browser=ChromeNoSandbox
141-
- xvfb-run -a npm run e2e -- --no-progress --config=protractor-ci.conf.js
142-
141+
- npm run test -- --watch=false --progress=false --browsers=ChromeHeadlessCI
142+
- npm run e2e -- --protractor-config=./e2e/protractor-ci.conf.js
143143
```
144144

145-
Although the syntax is different, we're mostly doing the same steps as were done in the
146-
Circle CI config.
147-
The only difference is that Travis doesn't come with Chrome, so we use Chromium instead.
148-
149145
Commit your changes and push them to your repository.
150146

151147
Next you'll need to [sign up for Travis CI](https://travis-ci.org/auth) and
152148
[add your project](https://travis-ci.org/profile).
153149
You'll need to push a new commit to trigger a build.
154150

155151
Be sure to check out the [Travis CI docs](https://docs.travis-ci.com/) if you want to know more.
152+
153+
## ChromeDriver
154+
155+
In CI environments it's a good idea to to use a specific version of [ChromeDriver](http://chromedriver.chromium.org/)
156+
instead of allowing `ng e2e` to use the latest one. CI environments often use older versions of chrome, which are unsupported by newer versions of ChromeDriver.
157+
158+
An easy way to do this is to define a NPM script:
159+
160+
```text
161+
"webdriver-update-ci": "webdriver-manager update --standalone false --gecko false --versions.chrome 2.37"
162+
```
163+
164+
And then on CI environments you call that script followed by the e2e command without updating webdriver:
165+
166+
```text
167+
npm run webdriver-update-ci
168+
ng e2e --webdriver-update=false
169+
```
170+
171+
This way you will always use a specific version of chrome driver between runs.

0 commit comments

Comments
 (0)