Get module unit tests running inside Docker as well as main tests

This commit is contained in:
James Allen 2017-11-23 16:45:46 +00:00
parent fbf8cc2d03
commit d9d7c96958
5 changed files with 71 additions and 47 deletions

View file

@ -109,23 +109,15 @@ pipeline {
}
}
stage('Unit Test') {
agent {
docker {
image 'node:6.9.5'
reuseNode true
}
}
stage('Unit Tests') {
steps {
sh 'make install'
sh 'make test_unit MOCHA_ARGS="--reporter=tap"'
sh 'env NODE_ENV=development ./node_modules/.bin/grunt mochaTest:unit --reporter=tap'
sh "make test_unit MOCHA_ARGS="--reporter=tap"'
}
}
stage('Acceptance Tests') {
steps {
sh 'make install'
sh "make test_acceptance MOCHA_ARGS="--reporter=tap"'
}
}

View file

@ -17,6 +17,69 @@ web-sharelatex uses [Grunt](http://gruntjs.com/) to build its front-end related
Image processing tasks are commented out in the gruntfile and the needed packages aren't presently in the project's `package.json`. If the images need to be processed again (minified and sprited), start by fetching the packages (`npm install grunt-contrib-imagemin grunt-sprity`), then *decomment* the tasks in `Gruntfile.coffee`. After this, the tasks can be called (explicitly, via `grunt imagemin` and `grunt sprity`).
New Docker-based build process
------------------------------
Note that the Grunt workflow from above should still work, but we are transitioning to a
Docker based testing workflow, which is documented below:
### Running the app
The app runs natively using npm and Node on the local system:
```
$ npm install
$ npm run start
```
*Ideally the app would run in Docker like the tests below, but with host networking not supported in OS X, we need to run it natively until all services are Dockerised.*
### Unit Tests
The test suites run in Docker.
Unit tests can be run in the `test_unit` container defined in `docker-compose.tests.yml`.
The makefile contains a short cut to run these:
```
make install # Only needs running once, or when npm packages are updated
make unit_test
```
During development it is often useful to only run a subset of tests, which can be configured with arguments to the mocha CLI:
```
make unit_test MOCHA_ARGS='--grep=AuthorizationManager'
```
### Acceptance Tests
Acceptance tests are run against a live service, which runs in the `acceptance_test` container defined in `docker-compose.tests.yml`.
To run the tests out-of-the-box, the makefile defines:
```
make install # Only needs running once, or when npm packages are updated
make acceptance_test
```
However, during development it is often useful to leave the service running for rapid iteration on the acceptance tests. This can be done with:
```
make acceptance_test_start_service
make acceptance_test_run # Run as many times as needed during development
make acceptance_test_stop_service
```
`make acceptance_test` just runs these three commands in sequence.
During development it is often useful to only run a subset of tests, which can be configured with arguments to the mocha CLI:
```
make acceptance_test_run MOCHA_ARGS='--grep=AuthorizationManager'
```
Unit test status
----------------

View file

@ -1,12 +0,0 @@
version: "2"
services:
test_unit:
image: quay.io/sharelatex/$PROJECT_NAME:$BRANCH_NAME-$BUILD_NUMBER
user: root
volumes: []
test_acceptance:
image: quay.io/sharelatex/$PROJECT_NAME:$BRANCH_NAME-$BUILD_NUMBER
user: root
volumes: []

View file

@ -7,7 +7,6 @@ all: install test
@echo "Run:"
@echo " make install to set up the project dependencies (in docker)"
@echo " make test to run all the tests for the project (in docker)"
@echo " make run to run the app (natively)"
add:
$(NPM) install --save ${P}
@ -40,25 +39,7 @@ test_acceptance_stop_service:
test_acceptance_run:
docker-compose -f docker-compose.yml ${DOCKER_COMPOSE_FLAGS} exec -T test_acceptance npm run test:acceptance -- ${MOCHA_ARGS}
build:
docker build --pull --tag quay.io/sharelatex/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) .
publish:
docker push quay.io/sharelatex/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
ci:
# When we run the tests locally we mount the local directory as a volumne
# and use a persistent node_modules folder (see docker-compose.yml).
# However, on the CI server, we want to run our tests in the image that we
# have built for deployment, which is what the docker-compose.ci.yml
# override does.
PROJECT_NAME=$(PROJECT_NAME) \
BRANCH_NAME=$(BRANCH_NAME) \
BUILD_NUMBER=$(BUILD_NUMBER) \
DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" \
$(MAKE) build test publish
.PHONY:
add install update test test_unit test_acceptance \
test_acceptance_start_service test_acceptance_stop_service \
test_acceptance_run build publish ci
test_acceptance_run

View file

@ -11,12 +11,12 @@
},
"scripts": {
"test:acceptance:wait_for_app": "echo 'Waiting for app to be accessible' && while (! curl -s -o /dev/null localhost:3000/status) do sleep 1; done",
"test:acceptance:run": "mocha --recursive --reporter spec --timeout 15000 $@ test/acceptance/js",
"test:acceptance:run": "bin/acceptance_test $@",
"test:acceptance": "npm run compile:acceptance_tests && npm run test:acceptance:wait_for_app && npm run test:acceptance:run -- $@",
"test:unit": "npm run compile:app && npm run compile:unit_tests && mocha --recursive --reporter spec $@ test/unit/js",
"compile:unit_tests": "coffee -o test/unit/js -c test/unit/coffee",
"compile:acceptance_tests": "coffee -o test/acceptance/js -c test/acceptance/coffee",
"compile:app": "coffee -o app/js -c app/coffee && coffee -c app.coffee",
"test:unit": "npm run compile:app && npm run compile:unit_tests && bin/unit_test $@",
"compile:unit_tests": "bin/compile_unit_tests",
"compile:acceptance_tests": "bin/compile_acceptance_tests",
"compile:app": "bin/compile_app",
"start": "npm run compile:app && node app.js",
"echo": "echo $@"
},