From 60b31346ba3bce12e73567e03a79a704b54a05c8 Mon Sep 17 00:00:00 2001 From: Evelin Date: Fri, 20 Mar 2026 00:58:40 +0100 Subject: [PATCH] refactor(tests): co-locate test files with source modules Move test files from flat tests/ directory to live alongside the source they test. Update jest.config.js, tsconfig.json, and package.json globs accordingly. Closes #37. --- jest.config.js | 2 +- package.json | 4 ++-- {tests => scripts/renderers}/calcPercentages.test.ts | 6 +++--- {tests => scripts/renderers}/renderErrorCard.test.ts | 4 ++-- {tests => scripts/utils}/validators.test.ts | 2 +- tsconfig.json | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) rename {tests => scripts/renderers}/calcPercentages.test.ts (90%) rename {tests => scripts/renderers}/renderErrorCard.test.ts (80%) rename {tests => scripts/utils}/validators.test.ts (94%) diff --git a/jest.config.js b/jest.config.js index 80af616..9e4ca38 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,6 +2,6 @@ module.exports = { preset: "ts-jest", testEnvironment: "node", - testMatch: ["**/tests/**/*.test.ts"], + testMatch: ["**/*.test.ts"], moduleFileExtensions: ["ts", "js", "json"], }; diff --git a/package.json b/package.json index 26586e1..a6b2b38 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "scripts": { "test": "jest", "typecheck": "tsc --noEmit", - "lint": "eslint \"api/**/*.{js,ts}\" \"scripts/**/*.{js,ts}\" \"tests/**/*.ts\"", - "format": "prettier --write \"api/**/*.{js,ts}\" \"scripts/**/*.{js,ts}\" \"tests/**/*.ts\"" + "lint": "eslint \"api/**/*.{js,ts}\" \"scripts/**/*.{js,ts}\"", + "format": "prettier --write \"api/**/*.{js,ts}\" \"scripts/**/*.{js,ts}\"" }, "repository": { "type": "git", diff --git a/tests/calcPercentages.test.ts b/scripts/renderers/calcPercentages.test.ts similarity index 90% rename from tests/calcPercentages.test.ts rename to scripts/renderers/calcPercentages.test.ts index efc1204..e782fd7 100644 --- a/tests/calcPercentages.test.ts +++ b/scripts/renderers/calcPercentages.test.ts @@ -1,6 +1,6 @@ -import { calcPercentages as calcPercentagesPie } from '../scripts/renderers/renderLangPie'; -import { calcPercentages as calcPercentagesBar } from '../scripts/renderers/renderLangPercent'; -import { LanguageData } from '../types'; +import { calcPercentages as calcPercentagesPie } from './renderLangPie'; +import { calcPercentages as calcPercentagesBar } from './renderLangPercent'; +import { LanguageData } from '../../types'; const mockLanguages: LanguageData[] = [ { name: 'JavaScript', color: '#f1e05a', count: 50 }, diff --git a/tests/renderErrorCard.test.ts b/scripts/renderers/renderErrorCard.test.ts similarity index 80% rename from tests/renderErrorCard.test.ts rename to scripts/renderers/renderErrorCard.test.ts index 99b0de6..466e80d 100644 --- a/tests/renderErrorCard.test.ts +++ b/scripts/renderers/renderErrorCard.test.ts @@ -1,5 +1,5 @@ -import { renderErrorCard } from '../scripts/renderers/renderErrorCard'; -import { CARD_WIDTH, CARD_HEIGHT } from '../scripts/utils/constants'; +import { renderErrorCard } from './renderErrorCard'; +import { CARD_WIDTH, CARD_HEIGHT } from '../utils/constants'; describe('renderErrorCard', () => { test('returns an SVG string', () => { diff --git a/tests/validators.test.ts b/scripts/utils/validators.test.ts similarity index 94% rename from tests/validators.test.ts rename to scripts/utils/validators.test.ts index 08012ae..8521553 100644 --- a/tests/validators.test.ts +++ b/scripts/utils/validators.test.ts @@ -1,4 +1,4 @@ -import { VALID_USERNAME } from '../scripts/utils/validators'; +import { VALID_USERNAME } from './validators'; describe('VALID_USERNAME', () => { test('accepts valid usernames', () => { diff --git a/tsconfig.json b/tsconfig.json index 07e7e7c..0ecb1a2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,6 @@ "resolveJsonModule": true, "allowJs": true }, - "include": ["api/**/*", "scripts/**/*", "types/**/*", "tests/**/*"], + "include": ["api/**/*", "scripts/**/*", "types/**/*"], "exclude": ["node_modules", "dist"] }