diff --git a/.github/workflows/test_js.yaml b/.github/workflows/test_js.yaml index 2bfe681..21661d4 100644 --- a/.github/workflows/test_js.yaml +++ b/.github/workflows/test_js.yaml @@ -1,34 +1,20 @@ -name: JS Test chosen +name: JS tests -on: - push: - paths: - - '**.js' +on: [push] jobs: test: - name: TEST CHOSEN + name: Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Install - run: | - npm --save-dev install \ - qunit \ - karma \ - karma-qunit \ - karma-coverage \ - karma-chrome-launcher \ - karma-module-resolver-preprocessor - npm --no-save install https://github.com/jquery/jquery#main + - name: Install + run: | + corepack enable + make nodejs - - name: Run tests - run: | - node_modules/karma/bin/karma start js/karma.conf.js - - - name: Run coverage - run: | - npm run karma-test:coverage + - name: Run tests + run: make wtr diff --git a/.github/workflows/test_py.yaml b/.github/workflows/test_py.yaml index 2b55bd5..69afbd4 100644 --- a/.github/workflows/test_py.yaml +++ b/.github/workflows/test_py.yaml @@ -1,9 +1,6 @@ -name: PY Test chosen +name: Python tests -on: - push: - paths: - - '**.py' +on: [push] jobs: test: @@ -19,34 +16,35 @@ jobs: - macos-latest python: - - "2.7" - - "3.7" - "3.8" - "3.9" - "3.10" + - "3.11" + - "3.12" + - "3.13" steps: - - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - - - name: Install - run: | - pip install wheel - pip install coverage - pip install lxml - pip install zope.testrunner - pip install https://github.com/conestack/webresource/archive/master.zip - pip install https://github.com/conestack/yafowil/archive/master.zip - pip install -e .[test] - - name: Run tests - run: | - python --version - python -m yafowil.widget.chosen.tests - - name: Run coverage - run: | - coverage run --source=src/yafowil/widget/chosen --omit=src/yafowil/widget/chosen/example.py -m yafowil.widget.chosen.tests - coverage report --fail-under=99 \ No newline at end of file + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + + - name: Install + run: | + pip install wheel + pip install coverage + pip install https://github.com/conestack/webresource/archive/master.zip + pip install https://github.com/conestack/yafowil/archive/master.zip + pip install -e .[test] + + - name: Run tests + run: | + python --version + python -m pytest src/yafowil/widget/chosen/tests + + - name: Run coverage + run: | + coverage run --source=src/yafowil/widget/chosen --omit=src/yafowil/widget/chosen/example.py -m pytest src/yafowil/widget/chosen/tests + coverage report --fail-under=99 diff --git a/.gitignore b/.gitignore index 904259c..ea39d26 100644 --- a/.gitignore +++ b/.gitignore @@ -2,11 +2,16 @@ *.pyc *.pyo /.coverage +/.mxmake/ +/coverage/ /dist/ /htmlcov/ /js/karma/ /node_modules/ /package-lock.json +/pnpm-lock.yaml /py2/ /py3/ /pypy3/ +/requirements-mxdev.txt +/venv/ \ No newline at end of file diff --git a/LICENSE.rst b/LICENSE.rst index f1304c3..7eab66e 100644 --- a/LICENSE.rst +++ b/LICENSE.rst @@ -2,7 +2,7 @@ License ======= Copyright (c) 2012-2021, BlueDynamics Alliance, Austria, Germany, Switzerland -Copyright (c) 2021-2022, Yafowil Contributors +Copyright (c) 2021-2024, Yafowil Contributors All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..aaf91c9 --- /dev/null +++ b/Makefile @@ -0,0 +1,581 @@ +############################################################################## +# THIS FILE IS GENERATED BY MXMAKE +# +# DOMAINS: +#: core.base +#: core.mxenv +#: core.mxfiles +#: core.packages +#: js.nodejs +#: js.rollup +#: js.wtr +#: qa.coverage +#: qa.test +# +# SETTINGS (ALL CHANGES MADE BELOW SETTINGS WILL BE LOST) +############################################################################## + +## core.base + +# `deploy` target dependencies. +# No default value. +DEPLOY_TARGETS?= + +# target to be executed when calling `make run` +# No default value. +RUN_TARGET?= + +# Additional files and folders to remove when running clean target +# No default value. +CLEAN_FS?= + +# Optional makefile to include before default targets. This can +# be used to provide custom targets or hook up to existing targets. +# Default: include.mk +INCLUDE_MAKEFILE?=include.mk + +# Optional additional directories to be added to PATH in format +# `/path/to/dir/:/path/to/other/dir`. Gets inserted first, thus gets searched +# first. +# No default value. +EXTRA_PATH?= + +## js.nodejs + +# The package manager to use. Defaults to `npm`. Possible values +# are `npm` and `pnpm` +# Default: npm +NODEJS_PACKAGE_MANAGER?=pnpm + +# Value for `--prefix` option when installing packages. +# Default: . +NODEJS_PREFIX?=. + +# Packages to install with `--no-save` option. +# No default value. +NODEJS_PACKAGES?= + +# Packages to install with `--save-dev` option. +# No default value. +NODEJS_DEV_PACKAGES?= + +# Packages to install with `--save-prod` option. +# No default value. +NODEJS_PROD_PACKAGES?= + +# Packages to install with `--save-optional` option. +# No default value. +NODEJS_OPT_PACKAGES?= + +# Additional install options. Possible values are `--save-exact` +# and `--save-bundle`. +# No default value. +NODEJS_INSTALL_OPTS?= + +## js.wtr + +# Web test runner config file. +# Default: wtr.config.mjs +WTR_CONFIG?=js/wtr.config.mjs + +# Web test runner additional command line options. +# Default: --coverage +WTR_OPTIONS?=--coverage + +## js.rollup + +# Rollup config file. +# Default: rollup.conf.js +ROLLUP_CONFIG?=js/rollup.conf.js + +## core.mxenv + +# Primary Python interpreter to use. It is used to create the +# virtual environment if `VENV_ENABLED` and `VENV_CREATE` are set to `true`. +# Default: python3 +PRIMARY_PYTHON?=python3 + +# Minimum required Python version. +# Default: 3.9 +PYTHON_MIN_VERSION?=3.9 + +# Install packages using the given package installer method. +# Supported are `pip` and `uv`. If uv is used, its global availability is +# checked. Otherwise, it is installed, either in the virtual environment or +# using the `PRIMARY_PYTHON`, dependent on the `VENV_ENABLED` setting. If +# `VENV_ENABLED` and uv is selected, uv is used to create the virtual +# environment. +# Default: pip +PYTHON_PACKAGE_INSTALLER?=uv + +# Flag whether to use a global installed 'uv' or install +# it in the virtual environment. +# Default: false +MXENV_UV_GLOBAL?=false + +# Flag whether to use virtual environment. If `false`, the +# interpreter according to `PRIMARY_PYTHON` found in `PATH` is used. +# Default: true +VENV_ENABLED?=true + +# Flag whether to create a virtual environment. If set to `false` +# and `VENV_ENABLED` is `true`, `VENV_FOLDER` is expected to point to an +# existing virtual environment. +# Default: true +VENV_CREATE?=true + +# The folder of the virtual environment. +# If `VENV_ENABLED` is `true` and `VENV_CREATE` is true it is used as the +# target folder for the virtual environment. If `VENV_ENABLED` is `true` and +# `VENV_CREATE` is false it is expected to point to an existing virtual +# environment. If `VENV_ENABLED` is `false` it is ignored. +# Default: .venv +VENV_FOLDER?=venv + +# mxdev to install in virtual environment. +# Default: mxdev +MXDEV?=mxdev + +# mxmake to install in virtual environment. +# Default: mxmake +MXMAKE?=mxmake + +## core.mxfiles + +# The config file to use. +# Default: mx.ini +PROJECT_CONFIG?=mx.ini + +## core.packages + +# Allow prerelease and development versions. +# By default, the package installer only finds stable versions. +# Default: false +PACKAGES_ALLOW_PRERELEASES?=false + +## qa.test + +# The command which gets executed. Defaults to the location the +# :ref:`run-tests` template gets rendered to if configured. +# Default: .mxmake/files/run-tests.sh +TEST_COMMAND?=$(VENV_FOLDER)/bin/pytest src/yafowil/widget/chosen/tests + +# Additional Python requirements for running tests to be +# installed (via pip). +# Default: pytest +TEST_REQUIREMENTS?=pytest + +# Additional make targets the test target depends on. +# No default value. +TEST_DEPENDENCY_TARGETS?= + +## qa.coverage + +# The command which gets executed. Defaults to the location the +# :ref:`run-coverage` template gets rendered to if configured. +# Default: .mxmake/files/run-coverage.sh +COVERAGE_COMMAND?=\ + $(VENV_FOLDER)/bin/coverage run \ + --omit src/yafowil/widget/chosen/example.py \ + --source src/yafowil/widget/chosen \ + -m pytest src/yafowil/widget/chosen/tests \ + && $(VENV_FOLDER)/bin/coverage report --fail-under=99 + + +############################################################################## +# END SETTINGS - DO NOT EDIT BELOW THIS LINE +############################################################################## + +INSTALL_TARGETS?= +DIRTY_TARGETS?= +CLEAN_TARGETS?= +PURGE_TARGETS?= +CHECK_TARGETS?= +TYPECHECK_TARGETS?= +FORMAT_TARGETS?= + +export PATH:=$(if $(EXTRA_PATH),$(EXTRA_PATH):,)$(PATH) + +# Defensive settings for make: https://tech.davis-hansson.com/p/make/ +SHELL:=bash +.ONESHELL: +# for Makefile debugging purposes add -x to the .SHELLFLAGS +.SHELLFLAGS:=-eu -o pipefail -O inherit_errexit -c +.SILENT: +.DELETE_ON_ERROR: +MAKEFLAGS+=--warn-undefined-variables +MAKEFLAGS+=--no-builtin-rules + +# mxmake folder +MXMAKE_FOLDER?=.mxmake + +# Sentinel files +SENTINEL_FOLDER?=$(MXMAKE_FOLDER)/sentinels +SENTINEL?=$(SENTINEL_FOLDER)/about.txt +$(SENTINEL): $(firstword $(MAKEFILE_LIST)) + @mkdir -p $(SENTINEL_FOLDER) + @echo "Sentinels for the Makefile process." > $(SENTINEL) + +############################################################################## +# nodejs +############################################################################## + +export PATH:=$(shell pwd)/$(NODEJS_PREFIX)/node_modules/.bin:$(PATH) + + +NODEJS_TARGET:=$(SENTINEL_FOLDER)/nodejs.sentinel +$(NODEJS_TARGET): $(SENTINEL) + @echo "Install nodejs packages" + @test -z "$(NODEJS_DEV_PACKAGES)" \ + && echo "No dev packages to be installed" \ + || $(NODEJS_PACKAGE_MANAGER) --prefix $(NODEJS_PREFIX) install \ + --save-dev \ + $(NODEJS_INSTALL_OPTS) \ + $(NODEJS_DEV_PACKAGES) + @test -z "$(NODEJS_PROD_PACKAGES)" \ + && echo "No prod packages to be installed" \ + || $(NODEJS_PACKAGE_MANAGER) --prefix $(NODEJS_PREFIX) install \ + --save-prod \ + $(NODEJS_INSTALL_OPTS) \ + $(NODEJS_PROD_PACKAGES) + @test -z "$(NODEJS_OPT_PACKAGES)" \ + && echo "No opt packages to be installed" \ + || $(NODEJS_PACKAGE_MANAGER) --prefix $(NODEJS_PREFIX) install \ + --save-optional \ + $(NODEJS_INSTALL_OPTS) \ + $(NODEJS_OPT_PACKAGES) + @test -z "$(NODEJS_PACKAGES)" \ + && echo "No packages to be installed" \ + || $(NODEJS_PACKAGE_MANAGER) --prefix $(NODEJS_PREFIX) install \ + --no-save \ + $(NODEJS_PACKAGES) + @touch $(NODEJS_TARGET) + +.PHONY: nodejs +nodejs: $(NODEJS_TARGET) + +.PHONY: nodejs-dirty +nodejs-dirty: + @rm -f $(NODEJS_TARGET) + +.PHONY: nodejs-clean +nodejs-clean: nodejs-dirty + @rm -rf $(NODEJS_PREFIX)/node_modules + +INSTALL_TARGETS+=nodejs +DIRTY_TARGETS+=nodejs-dirty +CLEAN_TARGETS+=nodejs-clean + +############################################################################## +# web test runner +############################################################################## + +NODEJS_DEV_PACKAGES+=\ + @web/test-runner \ + @web/dev-server-import-maps + +.PHONY: wtr +wtr: $(NODEJS_TARGET) + @web-test-runner $(WTR_OPTIONS) --config $(WTR_CONFIG) + +############################################################################## +# rollup +############################################################################## + +NODEJS_DEV_PACKAGES+=\ + rollup \ + rollup-plugin-cleanup \ + @rollup/plugin-terser + +.PHONY: rollup +rollup: $(NODEJS_TARGET) + @rollup --config $(ROLLUP_CONFIG) + +############################################################################## +# mxenv +############################################################################## + +export OS:=$(OS) + +# Determine the executable path +ifeq ("$(VENV_ENABLED)", "true") +export VIRTUAL_ENV=$(abspath $(VENV_FOLDER)) +ifeq ("$(OS)", "Windows_NT") +VENV_EXECUTABLE_FOLDER=$(VIRTUAL_ENV)/Scripts +else +VENV_EXECUTABLE_FOLDER=$(VIRTUAL_ENV)/bin +endif +export PATH:=$(VENV_EXECUTABLE_FOLDER):$(PATH) +MXENV_PYTHON=python +else +MXENV_PYTHON=$(PRIMARY_PYTHON) +endif + +# Determine the package installer +ifeq ("$(PYTHON_PACKAGE_INSTALLER)","uv") +PYTHON_PACKAGE_COMMAND=uv pip +else +PYTHON_PACKAGE_COMMAND=$(MXENV_PYTHON) -m pip +endif + +MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel +$(MXENV_TARGET): $(SENTINEL) + @$(PRIMARY_PYTHON) -c "import sys; vi = sys.version_info; sys.exit(1 if (int(vi[0]), int(vi[1])) >= tuple(map(int, '$(PYTHON_MIN_VERSION)'.split('.'))) else 0)" \ + && echo "Need Python >= $(PYTHON_MIN_VERSION)" && exit 1 || : + @[[ "$(VENV_ENABLED)" == "true" && "$(VENV_FOLDER)" == "" ]] \ + && echo "VENV_FOLDER must be configured if VENV_ENABLED is true" && exit 1 || : + @[[ "$(VENV_ENABLED)$(PYTHON_PACKAGE_INSTALLER)" == "falseuv" ]] \ + && echo "Package installer uv does not work with a global Python interpreter." && exit 1 || : +ifeq ("$(VENV_ENABLED)", "true") +ifeq ("$(VENV_CREATE)", "true") +ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)","uvtrue") + @echo "Setup Python Virtual Environment using package 'uv' at '$(VENV_FOLDER)'" + @uv venv -p $(PRIMARY_PYTHON) --seed $(VENV_FOLDER) +else + @echo "Setup Python Virtual Environment using module 'venv' at '$(VENV_FOLDER)'" + @$(PRIMARY_PYTHON) -m venv $(VENV_FOLDER) + @$(MXENV_PYTHON) -m ensurepip -U +endif +endif +else + @echo "Using system Python interpreter" +endif +ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)","uvfalse") + @echo "Install uv" + @$(MXENV_PYTHON) -m pip install uv +endif + @$(PYTHON_PACKAGE_COMMAND) install -U pip setuptools wheel + @echo "Install/Update MXStack Python packages" + @$(PYTHON_PACKAGE_COMMAND) install -U $(MXDEV) $(MXMAKE) + @touch $(MXENV_TARGET) + +.PHONY: mxenv +mxenv: $(MXENV_TARGET) + +.PHONY: mxenv-dirty +mxenv-dirty: + @rm -f $(MXENV_TARGET) + +.PHONY: mxenv-clean +mxenv-clean: mxenv-dirty +ifeq ("$(VENV_ENABLED)", "true") +ifeq ("$(VENV_CREATE)", "true") + @rm -rf $(VENV_FOLDER) +endif +else + @$(PYTHON_PACKAGE_COMMAND) uninstall -y $(MXDEV) + @$(PYTHON_PACKAGE_COMMAND) uninstall -y $(MXMAKE) +endif + +INSTALL_TARGETS+=mxenv +DIRTY_TARGETS+=mxenv-dirty +CLEAN_TARGETS+=mxenv-clean + +############################################################################## +# mxfiles +############################################################################## + +# case `core.sources` domain not included +SOURCES_TARGET?= + +# File generation target +MXMAKE_FILES?=$(MXMAKE_FOLDER)/files + +# set environment variables for mxmake +define set_mxfiles_env + @export MXMAKE_FILES=$(1) +endef + +# unset environment variables for mxmake +define unset_mxfiles_env + @unset MXMAKE_FILES +endef + +$(PROJECT_CONFIG): +ifneq ("$(wildcard $(PROJECT_CONFIG))","") + @touch $(PROJECT_CONFIG) +else + @echo "[settings]" > $(PROJECT_CONFIG) +endif + +LOCAL_PACKAGE_FILES:=$(wildcard pyproject.toml setup.cfg setup.py requirements.txt constraints.txt) + +FILES_TARGET:=requirements-mxdev.txt +$(FILES_TARGET): $(PROJECT_CONFIG) $(MXENV_TARGET) $(SOURCES_TARGET) $(LOCAL_PACKAGE_FILES) + @echo "Create project files" + @mkdir -p $(MXMAKE_FILES) + $(call set_mxfiles_env,$(MXMAKE_FILES)) + @mxdev -n -c $(PROJECT_CONFIG) + $(call unset_mxfiles_env) + @test -e $(MXMAKE_FILES)/pip.conf && cp $(MXMAKE_FILES)/pip.conf $(VENV_FOLDER)/pip.conf || : + @touch $(FILES_TARGET) + +.PHONY: mxfiles +mxfiles: $(FILES_TARGET) + +.PHONY: mxfiles-dirty +mxfiles-dirty: + @touch $(PROJECT_CONFIG) + +.PHONY: mxfiles-clean +mxfiles-clean: mxfiles-dirty + @rm -rf constraints-mxdev.txt requirements-mxdev.txt $(MXMAKE_FILES) + +INSTALL_TARGETS+=mxfiles +DIRTY_TARGETS+=mxfiles-dirty +CLEAN_TARGETS+=mxfiles-clean + +############################################################################## +# packages +############################################################################## + +# additional sources targets which requires package re-install on change +-include $(MXMAKE_FILES)/additional_sources_targets.mk +ADDITIONAL_SOURCES_TARGETS?= + +INSTALLED_PACKAGES=$(MXMAKE_FILES)/installed.txt + +ifeq ("$(PACKAGES_ALLOW_PRERELEASES)","true") +ifeq ("$(PYTHON_PACKAGE_INSTALLER)","uv") +PACKAGES_PRERELEASES=--prerelease=allow +else +PACKAGES_PRERELEASES=--pre +endif +else +PACKAGES_PRERELEASES= +endif + +PACKAGES_TARGET:=$(INSTALLED_PACKAGES) +$(PACKAGES_TARGET): $(FILES_TARGET) $(ADDITIONAL_SOURCES_TARGETS) + @echo "Install python packages" + @$(PYTHON_PACKAGE_COMMAND) install $(PACKAGES_PRERELEASES) -r $(FILES_TARGET) + @$(PYTHON_PACKAGE_COMMAND) freeze > $(INSTALLED_PACKAGES) + @touch $(PACKAGES_TARGET) + +.PHONY: packages +packages: $(PACKAGES_TARGET) + +.PHONY: packages-dirty +packages-dirty: + @rm -f $(PACKAGES_TARGET) + +.PHONY: packages-clean +packages-clean: + @test -e $(FILES_TARGET) \ + && test -e $(MXENV_PYTHON) \ + && $(MXENV_PYTHON) -m pip uninstall -y -r $(FILES_TARGET) \ + || : + @rm -f $(PACKAGES_TARGET) + +INSTALL_TARGETS+=packages +DIRTY_TARGETS+=packages-dirty +CLEAN_TARGETS+=packages-clean + +############################################################################## +# test +############################################################################## + +TEST_TARGET:=$(SENTINEL_FOLDER)/test.sentinel +$(TEST_TARGET): $(MXENV_TARGET) + @echo "Install $(TEST_REQUIREMENTS)" + @$(PYTHON_PACKAGE_COMMAND) install $(TEST_REQUIREMENTS) + @touch $(TEST_TARGET) + +.PHONY: test +test: $(FILES_TARGET) $(SOURCES_TARGET) $(PACKAGES_TARGET) $(TEST_TARGET) $(TEST_DEPENDENCY_TARGETS) + @test -z "$(TEST_COMMAND)" && echo "No test command defined" && exit 1 || : + @echo "Run tests using $(TEST_COMMAND)" + @/usr/bin/env bash -c "$(TEST_COMMAND)" + +.PHONY: test-dirty +test-dirty: + @rm -f $(TEST_TARGET) + +.PHONY: test-clean +test-clean: test-dirty + @test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y $(TEST_REQUIREMENTS) || : + @rm -rf .pytest_cache + +INSTALL_TARGETS+=$(TEST_TARGET) +CLEAN_TARGETS+=test-clean +DIRTY_TARGETS+=test-dirty + +############################################################################## +# coverage +############################################################################## + +COVERAGE_TARGET:=$(SENTINEL_FOLDER)/coverage.sentinel +$(COVERAGE_TARGET): $(TEST_TARGET) + @echo "Install Coverage" + @$(PYTHON_PACKAGE_COMMAND) install -U coverage + @touch $(COVERAGE_TARGET) + +.PHONY: coverage +coverage: $(FILES_TARGET) $(SOURCES_TARGET) $(PACKAGES_TARGET) $(COVERAGE_TARGET) + @test -z "$(COVERAGE_COMMAND)" && echo "No coverage command defined" && exit 1 || : + @echo "Run coverage using $(COVERAGE_COMMAND)" + @/usr/bin/env bash -c "$(COVERAGE_COMMAND)" + +.PHONY: coverage-dirty +coverage-dirty: + @rm -f $(COVERAGE_TARGET) + +.PHONY: coverage-clean +coverage-clean: coverage-dirty + @test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y coverage || : + @rm -rf .coverage htmlcov + +INSTALL_TARGETS+=$(COVERAGE_TARGET) +DIRTY_TARGETS+=coverage-dirty +CLEAN_TARGETS+=coverage-clean + +############################################################################## +# Custom includes +############################################################################## + +-include $(INCLUDE_MAKEFILE) + +############################################################################## +# Default targets +############################################################################## + +INSTALL_TARGET:=$(SENTINEL_FOLDER)/install.sentinel +$(INSTALL_TARGET): $(INSTALL_TARGETS) + @touch $(INSTALL_TARGET) + +.PHONY: install +install: $(INSTALL_TARGET) + @touch $(INSTALL_TARGET) + +.PHONY: run +run: $(RUN_TARGET) + +.PHONY: deploy +deploy: $(DEPLOY_TARGETS) + +.PHONY: dirty +dirty: $(DIRTY_TARGETS) + @rm -f $(INSTALL_TARGET) + +.PHONY: clean +clean: dirty $(CLEAN_TARGETS) + @rm -rf $(CLEAN_TARGETS) $(MXMAKE_FOLDER) $(CLEAN_FS) + +.PHONY: purge +purge: clean $(PURGE_TARGETS) + +.PHONY: runtime-clean +runtime-clean: + @echo "Remove runtime artifacts, like byte-code and caches." + @find . -name '*.py[c|o]' -delete + @find . -name '*~' -exec rm -f {} + + @find . -name '__pycache__' -exec rm -fr {} + + +.PHONY: check +check: $(CHECK_TARGETS) + +.PHONY: typecheck +typecheck: $(TYPECHECK_TARGETS) + +.PHONY: format +format: $(FORMAT_TARGETS) diff --git a/js/karma-coverage.js b/js/karma-coverage.js deleted file mode 100644 index 0072d7d..0000000 --- a/js/karma-coverage.js +++ /dev/null @@ -1,17 +0,0 @@ -const percentage = { - lines: 100, - statements: 100, - functions: 100, - branches: 100 -} -var summary = require('./karma/coverage/coverage-summary.json'); - -for (let res in summary.total) { - if (summary.total[res].pct < percentage[res]) { - throw new Error( - `Coverage too low on ${res}, - expected: ${percentage[res]}, - got: ${summary.total[res].pct}` - ); - } -} \ No newline at end of file diff --git a/js/karma.conf.js b/js/karma.conf.js deleted file mode 100644 index 5080d4d..0000000 --- a/js/karma.conf.js +++ /dev/null @@ -1,68 +0,0 @@ -// chromium binary -process.env.CHROME_BIN = '/usr/bin/chromium'; - -// karma config -module.exports = function(config) { - config.set({ - basePath: 'karma', - frameworks: [ - 'qunit' - ], - files: [{ - pattern: '../../node_modules/jquery/src/**/*.js', - type: 'module', - included: false - }, { - pattern: '../src/*.js', - type: 'module', - included: false - }, { - pattern: '../tests/test_*.js', - type: 'module' - }, { - pattern: '../../src/yafowil/widget/chosen/resources/chosen/chosen.jquery.js', - type: 'module', - included: true - }], - browsers: [ - 'ChromeHeadless' - ], - autoWatch: false, - singleRun: true, - reporters: [ - 'progress', - 'coverage' - ], - coverageReporter: { - reporters: [ - { - type: 'json-summary', - dir: 'coverage/', - subdir: '.' - }, { - type: 'html', - dir: 'coverage/', - subdir: 'chrome-headless' - } - ] - }, - preprocessors: { - '../src/*.js': [ - 'coverage', - 'module-resolver' - ], - '../tests/*.js': [ - 'coverage', - 'module-resolver' - ] - }, - moduleResolverPreprocessor: { - addExtension: 'js', - customResolver: null, - ecmaVersion: 6, - aliases: { - jquery: '../../node_modules/jquery/src/jquery.js' - } - } - }); -}; \ No newline at end of file diff --git a/js/rollup.conf.js b/js/rollup.conf.js index 8081bba..97ef68c 100644 --- a/js/rollup.conf.js +++ b/js/rollup.conf.js @@ -1,5 +1,6 @@ import cleanup from 'rollup-plugin-cleanup'; -import {terser} from 'rollup-plugin-terser'; +import postcss from 'rollup-plugin-postcss'; +import terser from '@rollup/plugin-terser'; const out_dir = 'src/yafowil/widget/chosen/resources'; @@ -43,5 +44,23 @@ export default args => { interop: 'default' }); } - return conf; + let scss = { + input: ['scss/widget.scss'], + output: [{ + file: `${out_dir}/widget.css`, + format: 'es', + plugins: [terser()], // Optional: Minify the output + }], + plugins: [ + postcss({ + extract: true, + minimize: true, + use: [ + ['sass', { outputStyle: 'compressed' }], + ], + }), + ], + }; + + return [conf, scss]; }; diff --git a/js/src/widget.js b/js/src/widget.js index b04cae8..059ce5d 100644 --- a/js/src/widget.js +++ b/js/src/widget.js @@ -1,3 +1,4 @@ + import $ from 'jquery'; export class ChosenWidget { diff --git a/js/tests/mockJQuery.js b/js/tests/mockJQuery.js new file mode 100644 index 0000000..ce0b2bc --- /dev/null +++ b/js/tests/mockJQuery.js @@ -0,0 +1,5 @@ +// Import factory from jquery to allow access of global in chosen.jquery.js. +// This is required so that widget.js, test_chosen.js and chosen.jquery.js can +// use the same jQuery as global or via import. +import 'jquery-factory'; +export default $; diff --git a/js/tests/test_chosen.js b/js/tests/test_chosen.js index 71494d4..d164ee5 100644 --- a/js/tests/test_chosen.js +++ b/js/tests/test_chosen.js @@ -1,3 +1,5 @@ +import $ from 'jquery'; +import 'chosen'; // Necessary for global access in tests; do not remove. import {ChosenWidget} from "../src/widget.js"; import {register_array_subscribers} from "../src/widget.js"; @@ -7,6 +9,9 @@ QUnit.module('chosen', hooks => { on_add: [] }; + hooks.before(() => { + + }); hooks.beforeEach(() => { container = $('
').appendTo('body'); el = $('