Skip to content

Commit 9c4adc0

Browse files
Update coverage configuration and Travis CI setup for frontend tests (#4948)
* Update coverage configuration and Travis CI setup for frontend tests - Adjusted source paths in .coveragerc to include 'apps/' alongside 'evalai/'. - Modified .travis.yml to create a directory for frontend coverage reports before running tests. - Updated karma.conf.js to change the coverage report directory structure for consistency. * Enhance pre-commit configuration and cleanup script for improved code formatting - Updated .pre-commit-config.yaml to include isort in the cleanup code hook and adjusted arguments for black and isort to enforce a line length of 79. - Modified cleanup_code.sh to run isort for fixing import ordering, ensuring compatibility with the black profile. * Enhance Travis CI configuration for frontend and backend tests - Updated .travis.yml to use 'set -e' for fail-fast behavior in frontend and backend test scripts. - Improved logging messages for better clarity during test execution. - Refactored code quality checks to also utilize 'set -e' for consistent error handling. - Adjusted Dockerfile for nodejs to ensure necessary packages are installed for Chrome and Chromium on both AMD64 and ARM64 architectures. * Refactor Dockerfile to clean up Chrome locale files - Updated the Dockerfile for Node.js to refine the cleanup process for Chrome by preserving essential locale files while removing unnecessary ones. This change enhances the efficiency of the image build process.
1 parent cad05d9 commit 9c4adc0

File tree

7 files changed

+69
-33
lines changed

7 files changed

+69
-33
lines changed

.coveragerc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ omit =
1616
scripts/seed.py
1717
node_modules/
1818
bower_components/
19-
source = evalai/
19+
source =
20+
evalai/
21+
apps/
2022

2123
[report]
2224
exclude_lines =

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ repos:
22
- repo: local
33
hooks:
44
- id: cleanup-code
5-
name: Clean up code (autoflake, autopep8, black)
5+
name: Clean up code (autoflake, autopep8, black, isort)
66
entry: bash scripts/tools/cleanup_code.sh
77
language: system
88
types: [python]
@@ -14,14 +14,14 @@ repos:
1414
hooks:
1515
- id: black
1616
language_version: python3.9
17-
args: ['--check', '--diff', '--verbose']
17+
args: ['--line-length=79', '--check', '--diff', '--verbose']
1818
verbose: true
1919

2020
- repo: https://github.com/pycqa/isort
2121
rev: 5.12.0
2222
hooks:
2323
- id: isort
24-
args: ['--profile=black', '--verbose']
24+
args: ['--profile=black', '--line-length=79', '--check', '--diff', '--verbose']
2525
verbose: true
2626

2727
- repo: https://github.com/pycqa/flake8

.travis.yml

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,53 @@ jobs:
4242
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin || travis_terminate 1; fi
4343
- docker-compose --profile worker_py3_7 --profile worker_py3_8 --profile worker_py3_9 --profile statsd build || travis_terminate 1;
4444

45-
# Frontend Tests
46-
- docker-compose run nodejs bash -c "npm install && gulp dev && karma start --single-run --reporters=junit,coverage && pkill -f chrome || true && pkill -f chromium || true && gulp staging" || travis_terminate 1;
45+
# Frontend Tests - using set -e to fail fast on any error
46+
- |
47+
docker-compose run nodejs bash -c '
48+
set -e
49+
echo "=== Installing dependencies ==="
50+
npm install
51+
echo "=== Building frontend (dev) ==="
52+
gulp dev
53+
echo "=== Running frontend tests ==="
54+
mkdir -p coverage/frontend
55+
karma start --single-run --reporters=junit,coverage
56+
echo "=== Frontend tests passed ==="
57+
# Cleanup browser processes (ignore errors if not found)
58+
pkill -f chrome 2>/dev/null || true
59+
pkill -f chromium 2>/dev/null || true
60+
echo "=== Building frontend (staging) ==="
61+
gulp staging
62+
echo "=== Frontend build complete ==="
63+
' || travis_terminate 1;
4764
48-
# Backend Tests
49-
- docker-compose run -e DJANGO_SETTINGS_MODULE=settings.test django python manage.py flush --noinput || travis_terminate 1;
50-
- docker-compose run -e DJANGO_SETTINGS_MODULE=settings.test django pytest --cov . --cov-config .coveragerc --cov-report=xml:coverage-backend.xml --junitxml=junit-backend.xml -o junit_family=legacy || travis_terminate 1;
65+
# Backend Tests - using set -e to fail fast on any error
66+
- |
67+
docker-compose run -e DJANGO_SETTINGS_MODULE=settings.test django bash -c '
68+
set -e
69+
echo "=== Flushing database ==="
70+
python manage.py flush --noinput
71+
echo "=== Running backend tests with coverage ==="
72+
pytest --cov . --cov-config .coveragerc --cov-report=xml:coverage-backend.xml --junitxml=junit-backend.xml -o junit_family=legacy
73+
echo "=== Backend tests passed ==="
74+
' || travis_terminate 1;
5175
52-
# Check Code Quality
53-
- docker-compose run -e DJANGO_SETTINGS_MODULE=settings.dev -e VERBOSE=1 django bash -c "
54-
echo 'Installing black, flake8, pylint and isort...' &&
55-
pip install black==24.8.0 flake8==3.8.2 pylint==3.3.6 isort==5.12.0 &&
56-
echo 'Running black check...' &&
57-
black --check --diff ./ || { echo 'Black check failed!'; travis_terminate 1; } &&
58-
echo 'Running isort check...' &&
59-
isort --check-only --diff --profile=black ./ || { echo 'isort check failed!'; travis_terminate 1; } &&
60-
echo 'Running flake8 check...' &&
61-
flake8 --config=.flake8 ./ || { echo 'Flake8 check failed!'; travis_terminate 1; } &&
62-
echo 'Running pylint check...' &&
63-
pylint --rcfile=.pylintrc --output-format=colorized --score=y --fail-under=7.5 ./ || { echo 'Pylint check failed!'; travis_terminate 1; } &&
64-
echo 'All code quality checks passed!'" || travis_terminate 1;
76+
# Check Code Quality - using set -e to fail fast on any error
77+
- |
78+
docker-compose run -e DJANGO_SETTINGS_MODULE=settings.dev -e VERBOSE=1 django bash -c '
79+
set -e
80+
echo "=== Installing code quality tools ==="
81+
pip install black==24.8.0 flake8==3.8.2 pylint==3.3.6 isort==5.12.0
82+
echo "=== Running black check ==="
83+
black --check --diff ./
84+
echo "=== Running isort check ==="
85+
isort --check-only --diff --profile=black ./
86+
echo "=== Running flake8 check ==="
87+
flake8 --config=.flake8 ./
88+
echo "=== Running pylint check ==="
89+
pylint --rcfile=.pylintrc --output-format=colorized --score=y --fail-under=7.5 ./
90+
echo "=== All code quality checks passed ==="
91+
' || travis_terminate 1;
6592
6693
after_success:
6794
# Install Codecov CLI

docker/dev/nodejs/Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,23 @@ COPY --from=builder /code/bower_components /code/bower_components
9191

9292
# AMD64-specific stage for Chrome
9393
FROM base AS amd64
94-
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
94+
RUN apt-get update && \
95+
apt-get install -y --no-install-recommends --fix-missing wget gnupg procps && \
96+
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
9597
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \
9698
apt-get update && \
9799
apt-get install -y --no-install-recommends --fix-missing google-chrome-stable libxss1 \
98100
|| (apt-get update && apt-get install -y --no-install-recommends --fix-missing google-chrome-stable libxss1) && \
99101
rm -rf /var/lib/apt/lists/* && \
100102
rm -rf /var/cache/apt/* && \
101-
# Clean Chrome unnecessary files
102-
rm -rf /opt/google/chrome/locales/*.pak && \
103-
find /opt/google/chrome -name "*.pak" ! -name "en-US.pak" -delete 2>/dev/null || true
103+
# Clean Chrome unnecessary locale files only (preserve essential .pak files)
104+
find /opt/google/chrome/locales -name "*.pak" ! -name "en-US.pak" -delete 2>/dev/null || true
104105

105106
# ARM64-specific stage for Chromium
106107
FROM base AS arm64
107108
RUN apt-get update && \
108-
apt-get install -y --no-install-recommends --fix-missing chromium libxss1 \
109-
|| (apt-get update && apt-get install -y --no-install-recommends --fix-missing chromium libxss1) && \
109+
apt-get install -y --no-install-recommends --fix-missing chromium libxss1 procps \
110+
|| (apt-get update && apt-get install -y --no-install-recommends --fix-missing chromium libxss1 procps) && \
110111
ln -sf /usr/bin/chromium /usr/bin/google-chrome && \
111112
rm -rf /var/lib/apt/lists/* && \
112113
rm -rf /var/cache/apt/*

frontend/tests/controllers-test/challengeListCtrl.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ describe('Unit tests for challenge list controller', function () {
1919

2020
describe('Global variables', function () {
2121
it('has default values', function () {
22-
spyOn(utilities, 'getData');
2322
spyOn(utilities, 'showLoader');
23+
spyOn(utilities, 'hideButton');
2424

2525
vm = createController();
26-
expect(utilities.getData).toHaveBeenCalledWith('userKey');
27-
expect(vm.userKey).toEqual(utilities.getData('userKey'));
2826
expect(utilities.showLoader).toHaveBeenCalled();
27+
expect(utilities.hideButton).toHaveBeenCalled();
2928
expect(vm.currentList).toEqual([]);
3029
expect(vm.upcomingList).toEqual([]);
3130
expect(vm.pastList).toEqual([]);

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ module.exports = function(config) {
125125

126126
coverageReporter: {
127127
includeAllSources: true,
128-
dir: 'coverage/frontend/',
128+
dir: 'coverage/',
129129
reporters: [
130-
{ type: 'lcovonly', subdir: '.', file: 'lcov.info' },
130+
{ type: 'lcovonly', subdir: 'frontend', file: 'lcov.info' },
131131
{ type: 'text-summary' }
132132
]
133133
}

scripts/tools/cleanup_code.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ for file in $FILTERED_FILES; do
8080
black --line-length 79 --quiet "$file" || true
8181
done
8282

83+
# Fix import ordering with isort (using black-compatible profile)
84+
echo ""
85+
echo "Running isort to fix import ordering..."
86+
for file in $FILTERED_FILES; do
87+
isort --profile=black --line-length=79 --quiet "$file" || true
88+
done
89+
8390
# Stage the modified files so pylint/flake8 check the cleaned versions
8491
# Only stage files that were already staged
8592
echo ""

0 commit comments

Comments
 (0)