tests: configure vitest and happy-dom (#75221)

This commit is contained in:
Corentin Sechet 2023-03-07 17:58:38 +01:00 committed by Corentin Sechet
parent 632c18b825
commit e7d327cd50
7 changed files with 2198 additions and 556 deletions

2700
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -30,11 +30,13 @@
"devDependencies": {
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-node-resolve": "^13.0.6",
"happy-dom": "^12.5.0",
"rollup": "^2.26.3",
"rollup-plugin-terser": "^6.0.4"
"rollup-plugin-terser": "^6.0.4",
"vitest": "^0.34.6"
},
"scripts": {
"test": "true",
"test": "vitest --run",
"build": "rollup -c",
"watch": "rollup -c -w",
"prepare": "npm run build"

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 clean-install

4
tests/.eslintrc.yml Normal file
View File

@ -0,0 +1,4 @@
env:
node: true

12
tests/godo.test.js Normal file
View File

@ -0,0 +1,12 @@
import Godo from '../src-js/godo'
import {test, expect} from 'vitest'
test('test create editor', async () => {
const form = document.createElement('form')
const textArea = document.createElement('textarea')
form.appendChild(textArea)
const godo = new Godo(textArea, {})
expect(godo).not.toBe(undefined)
expect(document.querySelector('.godo')).not.toBe(undefined)
})

12
tox.ini
View File

@ -1,10 +1,13 @@
[tox]
envlist = pre-commit
envlist = pre-commit,test
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/godo.js/
[testenv]
whitelist_externals =
/bin/mv
npm
npx
bash
setenv =
PYTHONPATH=.
SETUPTOOLS_USE_DISTUTILS=stdlib
@ -15,3 +18,10 @@ deps =
pre-commit
commands =
pre-commit run --all-files --show-diff-on-failure
[testenv:test]
deps = nodeenv
install_command = bash setup-vitest.sh {packages}
setenv =
NODE_PATH={envdir}/lib/node_modules
commands = npx vitest --run

14
vitest.config.js Normal file
View File

@ -0,0 +1,14 @@
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
include: 'tests/**/*.test.js',
watchExclude: ['**'],
alias: {
godo: fileURLToPath(new URL('./src-js', import.meta.url)),
},
environment: 'happy-dom',
},
})