Skip to content

Commit 8f71798

Browse files
authored
Docker fix (#981)
* fixed formatting in changelog * fixed usage of docker image * fixes to circle ci to run docker images: * build and run separated * fixed unit tests * fixed build sh permissions * install npm before building images * fixing npm install in build * fix puppeteer installing * fixed puppeteer install * fixed tests * fixed wd tests * removed event handlers from config * fixed events location * added data dir * fixed retries * fixed retries * increased timeout * increased timeout * fixed loading events * moved node modules to root * fixed loading events * fixed event test * fixed events
1 parent fb4f9d8 commit 8f71798

18 files changed

+91
-92
lines changed

.circleci/build.sh

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
#!/usr/bin/env bash
2-
3-
set -e
4-
51
cd test
62

7-
docker-compose build \
8-
--build-arg NODE_VERSION=$NODE_VERSION \
9-
test-unit \
10-
test-helpers \
11-
test-acceptance.webdriverio \
12-
test-acceptance.nightmare \
13-
test-acceptance.puppeteer \
14-
json_server
15-
16-
docker-compose pull \
17-
php \
18-
selenium.chrome
3+
docker-compose build
4+
docker-compose pull php selenium.chrome

.circleci/config.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ defaults: &defaults
1010
- run: .circleci/test.sh
1111

1212
jobs:
13-
node 8.9.1:
14-
<<: *defaults
15-
environment:
16-
- NODE_VERSION: 8.9.1
17-
18-
node 9.2.0:
13+
docker:
1914
<<: *defaults
2015
environment:
2116
- NODE_VERSION: 9.2.0
@@ -25,5 +20,4 @@ workflows:
2520

2621
test_all:
2722
jobs:
28-
- node 8.9.1
29-
- node 9.2.0
23+
- docker

.circleci/test.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ set -e
55
cd test
66

77
docker-compose run --rm test-unit
8-
docker-compose run --rm test-helpers test/helper
9-
docker-compose run --rm test-helpers test/rest
8+
docker-compose run --rm test-rest
109
docker-compose run --rm test-acceptance.webdriverio
1110
docker-compose run --rm test-acceptance.nightmare
1211
docker-compose run --rm test-acceptance.puppeteer

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/node_modules
2+
test

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ before_script:
2929
- sh -e /etc/init.d/xvfb start
3030
- chmod -R 777 test/data
3131
- php -S 127.0.0.1:8000 -t test/data/app >/dev/null 2>&1 &
32-
- npm run json-server &
33-
- sleep 10
3432
script:
3533
- npm test
3634
- './node_modules/.bin/mocha test/helper/${HELPER}_test.js'

CHANGELOG.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* [Puppeteer] Added `waitForEnabled`, `waitForValue` and `waitNumberOfVisibleElements` methods by @reubenmiller
1010
* [WebDriverIO] Fixed `grabNumberOfVisibleElements` to return 0 when no visible elements are on page. By @michaltrunek
1111
* Helpers API improvements (by @reubenmiller)
12-
* `_passed` hook runs after a test passed successfully
13-
* `_failed` hook runs on a failed test
12+
* `_passed` hook runs after a test passed successfully
13+
* `_failed` hook runs on a failed test
1414
* Hooks API. New events added by @reubenmiller:
15-
* `event.all.before` - executed before all tests
16-
* `event.all.after` - executed after all tests
17-
* `event.multiple.before` - executed before all processes in run-multiple
18-
* `event.multiple.after` - executed after all processes in run-multiple
15+
* `event.all.before` - executed before all tests
16+
* `event.all.after` - executed after all tests
17+
* `event.multiple.before` - executed before all processes in run-multiple
18+
* `event.multiple.after` - executed after all processes in run-multiple
1919
* Multiple execution
2020
* Allow `AfterSuite` and `After` test hooks to be defined after the first Scenario. By @reubenmiller
2121
* [Nightmare] Prevent `I.amOnpage` navigation if the browser is already at the given url

Dockerfile

+9-15
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,24 @@ RUN apt-get update && apt-get install -y wget --no-install-recommends \
2828
# browser.launch({executablePath: 'google-chrome-unstable'})
2929
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
3030

31-
# Install puppeteer so it's available in the container.
32-
RUN yarn add puppeteer
3331

3432
# Add pptr user.
3533
RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
3634
&& mkdir -p /home/pptruser/Downloads \
3735
&& chown -R pptruser:pptruser /home/pptruser \
38-
&& chown -R pptruser:pptruser /home/pptruser \
39-
&& chown -R pptruser:pptruser /node_modules
40-
41-
RUN mkdir /codecept && chown -R pptruser:pptruser /codecept
36+
&& chown -R pptruser:pptruser /home/pptruser
4237

43-
WORKDIR /tmp
44-
COPY package.json /tmp/
45-
46-
# Install packages
47-
RUN npm install --loglevel=warn
4838

4939
#RUN mkdir /home/codecept
50-
WORKDIR /codecept
5140

5241
COPY . /codecept
5342

54-
RUN cp -a /tmp/node_modules /codecept/
43+
RUN chown -R pptruser:pptruser /codecept
44+
RUN runuser -l pptruser -c 'npm install --loglevel=warn --prefix /codecept'
45+
46+
RUN ln -s /codecept/bin/codecept.js /usr/local/bin/codeceptjs
47+
RUN mkdir /tests
48+
WORKDIR /tests
5549

5650
# Allow to pass argument to codecept run via env variable
5751
ENV CODECEPT_ARGS=""
@@ -63,7 +57,7 @@ ENV HOST=selenium
6357
# USER pptruser
6458

6559
# Set the entrypoint for Nightmare
66-
ENTRYPOINT ["docker/entrypoint"]
60+
ENTRYPOINT ["/codecept/docker/entrypoint"]
6761

6862
# Run tests
69-
CMD ["bash", "docker/run.sh"]
63+
CMD ["bash", "/codecept/docker/run.sh"]

docker/README.md

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Codeceptjs Docker
22

3-
CodeceptJS packed into container with the Nightmare, Protractor, and WebDriverIO drivers.
3+
CodeceptJS packed into container with the Nightmare, Protractor, Puppeteer, and WebDriverIO drivers.
44

55
## How to Use
66

@@ -9,15 +9,26 @@ Mount in your CodeceptJS config directory into the `/tests` directory in the doc
99

1010
Sample mount: `-v path/to/codecept.json:/tests`
1111

12+
CodeceptJS runner is available inside container as `codeceptjs`.
13+
1214
### Locally
1315

14-
You can execute CodeceptJS with Nightmare locally with no extra configuration.
16+
You can execute CodeceptJS with Puppeteer or Nightmare locally with no extra configuration.
1517

1618
```sh
1719
docker run --net=host -v $PWD:/tests codeception/codeceptjs
1820
```
1921

20-
Nightmare helper must be enabled in codecept.json config.
22+
To customize execution call `codeceptjs` command:
23+
24+
```sh
25+
# run tests with steps
26+
docker run --net=host -v $PWD:/tests codeception/codeceptjs codeceptjs run --steps
27+
28+
# run tests with @user in a name
29+
docker run --net=host -v $PWD:/tests codeception/codeceptjs codeceptjs run --grep "@user"
30+
```
31+
2132

2233
### Docker Compose
2334

@@ -79,18 +90,28 @@ To build this image:
7990
docker build -t codeception/codeceptjs .
8091
```
8192

82-
### Debugging
83-
To pass arguments to `codecept run` command inside docker image you can set
84-
`CODECEPT_ARGS` environment variable. For example to run your tests with debug
85-
and steps output:
93+
* this directory will be added as `/codecept` insde container
94+
* tests directory is expected to be mounted as `/tests`
95+
* `codeceptjs` is a synlink to `/codecept/bin/codecept.js`
96+
97+
### Passing Options
98+
99+
Options can be passed by calling `codeceptjs`:
100+
101+
```
102+
docker run -v $PWD:/tests codeception/codeceptjs codeceptjs run --debug
103+
```
104+
105+
Alternatively arguments to `codecept run` command can be passed via `CODECEPT_ARGS` environment variable. For example to run your tests with debug
106+
output:
86107

87108
```yaml
88109
version: '2'
89110
services:
90111
codeceptjs:
91112
image: codeception/codeceptjs
92113
environment:
93-
- CODECEPT_ARGS=--debug --steps
114+
- CODECEPT_ARGS=--debug
94115
volumes:
95116
- .:/tests
96117
```

docker/run.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env bash
22

3-
source docker/help.sh
3+
source /codecept/docker/help.sh
44

55
# Check if tests are correctly mounted
66
if [[ -d "/tests/" ]]; then
77
echo "CodeceptJS directory has been found."
88

99
# Run the tests
1010
cd /tests/
11-
node /codecept/bin/codecept.js run $CODECEPT_ARGS
11+
codeceptjs run $CODECEPT_ARGS
1212
else
1313
display_usage
1414
fi

lib/hooks.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ const fileExists = require('./utils').fileExists;
44

55
module.exports = function (hook, done, stage) {
66
stage = stage || 'bootstrap';
7-
if (typeof hook === 'string' && fileExists(fsPath.join(global.codecept_dir, hook))) {
8-
const callable = require(fsPath.join(global.codecept_dir, hook));
7+
if (typeof hook === 'string') {
8+
const pluginFile = fsPath.join(global.codecept_dir, hook);
9+
if (!fileExists(pluginFile)) {
10+
throw new Error(`Hook ${pluginFile} doesn't exist`);
11+
}
12+
const callable = require(pluginFile);
913
if (typeof callable === 'function') {
1014
callSync(callable, done);
1115
return;

test/acceptance/codecept.Nightmare.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const TestHelper = require('../support/TestHelper');
2-
const eventHandlers = require('../data/sandbox/eventHandlers');
32

43
module.exports.config = {
54
tests: './*_test.js',

test/acceptance/codecept.Puppeteer.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const TestHelper = require('../support/TestHelper');
2-
const eventHandlers = require('../data/sandbox/eventHandlers');
32

43
module.exports.config = {
54
tests: './*_test.js',

test/acceptance/codecept.WebDriverIO.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const TestHelper = require('../support/TestHelper');
2-
const eventHandlers = require('../data/sandbox/eventHandlers');
32

43
module.exports.config = {
54
tests: './*_test.js',

test/acceptance/event_test.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
const event = require('../../lib').event;
1+
let event;
2+
try {
3+
require.resolve('../../lib');
4+
event = require('../../lib').event;
5+
} catch (err) {
6+
event = require('/codecept/lib').event; // eslint-disable-line
7+
}
28
const assert = require('assert');
39
const expect = require('chai').expect;
410
const eventHandlers = require('../data/sandbox/eventHandlers');
511

612
const expectedEvents = [];
713

8-
Feature('Events', { retries: 0 });
14+
Feature('Events');
915

1016
BeforeSuite((I) => {
1117
expectedEvents.push(...[
12-
event.all.before,
1318
event.suite.before,
1419
]);
1520
expect(eventHandlers.events).to.deep.equal(expectedEvents);

test/data/rest/db.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"comments":[],"posts":[{"id":1,"title":"json-server","author":"davert"}]}
1+
{"posts":[{"id":1,"title":"json-server","author":"davert"}],"user":{"name":"davert"}}

test/data/sandbox/eventHandlers.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
const event = require('../../../lib').event;
1+
let event;
2+
try {
3+
require.resolve('../../../lib');
4+
event = require('../../../lib').event;
5+
} catch (err) {
6+
event = require('/codecept/lib').event; // eslint-disable-line
7+
}
28

39
const eventTypes = [
410
// All Events

test/docker-compose.yml

+11-19
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,20 @@ version: '3'
22
services:
33
test-unit:
44
build: ..
5-
entrypoint: docker/entrypoint node_modules/.bin/mocha
5+
entrypoint: /codecept/node_modules/.bin/mocha
66
command: test/unit
77
working_dir: /codecept
88
volumes:
99
- ..:/codecept
1010
- node_modules:/codecept/node_modules
1111

12-
test-runner:
12+
test-rest:
1313
build: ..
14-
entrypoint: docker/entrypoint node_modules/.bin/mocha
15-
command: test/runner
16-
working_dir: /codecept
17-
volumes:
18-
- ..:/codecept
19-
- node_modules:/codecept/node_modules
20-
21-
test-helpers:
22-
build: ..
23-
entrypoint: docker/entrypoint node_modules/.bin/mocha --invert --fgrep Appium
24-
command: test/helper
14+
entrypoint: /codecept/node_modules/.bin/mocha
15+
command: test/rest
2516
working_dir: /codecept
2617
env_file: .env
2718
depends_on:
28-
- selenium.chrome
29-
- php
3019
- json_server
3120
volumes:
3221
- ..:/codecept
@@ -36,14 +25,15 @@ services:
3625
build: ..
3726
env_file: .env
3827
environment:
39-
- CODECEPT_ARGS=-c codecept.WebDriverIO.js --grep @WebDriverIO
28+
- CODECEPT_ARGS=-c codecept.WebDriverIO.js --grep @WebDriverIO --verbose
4029
depends_on:
4130
- php
4231
- selenium.chrome
4332
volumes:
4433
- ./acceptance:/tests
34+
- ./data:/data
4535
- ./support:/support
46-
- node_modules:/codecept/node_modules
36+
- node_modules:/node_modules
4737

4838
test-acceptance.nightmare:
4939
build: ..
@@ -55,8 +45,9 @@ services:
5545
- selenium.chrome
5646
volumes:
5747
- ./acceptance:/tests
48+
- ./data:/data
5849
- ./support:/support
59-
- node_modules:/codecept/node_modules
50+
- node_modules:/node_modules
6051

6152
test-acceptance.puppeteer:
6253
build: ..
@@ -67,8 +58,9 @@ services:
6758
- php
6859
volumes:
6960
- ./acceptance:/tests
61+
- ./data:/data
7062
- ./support:/support
71-
- node_modules:/codecept/node_modules
63+
- node_modules:/node_modules
7264

7365
selenium.chrome:
7466
image: selenium/standalone-chrome:3.9.1-actinium

test/rest/ApiDataFactory_test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const data = {
2222

2323
const getDataFromFile = () => JSON.parse(fs.readFileSync(dbFile));
2424

25-
describe('ApiDataFactory', () => {
25+
describe('ApiDataFactory', function () {
26+
this.timeout(20000);
27+
2628
before(() => {
2729
I = new ApiDataFactory({
2830
endpoint: api_url,
@@ -42,14 +44,13 @@ describe('ApiDataFactory', () => {
4244
} catch (err) {
4345
// continue regardless of error
4446
}
45-
setTimeout(done, 500);
47+
setTimeout(done, 5000);
4648
});
4749

4850
afterEach(() => I._after());
4951

5052
describe('create and cleanup records', function () {
51-
this.retries(1);
52-
this.timeout(20000);
53+
this.retries(2);
5354

5455
it('should create a new post', async () => {
5556
await I.have('post');

0 commit comments

Comments
 (0)