Skip to content

Commit

Permalink
temp: put back paver checks for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick committed Oct 28, 2024
1 parent c76feed commit 1fc2c24
Show file tree
Hide file tree
Showing 20 changed files with 2,199 additions and 7 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/js-tests-paver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Javascript tests PAVER

on:
pull_request:
push:
branches:
- master

jobs:
run_tests:
name: JS
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: [18, 20]
python-version:
- "3.11"

steps:
- uses: actions/checkout@v4
- name: Fetch master to compare coverage
run: git fetch --depth=1 origin master

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Setup npm
run: npm i -g [email protected]

- name: Install Firefox 123.0
run: |
sudo apt-get purge firefox
wget "https://ftp.mozilla.org/pub/firefox/releases/123.0/linux-x86_64/en-US/firefox-123.0.tar.bz2"
tar -xjf firefox-123.0.tar.bz2
sudo mv firefox /opt/firefox
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
- name: Install Required System Packages
run: sudo apt-get update && sudo apt-get install libxmlsec1-dev ubuntu-restricted-extras xvfb

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache-dir
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Cache pip dependencies
id: cache-dependencies
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache-dir.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('requirements/edx/base.txt') }}
restore-keys: ${{ runner.os }}-pip-

- name: Install Required Python Dependencies
run: |
make base-requirements
- uses: c-hive/gha-npm-cache@v1
- name: Run JS Tests
env:
TEST_SUITE: js-unit
SCRIPT_TO_RUN: ./scripts/generic-ci-tests.sh
run: |
npm install -g jest
xvfb-run --auto-servernum ./scripts/all-tests.sh
- name: Save Job Artifacts
uses: actions/upload-artifact@v4
with:
name: Build-Artifacts
path: |
reports/**/*
test_root/log/*.png
test_root/log/*.log
**/TEST-*.xml
overwrite: true
2 changes: 1 addition & 1 deletion .github/workflows/js-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- uses: c-hive/gha-npm-cache@v1

- name: Install npm
run: npm ci
run: npm ci

- name: Run JS Tests
run: |
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/quality-checks-paver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Quality checks PAVER

on:
pull_request:
push:
branches:
- master
- open-release/lilac.master

jobs:
run_tests:
name: Quality Others
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]
python-version:
- "3.11"
node-version: [20]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Fetch base branch for comparison
run: git fetch --depth=1 origin ${{ github.base_ref }}

- name: Install Required System Packages
run: sudo apt-get update && sudo apt-get install libxmlsec1-dev

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Setup npm
run: npm i -g [email protected]

- name: Get pip cache dir
id: pip-cache-dir
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Cache pip dependencies
id: cache-dependencies
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache-dir.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('requirements/edx/testing.txt') }}
restore-keys: ${{ runner.os }}-pip-

- name: Install Required Python Dependencies
env:
PIP_SRC: ${{ runner.temp }}
run: |
make test-requirements
- name: Run Quality Tests
env:
TEST_SUITE: quality
SCRIPT_TO_RUN: ./scripts/generic-ci-tests.sh
PIP_SRC: ${{ runner.temp }}
TARGET_BRANCH: ${{ github.base_ref }}
run: |
./scripts/all-tests.sh
- name: Save Job Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: Build-Artifacts
path: |
**/reports/**/*
test_root/log/**/*.log
*.log
overwrite: true
10 changes: 5 additions & 5 deletions .github/workflows/quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ jobs:
PIP_SRC: ${{ runner.temp }}
run: |
make test-requirements
- name: Install npm
env:
PIP_SRC: ${{ runner.temp }}
run: npm ci
run: npm ci

- name: Install python packages
env:
PIP_SRC: ${{ runner.temp }}
run: |
pip install -e .
- name: Run Quality Tests
env:
PIP_SRC: ${{ runner.temp }}
Expand All @@ -83,7 +83,7 @@ jobs:
make xsslint
make pii_check
make check_keywords
- name: Save Job Artifacts
if: always()
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion pavelib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""


from . import assets
from . import assets, js_test, prereqs, quality
143 changes: 143 additions & 0 deletions pavelib/js_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
"""
Javascript test tasks
"""


import os
import re
import sys

from paver.easy import cmdopts, needs, sh, task

from pavelib.utils.envs import Env
from pavelib.utils.test.suites import JestSnapshotTestSuite, JsTestSuite
from pavelib.utils.timer import timed

try:
from pygments.console import colorize
except ImportError:
colorize = lambda color, text: text

__test__ = False # do not collect


@task
@needs(
'pavelib.prereqs.install_node_prereqs',
'pavelib.utils.test.utils.clean_reports_dir',
)
@cmdopts([
("suite=", "s", "Test suite to run"),
("mode=", "m", "dev or run"),
("coverage", "c", "Run test under coverage"),
("port=", "p", "Port to run test server on (dev mode only)"),
('skip-clean', 'C', 'skip cleaning repository before running tests'),
('skip_clean', None, 'deprecated in favor of skip-clean'),
], share_with=["pavelib.utils.tests.utils.clean_reports_dir"])
@timed
def test_js(options):
"""
Run the JavaScript tests
"""
mode = getattr(options, 'mode', 'run')
port = None
skip_clean = getattr(options, 'skip_clean', False)

if mode == 'run':
suite = getattr(options, 'suite', 'all')
coverage = getattr(options, 'coverage', False)
elif mode == 'dev':
suite = getattr(options, 'suite', None)
coverage = False
port = getattr(options, 'port', None)
else:
sys.stderr.write("Invalid mode. Please choose 'dev' or 'run'.")
return

if (suite != 'all') and (suite not in Env.JS_TEST_ID_KEYS):
sys.stderr.write(
"Unknown test suite. Please choose from ({suites})\n".format(
suites=", ".join(Env.JS_TEST_ID_KEYS)
)
)
return

if suite != 'jest-snapshot':
test_suite = JsTestSuite(suite, mode=mode, with_coverage=coverage, port=port, skip_clean=skip_clean)
test_suite.run()

if (suite == 'jest-snapshot') or (suite == 'all'): # lint-amnesty, pylint: disable=consider-using-in
test_suite = JestSnapshotTestSuite('jest')
test_suite.run()


@task
@cmdopts([
("suite=", "s", "Test suite to run"),
("coverage", "c", "Run test under coverage"),
])
@timed
def test_js_run(options):
"""
Run the JavaScript tests and print results to the console
"""
options.mode = 'run'
test_js(options)


@task
@cmdopts([
("suite=", "s", "Test suite to run"),
("port=", "p", "Port to run test server on"),
])
@timed
def test_js_dev(options):
"""
Run the JavaScript tests in your default browsers
"""
options.mode = 'dev'
test_js(options)


@task
@needs('pavelib.prereqs.install_coverage_prereqs')
@cmdopts([
("compare-branch=", "b", "Branch to compare against, defaults to origin/master"),
], share_with=['coverage'])
@timed
def diff_coverage(options):
"""
Build the diff coverage reports
"""
compare_branch = options.get('compare_branch', 'origin/master')

# Find all coverage XML files (both Python and JavaScript)
xml_reports = []

for filepath in Env.REPORT_DIR.walk():
if bool(re.match(r'^coverage.*\.xml$', filepath.basename())):
xml_reports.append(filepath)

if not xml_reports:
err_msg = colorize(
'red',
"No coverage info found. Run `paver test` before running "
"`paver coverage`.\n"
)
sys.stderr.write(err_msg)
else:
xml_report_str = ' '.join(xml_reports)
diff_html_path = os.path.join(Env.REPORT_DIR, 'diff_coverage_combined.html')

# Generate the diff coverage reports (HTML and console)
# The --diff-range-notation parameter is a workaround for https://github.com/Bachmann1234/diff_cover/issues/153
sh(
"diff-cover {xml_report_str} --diff-range-notation '..' --compare-branch={compare_branch} "
"--html-report {diff_html_path}".format(
xml_report_str=xml_report_str,
compare_branch=compare_branch,
diff_html_path=diff_html_path,
)
)

print("\n")
22 changes: 22 additions & 0 deletions pavelib/paver_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Pytest fixtures for the pavelib unit tests.
"""


import os
from shutil import rmtree

import pytest

from pavelib.utils.envs import Env


@pytest.fixture(autouse=True, scope='session')
def delete_quality_junit_xml():
"""
Delete the JUnit XML results files for quality check tasks run during the
unit tests.
"""
yield
if os.path.exists(Env.QUALITY_DIR):
rmtree(Env.QUALITY_DIR, ignore_errors=True)
Loading

0 comments on commit 1fc2c24

Please sign in to comment.