diff --git a/docs/REFACTOR-AND-TEST.md b/docs/REFACTOR-AND-TEST.md index 980bf1f..43fdb56 100644 --- a/docs/REFACTOR-AND-TEST.md +++ b/docs/REFACTOR-AND-TEST.md @@ -14,17 +14,15 @@ src/ ├── ports.ts # Интерфейсы: IFileSystem, ITaskRepository, IConfigProvider ├── storage/ │ ├── FsTaskRepository.ts # ITaskRepository → зависит только от IFileSystem, markdown, uuid +│ ├── FsTaskRepository.test.ts # unit (sociable) — colocation с модулем │ ├── VscodeConfigProvider.ts # IConfigProvider → зависит от vscode │ └── NodeFileSystem.ts # IFileSystem → обёртка над fs.promises +├── utils/ +│ └── markdown.test.ts # unit — colocation tests/ -├── utils/ -│ ├── markdown.test.ts -│ └── uuid.test.ts -├── storage/ -│ ├── FsTaskRepository.test.ts -│ └── helpers/ -│ └── InMemoryFileSystem.ts +└── helpers/ + └── InMemoryFileSystem.ts # shared fakes; integration/e2e — сюда же позже ``` ### Удалить @@ -46,12 +44,13 @@ tests/ ## Тесты -| Тест | I/O | Что проверяет | -| ------------------ | ------------------------ | -------------------------------------------- | -| FsTaskRepository | InMemoryFileSystem (Map) | CRUD, фильтрация по extension, контент файла | -| markdown | — | parse, serialize, round-trip, default-ы | -| uuid | — | валидный формат, уникальность | -| InMemoryFileSystem | — | read/write/readdir/mkdir | +| Тест | Где | I/O | Что проверяет | +| ---------------- | ----------------------- | ------------------------ | -------------------------------------------- | +| FsTaskRepository | `src/storage/*.test.ts` | InMemoryFileSystem (Map) | CRUD, фильтрация по extension, контент файла | +| markdown | `src/utils/*.test.ts` | — | parse, serialize, round-trip, default-ы | + +Unit/sociable unit — рядом с модулем (`src/**/*.test.ts`). +Shared fakes и будущие integration/e2e — в `tests/`. ## Что НЕ тестируем (пока) diff --git a/package.json b/package.json index a193336..98604d8 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,9 @@ "build": "vite build", "watch": "vite build --watch", "vscode:prepublish": "npm run build", - "lint": "tsc --noEmit", + "lint": "npm run lint:app && npm run lint:test", + "lint:app": "tsc --noEmit -p tsconfig.app.json", + "lint:test": "tsc --noEmit -p tsconfig.test.json", "format": "prettier --write .", "test": "vitest", "test:run": "vitest run" diff --git a/tests/storage/FsTaskRepository.test.ts b/src/storage/FsTaskRepository.test.ts similarity index 94% rename from tests/storage/FsTaskRepository.test.ts rename to src/storage/FsTaskRepository.test.ts index b749c76..b2cc84a 100644 --- a/tests/storage/FsTaskRepository.test.ts +++ b/src/storage/FsTaskRepository.test.ts @@ -1,8 +1,8 @@ -import { describe, it, expect, beforeEach } from "vitest"; -import { FsTaskRepository } from "@/storage/FsTaskRepository"; -import { InMemoryFileSystem } from "../helpers/InMemoryFileSystem"; -import { ITaskRepository } from "@/ports"; import { Task } from "@/model/task"; +import { ITaskRepository } from "@/ports"; +import { beforeEach, describe, expect, it } from "vitest"; +import { InMemoryFileSystem } from "../../tests/helpers/InMemoryFileSystem"; +import { FsTaskRepository } from "./FsTaskRepository"; describe("FsTaskRepository", () => { let fs: InMemoryFileSystem; diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 9169110..ca1253b 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -1,8 +1,3 @@ { - "extends": "../tsconfig.json", - "include": ["**/*", "../src/**/*"], - "compilerOptions": { - "noEmit": true, - "rootDir": ".." - } + "extends": "../tsconfig.test.json" } diff --git a/tsconfig.app.json b/tsconfig.app.json new file mode 100644 index 0000000..67129f1 --- /dev/null +++ b/tsconfig.app.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "ES2022", + "outDir": "out", + "rootDir": "src", + "lib": ["ES2022"], + "sourceMap": true, + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "declaration": true, + "types": ["node"], + "paths": { + "@/*": ["./src/*"] + } + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "out", ".vscode-test", "src/**/*.test.ts"] +} diff --git a/tsconfig.json b/tsconfig.json index 7918758..c00d790 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,22 +1,7 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "ES2022", - "outDir": "out", - "rootDir": "src", - "lib": ["ES2022"], - "sourceMap": true, - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "declaration": true, - "types": ["node"], - "paths": { - "@/*": ["./src/*"] - } - }, - "include": ["src/**/*"], - "exclude": ["node_modules", "out", ".vscode-test"] + "files": [], + "references": [ + { "path": "./tsconfig.app.json" }, + { "path": "./tsconfig.test.json" } + ] } diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 0000000..998f9ad --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.app.json", + "compilerOptions": { + "noEmit": true, + "rootDir": ".", + "declaration": false, + "types": ["node"] + }, + "include": ["src/**/*", "tests/**/*"], + "exclude": ["node_modules", "out", ".vscode-test"] +}