Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: 🎡 Use docker-compose for CI #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.git
/.nyc_output
/.tmp
/node_modules
/reports
/REPORTS2
/coverage.lcov
25 changes: 4 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
language: node_js
node_js:
- "node"
sudo: required
dist: trusty
addons:
firefox: latest
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
- graphicsmagick

before_script:
- export CHROME_BIN=/usr/bin/google-chrome
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- npm run setup
- nohup bash -c "npm run server &> selenium-server.log &"
- sleep 10
after_success:
- npm run coverage
- npm run lint
services:
- docker
script:
- docker-compose run --rm --use-aliases app
deploy:
provider: npm
email: [email protected]
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Use the latest one as this is for CI purpose.
FROM node:latest

WORKDIR /app

RUN apt-get update \
&& apt-get install -y --no-install-recommends graphicsmagick \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY package.json .
COPY package-lock.json .

RUN npm install
65 changes: 65 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: '2'
services:
app:
build:
context: .
volumes:
- .:/app
- /app/node_modules
working_dir: /app
environment:
- SELENIUM_URL=http://selenium:4444/wd/hub
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker-compose launches 4 containers: app, selenium, firefox, chrome.

  • app runs tests.
  • Protractor on app connects to selenium to launch web browsers and control them.
  • firefox and chrome registers themselves to selenium. selenium connects to firefox or chromes based on the capability specified by protractor.

# To have report.ci defined
- TRAVIS=1
- TRAVIS_JOB_NUMBER=dummy
- TRAVIS_BRANCH=dummy
- TRAVIS_COMMIT=dummy
- TRAVIS_TAG=dummy
- TRAVIS_REPO_SLUG=dummy
- TRAVIS_COMMIT_MESSAGE=dummy
- TRAVIS_BUILD_ID=dummy
Comment on lines +13 to +20
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests always fail on local environments without these definitions.
Definitions like - TRAVIS (without =xxxx) allows inherit specified environment variables and make tests pass only on TravisCI, or you can have them it pass locally if you define those variables. Please let me know if you like that.

command:
- /bin/sh
- -x
- -e
- -c
- |
sleep 10
npm test
npm run coverage
npm run lint
depends_on:
- firefox
- chrome
networks:
- default
selenium:
image: selenium/hub
ports:
- 4444
networks:
- default
firefox:
image: selenium/node-firefox
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium
environment:
- HUB_HOST=selenium
networks:
- default
chrome:
image: selenium/node-chrome
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium
environment:
- HUB_HOST=selenium
# https://github.com/SeleniumHQ/docker-selenium/issues/87
- DBUS_SESSION_BUS_ADDRESS=/dev/null
- NODE_MAX_INSTANCES=2
- NODE_MAX_SESSION=2
networks:
- default
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ protractorUtil.registerJasmineReporter = function(context) {
prefix: ''
};
global.browser.getProcessedConfig().then(function(config) {
if(config.capabilities) {
if (config.capabilities) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint error: Expected space(s) after "if" keyword-spacing

protractorUtil.test.prefix = '[' + config.capabilities.name + '] ';
}
protractorUtil.testResults.push(protractorUtil.test);
Expand All @@ -457,7 +457,7 @@ protractorUtil.registerJasmineReporter = function(context) {
protractorUtil.takeOnSpecDone(result, context, protractorUtil.test); //exec async operation

//Add defined name to the test.description as a prefix
if(context.config.addPrefixToTests) {
if (context.config.addPrefixToTests) {
result.description = protractorUtil.test.prefix + result.description;
result.fullName = protractorUtil.test.prefix + result.fullName;
}
Expand Down
1 change: 0 additions & 1 deletion spec/integrational/protractor-config/bug55.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine2',
specs: ['../protractor/angularjs-homepage-disabled-test.js'],
useBlockingProxy: true,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow this causes tests fail (protractor raises an error Error from wait for angular).
This isn't specified in default.js and useBlockingProxy looks have nothing to do with the purpose of bug55, and I simply remove that.

plugins: [{
path: '../../../index.js',
screenshotPath: '.tmp/bug55',
Expand Down
4 changes: 4 additions & 0 deletions spec/integrational/protractor-config/failuresWithLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ exports.config = {
browserName: env.capabilities.browserName,
loggingPrefs: {
browser: 'ALL' // "OFF", "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST", "ALL".
},
// For chrome 75+
'goog:loggingPrefs': {
browser: 'ALL'
}
},
plugins: [{
Expand Down
4 changes: 4 additions & 0 deletions spec/integrational/protractor-config/failuresWithLogsAsap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ exports.config = {
browserName: env.capabilities.browserName,
loggingPrefs: {
browser: 'ALL' // "OFF", "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST", "ALL".
},
// For chrome 75+
'goog:loggingPrefs': {
browser: 'ALL'
}
},
plugins: [{
Expand Down
1 change: 0 additions & 1 deletion spec/integrational/protractor-config/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine2',
specs: ['../protractor/angularjs-homepage-disabled-test.js'],
useBlockingProxy: true,
plugins: [{
path: '../../../index.js',
screenshotPath: '.tmp/verbose',
Expand Down
24 changes: 12 additions & 12 deletions spec/integrational/screenshoter.int.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1537,18 +1537,18 @@ describe("Screenshoter running under protractor", function() {

var report = getReportAsJson(data);
//Since we can't guarantee which one of the test-specs will end up firts, I've to do a matcher validation between "M" and "L" letters.
expect(report.tests[0].description).toMatch('\[[M|L]\] should greet the named user');
expect(report.tests[0].fullName).toMatch('\[[M|L]\] angularjs homepage should greet the named user');
expect(report.tests[1].description).toMatch('\[[M|L]\] should list todos');
expect(report.tests[1].fullName).toMatch('\[[M|L]\] angularjs homepage todo list should list todos');
expect(report.tests[2].description).toMatch('\[[M|L]\] should add a todo');
expect(report.tests[2].fullName).toMatch('\[[M|L]\] angularjs homepage todo list should add a todo');
expect(report.tests[3].description).toMatch('\[[M|L]\] should greet the named user');
expect(report.tests[3].fullName).toMatch('\[[M|L]\] angularjs homepage should greet the named user');
expect(report.tests[4].description).toMatch('\[[M|L]\] should list todos');
expect(report.tests[4].fullName).toMatch('\[[M|L]\] angularjs homepage todo list should list todos');
expect(report.tests[5].description).toMatch('\[[M|L]\] should add a todo');
expect(report.tests[5].fullName).toMatch('\[[M|L]\] angularjs homepage todo list should add a todo');
expect(report.tests[0].description).toMatch('\\[[M|L]\\] should greet the named user');
expect(report.tests[0].fullName).toMatch('\\[[M|L]\\] angularjs homepage should greet the named user');
expect(report.tests[1].description).toMatch('\\[[M|L]\\] should list todos');
expect(report.tests[1].fullName).toMatch('\\[[M|L]\\] angularjs homepage todo list should list todos');
expect(report.tests[2].description).toMatch('\\[[M|L]\\] should add a todo');
expect(report.tests[2].fullName).toMatch('\\[[M|L]\\] angularjs homepage todo list should add a todo');
expect(report.tests[3].description).toMatch('\\[[M|L]\\] should greet the named user');
expect(report.tests[3].fullName).toMatch('\\[[M|L]\\] angularjs homepage should greet the named user');
expect(report.tests[4].description).toMatch('\\[[M|L]\\] should list todos');
expect(report.tests[4].fullName).toMatch('\\[[M|L]\\] angularjs homepage todo list should list todos');
expect(report.tests[5].description).toMatch('\\[[M|L]\\] should add a todo');
expect(report.tests[5].fullName).toMatch('\\[[M|L]\\] angularjs homepage todo list should add a todo');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint error: Unnecessary escape character: \[ no-useless-escape Unnecessary escape character: \] no-useless-escape

done();
});

Expand Down
4 changes: 2 additions & 2 deletions spec/unit/screenshoter.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ describe("Screenshoter unit", function() {

it("should merge user config", function() {
screenshoter.config = {
screenshotPath: 'REPORTS',
screenshotPath: 'REPORTS2',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REPORTS causes an error Error: EEXIST: file already exists, mkdir '/app/REPORTS' on Windows. It looks conflict with the existing reports. I changed the directory name to avoid the problem though it rather looks like an issue of mkdirp.

screenshotOnSpec: 'failure'
};
screenshoter.setup();
expect(screenshoter.config.reportFile).toBeDefined();
delete screenshoter.config.reportFile;
expect(screenshoter.config).toEqual({
screenshotPath: 'REPORTS',
screenshotPath: 'REPORTS2',
withLogs: true,
screenshotOnExpect: 'failure+success',
screenshotOnSpec: 'failure',
Expand Down