Merge pull request #1801 from overleaf/ew-module-unit-test

add ability to unit test a single module

GitOrigin-RevId: 584708066dea3c8d6afa1483953bbae252b48fa7
This commit is contained in:
Simon Detheridge 2019-05-23 14:12:22 +01:00 committed by sharelatex
parent a0adde3573
commit deb9e656a9
3 changed files with 58 additions and 6 deletions

View file

@ -1,4 +1,4 @@
DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml
DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml --log-level ERROR
BUILD_NUMBER ?= local
@ -14,6 +14,7 @@ DOCKER_COMPOSE := BUILD_NUMBER=$(BUILD_NUMBER) \
MODULE_DIRS := $(shell find modules -mindepth 1 -maxdepth 1 -type d -not -name '.git' )
MODULE_MAKEFILES := $(MODULE_DIRS:=/Makefile)
MODULE_NAME=$(shell basename $(MODULE))
COFFEE := node_modules/.bin/coffee -m $(COFFEE_OPTIONS)
COFFEE := node_modules/.bin/coffee $(COFFEE_OPTIONS)
@ -148,6 +149,9 @@ compile_full:
compile_css_full:
$(MAKE) css_full
compile_module:
cd modules/$(MODULE_NAME) && $(MAKE) compile
compile_modules: $(MODULE_MAKEFILES)
@set -e; \
for dir in $(MODULE_DIRS); \
@ -215,9 +219,16 @@ clean_ci:
test: test_unit test_frontend test_acceptance
test_module: compile_module test_unit_module_run test_acceptance_module_run
test_unit:
@[ ! -d test/unit ] && echo "web has no unit tests" || COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --name unit_test_$(BUILD_DIR_NAME) --rm test_unit
test_unit_module: compile_module test_unit_module_run
test_unit_module_run:
COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --name unit_test_$(BUILD_DIR_NAME) --rm test_unit bin/unit_test_module $(MODULE_NAME) --grep=$(MOCHA_GREP)
test_unit_app:
npm -q run test:unit:app -- ${MOCHA_ARGS}
@ -234,7 +245,7 @@ test_acceptance: compile test_acceptance_app_run test_acceptance_modules_run
test_acceptance_app: compile test_acceptance_app_run
test_acceptance_module: compile test_acceptance_module_run
test_acceptance_module: compile_module test_acceptance_module_run
test_acceptance_run: test_acceptance_app_run test_acceptance_modules_run
@ -253,10 +264,10 @@ test_acceptance_modules_run:
done
test_acceptance_module_run: $(MODULE_MAKEFILES)
@if [ -e $(MODULE)/test/acceptance ]; then \
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(DOCKER_COMPOSE) down -v -t 0 \
&& cd $(MODULE) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(MAKE) test_acceptance \
&& cd $(CURDIR) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(DOCKER_COMPOSE) down -v -t 0; \
@if [ -e modules/$(MODULE_NAME)/test/acceptance ]; then \
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE_NAME) $(DOCKER_COMPOSE) down -v -t 0 \
&& cd modules/$(MODULE_NAME) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE_NAME) $(MAKE) test_acceptance \
&& cd $(CURDIR) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE_NAME) $(DOCKER_COMPOSE) down -v -t 0; \
fi
ci:

View file

@ -34,6 +34,18 @@ $ 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.*
### Running Tests
To run all tests run:
```
make test
```
To run both unit and acceptance tests for a module run:
```
make test_module MODULE=overleaf-integration
```
### Unit Tests
The test suites run in Docker.
@ -52,6 +64,16 @@ During development it is often useful to only run a subset of tests, which can b
make test_unit MOCHA_GREP='AuthorizationManager'
```
To run only the unit tests for a single module do:
```
make test_unit_module MODULE=overleaf-integration
```
Module tests can also use a MOCHA_GREP argument:
```
make test_unit_module MODULE=overleaf-integration MOCHA_GREP=SSO
```
### Acceptance Tests
Acceptance tests are run against a live service, which runs in the `acceptance_test` container defined in `docker-compose.tests.yml`.
@ -78,6 +100,16 @@ During development it is often useful to only run a subset of tests, which can b
make acceptance_test_run MOCHA_ARGS='--grep=AuthorizationManager'
```
To run only the acceptance tests for a single module do:
```
make test_acceptance_module MODULE=overleaf-integration
```
Module tests can also use a MOCHA_GREP argument:
```
make test_acceptance_module MODULE=overleaf-integration MOCHA_GREP=SSO
```
Routes
------

View file

@ -0,0 +1,9 @@
#!/bin/bash
set -e;
MOCHA="node_modules/.bin/mocha --exit --recursive --reporter spec"
MODULE=$1
shift
$MOCHA "$@" modules/$MODULE/test/unit/js