diff --git a/.gitignore b/.gitignore index 01faf2b6..6f748080 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ junit-py*.xml .sass-cache/ passerelle/static/css/style.css passerelle/static/css/style.css.map +node_modules/ diff --git a/setup-vitest.sh b/setup-vitest.sh new file mode 100644 index 00000000..145be1c5 --- /dev/null +++ b/setup-vitest.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +pip install $* +nodeenv --prebuilt --python-virtualenv +source $VIRTUAL_ENV/bin/activate # source again to activate npm from env +npm install -g vitest happy-dom diff --git a/tests/js/qrcode.test.js b/tests/js/qrcode.test.js new file mode 100644 index 00000000..325afa25 --- /dev/null +++ b/tests/js/qrcode.test.js @@ -0,0 +1,6 @@ +import { expect, test} from 'vitest' + +test('test qrcode', async () => { + expect(true).toBe(true) +}) + diff --git a/tox.ini b/tox.ini index f2c5672d..e8668392 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/passerelle/{env:RAND_TEST:} -envlist = py3-django32-codestyle-coverage,pylint +envlist = py3-django32-codestyle-coverage,pylint,vitest [testenv] usedevelop = True @@ -86,3 +86,13 @@ allowlist_externals = ./pylint.sh commands = ./pylint.sh passerelle/ tests/ + +[testenv:vitest] +deps = nodeenv +allowlist_externals = + bash + npx +install_command = bash setup-vitest.sh {packages} +setenv = + NODE_PATH={envdir}/lib/node_modules +commands = npx vitest --run diff --git a/vitest.config.js b/vitest.config.js new file mode 100644 index 00000000..7f8f80ca --- /dev/null +++ b/vitest.config.js @@ -0,0 +1,15 @@ +import { fileURLToPath, URL } from 'node:url' +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + include: ['tests/js/**/*.test.js'], + watchExclude: ['**'], + alias: { + qrcode: fileURLToPath(new URL('./passerelle/apps/qrcode/static/qrcode/js', import.meta.url)), + vitest: process.env.NODE_PATH + '/vitest' + }, + environment: 'happy-dom' + } +}) +