feat : ajout config vitest/make/pre-commit/commit-msg + un exemple de test vitest
This commit is contained in:
23
app/components/malio/Input.test.ts
Normal file
23
app/components/malio/Input.test.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
import Input from './Input.vue'
|
||||||
|
|
||||||
|
describe('MalioInput', () => {
|
||||||
|
it('affiche la valeur initiale', () => {
|
||||||
|
const wrapper = mount(Input, {
|
||||||
|
props: { modelValue: 'hello' },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(wrapper.get('input').element.value).toBe('hello')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('emet update:modelValue au changement', async () => {
|
||||||
|
const wrapper = mount(Input, {
|
||||||
|
props: { modelValue: '' },
|
||||||
|
})
|
||||||
|
|
||||||
|
await wrapper.get('input').setValue('new value')
|
||||||
|
|
||||||
|
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual(['new value'])
|
||||||
|
})
|
||||||
|
})
|
||||||
31
commit-msg
Normal file
31
commit-msg
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
MSG_FILE="${1}"
|
||||||
|
FIRST_LINE="$(head -n 1 "$MSG_FILE" | tr -d '\r')"
|
||||||
|
|
||||||
|
# Autoriser commits auto-générés par git
|
||||||
|
if [[ "$FIRST_LINE" =~ ^Merge\ ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Types autorisés (MINUSCULES uniquement)
|
||||||
|
# Optionnel: scope => feat(auth) : ...
|
||||||
|
REGEX='^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9._-]+\))?\ :\ .+'
|
||||||
|
|
||||||
|
if [[ ! "$FIRST_LINE" =~ $REGEX ]]; then
|
||||||
|
echo "❌ Message de commit invalide."
|
||||||
|
echo ""
|
||||||
|
echo "➡️ Format attendu : <type>(<scope optionnel>) : <message>"
|
||||||
|
echo "➡️ Types autorisés (minuscules uniquement) :"
|
||||||
|
echo " build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test"
|
||||||
|
echo ""
|
||||||
|
echo "✅ Exemples :"
|
||||||
|
echo " feat : add login page"
|
||||||
|
echo " fix(auth) : prevent null token crash"
|
||||||
|
echo " docs : update README"
|
||||||
|
echo ""
|
||||||
|
echo "❌ Exemple refusé :"
|
||||||
|
echo " Feat : add login page"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
30
makefile
Normal file
30
makefile
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
.PHONY: start install dev dev-prepare lint test pre-commit copy-git-hook node-use
|
||||||
|
|
||||||
|
start: copy-git-hook node-use install
|
||||||
|
|
||||||
|
install:
|
||||||
|
npm install
|
||||||
|
|
||||||
|
dev:
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
dev-prepare:
|
||||||
|
npm run dev:prepare
|
||||||
|
|
||||||
|
lint: dev-prepare
|
||||||
|
npm run lint
|
||||||
|
|
||||||
|
test:
|
||||||
|
npm run test
|
||||||
|
|
||||||
|
pre-commit: lint test
|
||||||
|
|
||||||
|
copy-git-hook:
|
||||||
|
cp pre-commit .git/hooks/pre-commit
|
||||||
|
cp commit-msg .git/hooks/commit-msg
|
||||||
|
chmod a+x .git/hooks/pre-commit
|
||||||
|
chmod a+x .git/hooks/commit-msg
|
||||||
|
|
||||||
|
# Force la version node
|
||||||
|
node-use:
|
||||||
|
bash -lc 'source "$$HOME/.nvm/nvm.sh" && nvm install && nvm use'
|
||||||
1164
package-lock.json
generated
1164
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -10,17 +10,22 @@
|
|||||||
"build": "nuxt build .playground",
|
"build": "nuxt build .playground",
|
||||||
"generate": "nuxt generate .playground",
|
"generate": "nuxt generate .playground",
|
||||||
"preview": "nuxt preview .playground",
|
"preview": "nuxt preview .playground",
|
||||||
"lint": "eslint ."
|
"lint": "eslint .",
|
||||||
|
"test": "vitest run"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"nuxt": "^4.0.0"
|
"nuxt": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@vitejs/plugin-vue": "^6.0.1",
|
||||||
|
"@vue/test-utils": "^2.4.6",
|
||||||
"@nuxt/eslint": "latest",
|
"@nuxt/eslint": "latest",
|
||||||
"@types/node": "^24.10.13",
|
"@types/node": "^24.10.13",
|
||||||
"eslint": "^10.0.0",
|
"eslint": "^10.0.0",
|
||||||
|
"jsdom": "^27.0.1",
|
||||||
"nuxt": "^4.3.1",
|
"nuxt": "^4.3.1",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
|
"vitest": "^3.2.4",
|
||||||
"vue": "latest"
|
"vue": "latest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
36
pre-commit
Normal file
36
pre-commit
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "######### Pre-commit hook start #############"
|
||||||
|
|
||||||
|
if ! command -v npm >/dev/null 2>&1; then
|
||||||
|
if [ -f ".nvmrc" ]; then
|
||||||
|
NVM_VERSION="$(tr -d '\r\n' < .nvmrc)"
|
||||||
|
NVM_VERSION="${NVM_VERSION#v}"
|
||||||
|
NPM_BIN="$HOME/.nvm/versions/node/v$NVM_VERSION/bin"
|
||||||
|
if [ -x "$NPM_BIN/npm" ]; then
|
||||||
|
PATH="$NPM_BIN:$PATH"
|
||||||
|
export PATH
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v npm >/dev/null 2>&1; then
|
||||||
|
if [ -s "$HOME/.nvm/nvm.sh" ]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "$HOME/.nvm/nvm.sh"
|
||||||
|
nvm use >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v npm >/dev/null 2>&1; then
|
||||||
|
echo "npm introuvable dans le hook. Abandon du commit."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "--- make pre-commit start ---"
|
||||||
|
make pre-commit
|
||||||
|
echo "--- make pre-commit finished ---"
|
||||||
|
|
||||||
|
echo "All checks passed. Proceeding with commit."
|
||||||
|
exit 0
|
||||||
10
vitest.config.ts
Normal file
10
vitest.config.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { defineConfig } from 'vitest/config'
|
||||||
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [vue()],
|
||||||
|
test: {
|
||||||
|
environment: 'jsdom',
|
||||||
|
include: ['app/**/*.test.ts'],
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user