From efd596410b69e329fe87247f4ac85a60afdc8c26 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sat, 14 Jan 2023 13:42:43 -0500 Subject: [PATCH] pre-commit --- .pre-commit-config.yaml | 14 ++++++++++++++ Taskfile.yaml | 13 +++++++++++++ src/lib/store/api.js | 1 + src/lib/store/api.test.js | 6 +++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d3c7a7a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +#exclude: static/fontawesome|^build + +default_stages: + - merge-commit + - push + +repos: + - repo: local + hooks: + - id: lint + name: lint + entry: task lint:fix -- + language: system + files: '' diff --git a/Taskfile.yaml b/Taskfile.yaml index 4bcceb1..8afda30 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -4,6 +4,8 @@ version: '3' vars: GREETING: Hello, World! + FILES: + sh: git diff-ls --diff-filter=d main | perl -pe's/\n/ /' tasks: build: vite build @@ -13,3 +15,14 @@ tasks: cmds: - echo "{{.GREETING}}" silent: true + lint:fix: + cmds: + - npx prettier --write {{.CLI_ARGS | default .FILES }} + # - npx eslint --fix --quiet {{.CLI_ARGS | default .FILES }} + integrate: + cmds: + - git is-clean + - task: lint:fix + - task: test + - git co main + - git weld - diff --git a/src/lib/store/api.js b/src/lib/store/api.js index a3d43ea..8a0b1cb 100644 --- a/src/lib/store/api.js +++ b/src/lib/store/api.js @@ -11,6 +11,7 @@ const seedCampaign = { export function genApi(options = {}) { // if (options.local) MyPouch.plugin(pouchMem); + if (options.pouch) options.pouch(PouchDB); const pouchdb = new PouchDB( 'Campaigns', diff --git a/src/lib/store/api.test.js b/src/lib/store/api.test.js index 517e400..18de681 100644 --- a/src/lib/store/api.test.js +++ b/src/lib/store/api.test.js @@ -2,6 +2,7 @@ import { test, expect } from 'vitest'; import { get } from 'svelte/store'; import { genApi } from './api.js'; +import adapter from 'pouchdb-adapter-memory'; const waitUntil = (store, condition) => { return new Promise((resolve) => { @@ -10,7 +11,10 @@ const waitUntil = (store, condition) => { }; test('create and add and remove campaigns', async () => { - const api = genApi({ local: true }); + const api = genApi({ + local: true, + pouch: (p) => p.plugin(adapter), + }); let result = waitUntil(api.campaigns, (r) => r.length === 2);