js: add js unit tests support (#82651)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Corentin Sechet 2023-11-02 14:43:04 +01:00 committed by Benjamin Dauvergne
parent 82e9018865
commit 7314fa224c
5 changed files with 39 additions and 1 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ junit-py*.xml
.sass-cache/
passerelle/static/css/style.css
passerelle/static/css/style.css.map
node_modules/

6
setup-vitest.sh Normal file
View File

@ -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

6
tests/js/qrcode.test.js Normal file
View File

@ -0,0 +1,6 @@
import { expect, test} from 'vitest'
test('test qrcode', async () => {
expect(true).toBe(true)
})

12
tox.ini
View File

@ -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

15
vitest.config.js Normal file
View File

@ -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'
}
})