Skip to content

Commit

Permalink
feat: tutor-contrib-test-legacy-js (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick authored Dec 18, 2024
1 parent d50d846 commit c1d6855
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ community:
Plugin Status (*Experimental*, *Production*, or *Deprecated*)
=================================== ======================================================
tutor-contrib-learner-dashboard-mfe Deprecated
tutor-contrib-test-legacy-js "Production" (Supported For Developers)
=================================== ======================================================

Getting Started
Expand Down
7 changes: 7 additions & 0 deletions plugins/tutor-contrib-test-legacy-js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.*.swp
!.gitignore
TODO
__pycache__
*.egg-info/
/build/
/dist/
1 change: 1 addition & 0 deletions plugins/tutor-contrib-test-legacy-js/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include tutor_test_legacy_js/patches *
28 changes: 28 additions & 0 deletions plugins/tutor-contrib-test-legacy-js/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.DEFAULT_GOAL := help
.PHONY: docs
SRC_DIRS = ./tutor_test_legacy_js
BLACK_OPTS = --exclude templates ${SRC_DIRS}

# Warning: These checks are not necessarily run on every PR.
test: test-lint test-types test-format # Run some static checks.

test-format: ## Run code formatting tests
black --check --diff $(BLACK_OPTS)

test-lint: ## Run code linting tests
pylint --errors-only --enable=unused-import,unused-argument --ignore=templates --ignore=docs/_ext ${SRC_DIRS}

test-types: ## Run type checks.
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS}

format: ## Format code automatically
black $(BLACK_OPTS)

isort: ## Sort imports. This target is not mandatory because the output may be incompatible with black formatting. Provided for convenience purposes.
isort --skip=templates ${SRC_DIRS}

ESCAPE = 
help: ## Print this help
@grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \
| sed 's/######* \(.*\)/@ $(ESCAPE)[1;31m\1$(ESCAPE)[0m/g' | tr '@' '\n' \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'
36 changes: 36 additions & 0 deletions plugins/tutor-contrib-test-legacy-js/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
test-legacy-js plugin for `Tutor <https://docs.tutor.overhang.io>`__
====================================================================

This plugin allows edx-platform developers to run legacy JavaScript tests by adding some system requirements to the ``openedx-dev`` image.

This is a plugin rather than an upstream feature because adding these requirements directly to the core ``openedx-dev`` image would nontrivially increase its size and build time. Only a small minority of edx-platform developers need to run unit tests on the mostly-deprecated legacy JavaScript code.

Installation
------------

This will install the Test Legacy JS plugin directly from Github::

pip install git+https://github.com/openedx/openedx-tutor-plugins.git#subdirectory=plugins/tutor-contrib-test-legacy-js

Alternatively, you can clone the parent repository locally and install it from the checkout::

git clone https://github.com/openedx/openedx-tutor-plugins.git
cd openedx-tutor-plugins/plugins/tutor-contrib-test-legacy-js
pip install -e .

Usage
-----

Once installed, run the following commands to enable it::

tutor plugins enable test-legacy-js
tutor images build openedx-dev

This should allow you to run legacy edx-platform JS tests::

tutor dev run lms npm run test

License
-------

This software is licensed under the terms of the AGPLv3.
60 changes: 60 additions & 0 deletions plugins/tutor-contrib-test-legacy-js/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import io
import os
from setuptools import setup, find_packages

HERE = os.path.abspath(os.path.dirname(__file__))


def load_readme():
with io.open(os.path.join(HERE, "README.rst"), "rt", encoding="utf8") as f:
return f.read()


def load_about():
about = {}
with io.open(
os.path.join(HERE, "tutor_test_legacy_js", "__about__.py"),
"rt",
encoding="utf-8",
) as f:
exec(f.read(), about) # pylint: disable=exec-used
return about


ABOUT = load_about()


setup(
name="tutor-contrib-test-legacy-js",
version=ABOUT["__version__"],
url="https://github.com/openedx/openedx-tutor-plugins",
project_urls={
"Code": "https://github.com/openedx/openedx-tutor-plugins",
"Issue tracker": "https://github.com/openedx/openedx-tutor-plugins/issues",
},
license="AGPLv3",
author="Adolfo R. Brandes",
description="test-legacy-js plugin for Tutor",
long_description=load_readme(),
packages=find_packages(exclude=["tests*"]),
include_package_data=True,
python_requires=">=3.9",
install_requires=["tutor"],
extras_require={"dev": ["tutor[dev]>=16.0.0,<17.0.0"]},
entry_points={
"tutor.plugin.v1": [
"test-legacy-js = tutor_test_legacy_js.plugin"
]
},
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.0"
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
USER root
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && \
apt install -y libxmlsec1-dev ubuntu-restricted-extras xvfb libgtk-3-0
RUN cd /opt && \
(curl -L "https://ftp.mozilla.org/pub/firefox/releases/123.0/linux-x86_64/en-US/firefox-123.0.tar.bz2" > ffox.tar.gz) && \
tar -xjf ffox.tar.gz && \
ln -s /opt/firefox/firefox /usr/bin/firefox
USER app
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

import os
import os.path
from glob import glob

import importlib.resources

from tutor import hooks

########################################
# PATCH LOADING
########################################

# For each file in tutor_test_legacy_js/patches,
# apply a patch based on the file's name and contents.
for path in glob(
os.path.join(
importlib.resources.files("tutor_test_legacy_js") / "patches",
"*",
)
):
with open(path, encoding="utf-8") as patch_file:
hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read()))

0 comments on commit c1d6855

Please sign in to comment.