Merge pull request #2180 from overleaf/as-clean-up-makefile

Clean up how tests are run in Makefile

GitOrigin-RevId: 9b52ead16392cca09bdf7edc4365f10dc468ccf2
This commit is contained in:
Eric Mc Sween 2019-10-23 08:22:37 -04:00 committed by sharelatex
parent 9902edcfbb
commit 082f790fb6
8 changed files with 82 additions and 63 deletions

View file

@ -9,6 +9,7 @@ DOCKER_COMPOSE := BUILD_NUMBER=$(BUILD_NUMBER) \
BRANCH_NAME=$(BRANCH_NAME) \
PROJECT_NAME=$(PROJECT_NAME) \
MOCHA_GREP=${MOCHA_GREP} \
SHARELATEX_CONFIG=/app/test/acceptance/config/settings.test.coffee \
docker-compose ${DOCKER_COMPOSE_FLAGS}
MODULE_DIRS := $(shell find modules -mindepth 1 -maxdepth 1 -type d -not -name '.git' )
@ -57,6 +58,10 @@ $(MODULE_MAKEFILES): Makefile.module
cp Makefile.module $$makefile; \
done
#
# Clean
#
clean:
rm -f public/stylesheets/*.css*
@ -66,20 +71,44 @@ clean_ci:
docker image prune -af --filter "until=48h"
docker network prune -f
#
# Tests
#
test: test_unit test_frontend test_acceptance
test_module: test_unit_module_run test_acceptance_module_run
test_module: test_unit_module test_acceptance_module
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
#
# Unit tests
#
test_unit_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: test_unit_app test_unit_modules
test_unit_app:
npm -q run test:unit:app -- ${MOCHA_ARGS}
COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --name unit_test_$(BUILD_DIR_NAME) --rm test_unit
COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
test_unit_modules:
@set -e; \
for dir in $(MODULE_DIRS); \
do \
if [ -e $$dir/test/unit ]; then \
$(MAKE) test_unit_module MODULE=$$dir; \
fi; \
done
test_unit_module: $(MODULE_MAKEFILES)
@if [ -e modules/$(MODULE_NAME)/test/unit ]; then \
COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME)_$(MODULE_NAME) $(DOCKER_COMPOSE) down -v -t 0 \
&& cd modules/$(MODULE_NAME) && COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME)_$(MODULE_NAME) $(MAKE) test_unit \
&& cd $(CURDIR) && COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME)_$(MODULE_NAME) $(DOCKER_COMPOSE) down -v -t 0; \
fi
#
# Frontend unit tests
#
test_frontend: compile build_test_frontend test_frontend_run
@ -90,39 +119,45 @@ test_frontend_run:
test_frontend_build_run: build_test_frontend test_frontend_run
test_acceptance: test_acceptance_app_run test_acceptance_modules_run
#
# Acceptance tests
#
test_acceptance_app: test_acceptance_app_run
test_acceptance: test_acceptance_app test_acceptance_modules
test_acceptance_module: test_acceptance_module_run
test_acceptance_run: test_acceptance_app_run test_acceptance_modules_run
test_acceptance_app_run:
test_acceptance_app:
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_acceptance npm -q run test:acceptance:run_dir test/acceptance/src
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_acceptance
COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
test_acceptance_modules_run:
test_acceptance_modules:
@set -e; \
for dir in $(MODULE_DIRS); \
do \
if [ -e $$dir/test/acceptance ]; then \
$(MAKE) test_acceptance_module_run MODULE=$$dir; \
$(MAKE) test_acceptance_module MODULE=$$dir; \
fi; \
done
test_acceptance_module_run: $(MODULE_MAKEFILES)
test_acceptance_module: $(MODULE_MAKEFILES)
@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 tests
#
ci:
MOCHA_ARGS="--reporter tap" \
$(MAKE) test
#
# Lint & format
#
format:
npm -q run format
@ -132,6 +167,10 @@ format_fix:
lint:
npm -q run lint
#
# Build & publish
#
build:
docker build --pull --tag ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) \
--tag gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) \
@ -148,6 +187,10 @@ tar:
COMPOSE_PROJECT_NAME=tar_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
.PHONY:
all add install update test test_unit test_frontend test_acceptance \
test_acceptance_start_service test_acceptance_stop_service \
test_acceptance_run ci ci_clean compile clean css
css_full css minify minify_css minify_es compile compile_full \
compile_css_full compile_modules compile_modules_full clean clean_frontend \
clean_css clean_tests clean_ci test test_module test_unit test_unit_app \
test_unit_modules test_unit_module test_frontend test_frontend_run \
test_frontend_build_run test_acceptance test_acceptance_app \
test_acceptance_modules test_acceptance_module ci format format_fix lint \
build build_test_frontend publish tar

View file

@ -2,15 +2,18 @@ MODULE_NAME := $(notdir $(shell pwd))
MODULE_DIR := modules/$(MODULE_NAME)
PROJECT_NAME = web
DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml
DOCKER_COMPOSE_MODULE_FLAGS := ${DOCKER_COMPOSE_FLAGS} -f $(MODULE_DIR)/docker-compose.yml
DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml --log-level ERROR
DOCKER_COMPOSE := cd ../../ && \
MODULE_DIR=$(MODULE_DIR) \
BUILD_NUMBER=$(BUILD_NUMBER) \
BRANCH_NAME=$(BRANCH_NAME) \
PROJECT_NAME=$(PROJECT_NAME) \
MOCHA_GREP=${MOCHA_GREP} \
docker-compose ${DOCKER_COMPOSE_MODULE_FLAGS}
SHARELATEX_CONFIG=/app/$(MODULE_DIR)/test/acceptance/config/settings.test.coffee \
docker-compose ${DOCKER_COMPOSE_FLAGS}
test_unit:
${DOCKER_COMPOSE} run --rm test_unit npm -q run test:unit:run_dir -- ${MOCHA_ARGS} $(MODULE_DIR)/test/unit/src
test_acceptance:
${DOCKER_COMPOSE} run --rm test_acceptance npm -q run test:acceptance:run_dir -- ${MOCHA_ARGS} $(MODULE_DIR)/test/acceptance/src

View file

@ -1,14 +0,0 @@
#!/bin/bash
set -e;
MOCHA="node_modules/.bin/mocha --exit --recursive --reporter spec --require test/unit/bootstrap.js"
$MOCHA "$@" test/unit/src
for dir in modules/*;
do
if [ -d $dir/test/unit/src ]; then
$MOCHA "$@" $dir/test/unit/src
fi
done

View file

@ -1,6 +0,0 @@
#!/bin/bash
set -e;
MOCHA="node_modules/.bin/mocha --exit --recursive --reporter spec --require test/unit/bootstrap.js"
$MOCHA "$@" test/unit/src

View file

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

View file

@ -9,7 +9,7 @@ services:
build: .
image: ci/$PROJECT_NAME:$BRANCH_NAME-$BUILD_NUMBER
user: node
command: npm run test:unit:ci
command: npm run test:unit:app
test_acceptance:
build: .
@ -22,8 +22,9 @@ services:
PROJECT_HISTORY_ENABLED: 'true'
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley,zotero'
LINKED_URL_PROXY: 'http://localhost:6543'
SHARELATEX_CONFIG: /app/test/acceptance/config/settings.test.coffee
NODE_ENV: test
SHARELATEX_CONFIG:
command: npm run test:acceptance:app
user: root
depends_on:
- redis

View file

@ -12,7 +12,7 @@ services:
working_dir: /app
environment:
MOCHA_GREP: ${MOCHA_GREP}
command: npm run test:unit
command: npm run test:unit:app
user: node
test_acceptance:
@ -27,9 +27,10 @@ services:
PROJECT_HISTORY_ENABLED: 'true'
LINKED_URL_PROXY: 'http://localhost:6543'
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley,zotero'
SHARELATEX_CONFIG: /app/test/acceptance/config/settings.test.coffee
MOCHA_GREP: ${MOCHA_GREP}
NODE_ENV: test
SHARELATEX_CONFIG:
command: npm run test:acceptance:app
depends_on:
- redis
- mongo

View file

@ -12,10 +12,10 @@
"public": "./public"
},
"scripts": {
"test:acceptance:run_dir": "mocha --recursive --reporter spec --require test/acceptance/bootstrap.js --timeout 25000 --exit --grep=$MOCHA_GREP $@",
"test:unit": "bin/unit_test --grep=$MOCHA_GREP $@",
"test:unit:ci": "bin/unit_test --timeout 10000",
"test:unit:app": "bin/unit_test_app $@",
"test:acceptance:run_dir": "mocha --recursive --reporter spec --timeout 25000 --exit --grep=$MOCHA_GREP --require test/acceptance/bootstrap.js",
"test:acceptance:app": "npm run test:acceptance:run_dir -- test/acceptance/src",
"test:unit:run_dir": "mocha --recursive --reporter spec --timeout 25000 --exit --grep=$MOCHA_GREP --require test/unit/bootstrap.js",
"test:unit:app": "npm run test:unit:run_dir -- test/unit/src",
"test:frontend": "karma start",
"test:frontend:single": "karma start --single-run",
"compile": "make compile",