mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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:
parent
a0adde3573
commit
deb9e656a9
3 changed files with 58 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml
|
DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml --log-level ERROR
|
||||||
|
|
||||||
|
|
||||||
BUILD_NUMBER ?= local
|
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_DIRS := $(shell find modules -mindepth 1 -maxdepth 1 -type d -not -name '.git' )
|
||||||
MODULE_MAKEFILES := $(MODULE_DIRS:=/Makefile)
|
MODULE_MAKEFILES := $(MODULE_DIRS:=/Makefile)
|
||||||
|
MODULE_NAME=$(shell basename $(MODULE))
|
||||||
|
|
||||||
COFFEE := node_modules/.bin/coffee -m $(COFFEE_OPTIONS)
|
COFFEE := node_modules/.bin/coffee -m $(COFFEE_OPTIONS)
|
||||||
COFFEE := node_modules/.bin/coffee $(COFFEE_OPTIONS)
|
COFFEE := node_modules/.bin/coffee $(COFFEE_OPTIONS)
|
||||||
|
@ -148,6 +149,9 @@ compile_full:
|
||||||
compile_css_full:
|
compile_css_full:
|
||||||
$(MAKE) css_full
|
$(MAKE) css_full
|
||||||
|
|
||||||
|
compile_module:
|
||||||
|
cd modules/$(MODULE_NAME) && $(MAKE) compile
|
||||||
|
|
||||||
compile_modules: $(MODULE_MAKEFILES)
|
compile_modules: $(MODULE_MAKEFILES)
|
||||||
@set -e; \
|
@set -e; \
|
||||||
for dir in $(MODULE_DIRS); \
|
for dir in $(MODULE_DIRS); \
|
||||||
|
@ -215,9 +219,16 @@ clean_ci:
|
||||||
|
|
||||||
test: test_unit test_frontend test_acceptance
|
test: test_unit test_frontend test_acceptance
|
||||||
|
|
||||||
|
test_module: compile_module test_unit_module_run test_acceptance_module_run
|
||||||
|
|
||||||
test_unit:
|
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
|
@[ ! -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:
|
test_unit_app:
|
||||||
npm -q run test:unit:app -- ${MOCHA_ARGS}
|
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_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
|
test_acceptance_run: test_acceptance_app_run test_acceptance_modules_run
|
||||||
|
|
||||||
|
@ -253,10 +264,10 @@ test_acceptance_modules_run:
|
||||||
done
|
done
|
||||||
|
|
||||||
test_acceptance_module_run: $(MODULE_MAKEFILES)
|
test_acceptance_module_run: $(MODULE_MAKEFILES)
|
||||||
@if [ -e $(MODULE)/test/acceptance ]; then \
|
@if [ -e modules/$(MODULE_NAME)/test/acceptance ]; then \
|
||||||
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(DOCKER_COMPOSE) down -v -t 0 \
|
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE_NAME) $(DOCKER_COMPOSE) down -v -t 0 \
|
||||||
&& cd $(MODULE) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE) $(MAKE) test_acceptance \
|
&& 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) $(DOCKER_COMPOSE) down -v -t 0; \
|
&& cd $(CURDIR) && COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME)_$(MODULE_NAME) $(DOCKER_COMPOSE) down -v -t 0; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ci:
|
ci:
|
||||||
|
|
|
@ -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.*
|
*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
|
### Unit Tests
|
||||||
|
|
||||||
The test suites run in Docker.
|
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'
|
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
|
||||||
|
|
||||||
Acceptance tests are run against a live service, which runs in the `acceptance_test` container defined in `docker-compose.tests.yml`.
|
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'
|
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
|
Routes
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|
9
services/web/bin/unit_test_module
Executable file
9
services/web/bin/unit_test_module
Executable 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
|
Loading…
Reference in a new issue