diff --git a/package.json b/package.json index 14d3b6f..a28f098 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "@vitest/coverage-v8": "3.1.2", "@vitest/ui": "^3.1.2", "husky": "^9.1.7", - "jsdom": "^26.1.0", "lint-staged": "^15.5.1", "prettier": "^3.5.3", "vite": "^6.3.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d5bccf0..6760a3f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,9 +30,6 @@ importers: husky: specifier: ^9.1.7 version: 9.1.7 - jsdom: - specifier: ^26.1.0 - version: 26.1.0 lint-staged: specifier: ^15.5.1 version: 15.5.1 @@ -1309,6 +1306,7 @@ snapshots: '@csstools/css-parser-algorithms': 3.0.4(@csstools/css-tokenizer@3.0.3) '@csstools/css-tokenizer': 3.0.3 lru-cache: 10.4.3 + optional: true '@babel/helper-string-parser@7.25.9': {} @@ -1325,12 +1323,14 @@ snapshots: '@bcoe/v8-coverage@1.0.2': {} - '@csstools/color-helpers@5.0.2': {} + '@csstools/color-helpers@5.0.2': + optional: true '@csstools/css-calc@2.1.3(@csstools/css-parser-algorithms@3.0.4(@csstools/css-tokenizer@3.0.3))(@csstools/css-tokenizer@3.0.3)': dependencies: '@csstools/css-parser-algorithms': 3.0.4(@csstools/css-tokenizer@3.0.3) '@csstools/css-tokenizer': 3.0.3 + optional: true '@csstools/css-color-parser@3.0.9(@csstools/css-parser-algorithms@3.0.4(@csstools/css-tokenizer@3.0.3))(@csstools/css-tokenizer@3.0.3)': dependencies: @@ -1338,12 +1338,15 @@ snapshots: '@csstools/css-calc': 2.1.3(@csstools/css-parser-algorithms@3.0.4(@csstools/css-tokenizer@3.0.3))(@csstools/css-tokenizer@3.0.3) '@csstools/css-parser-algorithms': 3.0.4(@csstools/css-tokenizer@3.0.3) '@csstools/css-tokenizer': 3.0.3 + optional: true '@csstools/css-parser-algorithms@3.0.4(@csstools/css-tokenizer@3.0.3)': dependencies: '@csstools/css-tokenizer': 3.0.3 + optional: true - '@csstools/css-tokenizer@3.0.3': {} + '@csstools/css-tokenizer@3.0.3': + optional: true '@esbuild/aix-ppc64@0.25.3': optional: true @@ -1597,7 +1600,8 @@ snapshots: dependencies: event-target-shim: 5.0.1 - agent-base@7.1.3: {} + agent-base@7.1.3: + optional: true agentkeepalive@4.6.0: dependencies: @@ -1685,17 +1689,20 @@ snapshots: dependencies: '@asamuzakjp/css-color': 3.1.5 rrweb-cssom: 0.8.0 + optional: true data-urls@5.0.0: dependencies: whatwg-mimetype: 4.0.0 whatwg-url: 14.2.0 + optional: true debug@4.4.0: dependencies: ms: 2.1.3 - decimal.js@10.5.0: {} + decimal.js@10.5.0: + optional: true deep-eql@5.0.2: {} @@ -1717,7 +1724,8 @@ snapshots: emoji-regex@9.2.2: {} - entities@6.0.0: {} + entities@6.0.0: + optional: true environment@1.1.0: {} @@ -1872,6 +1880,7 @@ snapshots: html-encoding-sniffer@4.0.0: dependencies: whatwg-encoding: 3.1.1 + optional: true html-escaper@2.0.2: {} @@ -1881,6 +1890,7 @@ snapshots: debug: 4.4.0 transitivePeerDependencies: - supports-color + optional: true https-proxy-agent@7.0.6: dependencies: @@ -1888,6 +1898,7 @@ snapshots: debug: 4.4.0 transitivePeerDependencies: - supports-color + optional: true human-signals@5.0.0: {} @@ -1900,6 +1911,7 @@ snapshots: iconv-lite@0.6.3: dependencies: safer-buffer: 2.1.2 + optional: true is-fullwidth-code-point@3.0.0: {} @@ -1911,7 +1923,8 @@ snapshots: is-number@7.0.0: {} - is-potential-custom-element-name@1.0.1: {} + is-potential-custom-element-name@1.0.1: + optional: true is-stream@3.0.0: {} @@ -1970,6 +1983,7 @@ snapshots: - bufferutil - supports-color - utf-8-validate + optional: true kleur@3.0.3: {} @@ -2066,7 +2080,8 @@ snapshots: dependencies: path-key: 4.0.0 - nwsapi@2.2.20: {} + nwsapi@2.2.20: + optional: true onetime@6.0.0: dependencies: @@ -2095,6 +2110,7 @@ snapshots: parse5@7.3.0: dependencies: entities: 6.0.0 + optional: true path-key@3.1.1: {} @@ -2130,7 +2146,8 @@ snapshots: kleur: 3.0.3 sisteransi: 1.0.5 - punycode@2.3.1: {} + punycode@2.3.1: + optional: true restore-cursor@5.1.0: dependencies: @@ -2165,13 +2182,16 @@ snapshots: '@rollup/rollup-win32-x64-msvc': 4.40.1 fsevents: 2.3.3 - rrweb-cssom@0.8.0: {} + rrweb-cssom@0.8.0: + optional: true - safer-buffer@2.1.2: {} + safer-buffer@2.1.2: + optional: true saxes@6.0.0: dependencies: xmlchars: 2.2.0 + optional: true semver@7.7.1: {} @@ -2243,7 +2263,8 @@ snapshots: dependencies: has-flag: 4.0.0 - symbol-tree@3.2.4: {} + symbol-tree@3.2.4: + optional: true test-exclude@7.0.1: dependencies: @@ -2266,11 +2287,13 @@ snapshots: tinyspy@3.0.2: {} - tldts-core@6.1.86: {} + tldts-core@6.1.86: + optional: true tldts@6.1.86: dependencies: tldts-core: 6.1.86 + optional: true to-regex-range@5.0.1: dependencies: @@ -2281,12 +2304,14 @@ snapshots: tough-cookie@5.1.2: dependencies: tldts: 6.1.86 + optional: true tr46@0.0.3: {} tr46@5.1.1: dependencies: punycode: 2.3.1 + optional: true undici-types@5.26.5: {} @@ -2368,23 +2393,28 @@ snapshots: w3c-xmlserializer@5.0.0: dependencies: xml-name-validator: 5.0.0 + optional: true web-streams-polyfill@4.0.0-beta.3: {} webidl-conversions@3.0.1: {} - webidl-conversions@7.0.0: {} + webidl-conversions@7.0.0: + optional: true whatwg-encoding@3.1.1: dependencies: iconv-lite: 0.6.3 + optional: true - whatwg-mimetype@4.0.0: {} + whatwg-mimetype@4.0.0: + optional: true whatwg-url@14.2.0: dependencies: tr46: 5.1.1 webidl-conversions: 7.0.0 + optional: true whatwg-url@5.0.0: dependencies: @@ -2418,10 +2448,13 @@ snapshots: string-width: 7.2.0 strip-ansi: 7.1.0 - ws@8.18.1: {} + ws@8.18.1: + optional: true - xml-name-validator@5.0.0: {} + xml-name-validator@5.0.0: + optional: true - xmlchars@2.2.0: {} + xmlchars@2.2.0: + optional: true yaml@2.7.1: {} diff --git a/test/commit-message-fixtures.test.js b/test/commit-message-fixtures.test.js deleted file mode 100644 index 1794814..0000000 --- a/test/commit-message-fixtures.test.js +++ /dev/null @@ -1,131 +0,0 @@ -import { describe, it, expect, beforeEach } from 'vitest' -import { validateTestFixtureCommitMessage } from '../utils/validateTestFixtureCommitMessage' -import * as path from 'path' -import * as fs from 'fs' -import OpenAI from 'openai' -import dotenv from 'dotenv' - -dotenv.config() - -const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }) - -describe('Test Fixture Commit Message Validation', () => { - beforeEach(() => {}) - - it('should validate commit messages when test fixture files are modified', async () => { - if (!process.env.OPENAI_API_KEY) { - console.warn('Skipping test: No OpenAI API key available') - return - } - - const testFixtureDiff = ` -diff --git a/test/fixtures/array/chunk.js b/test/fixtures/array/chunk.js -index 1234567..abcdefg 100644 ---- a/test/fixtures/array/chunk.js -+++ b/test/fixtures/array/chunk.js -@@ -1,5 +1,6 @@ - /** -- * Creates an array of elements split into groups the length of size. -+ * Creates an array of elements split into groups the length of size. -+ * If array can't be split evenly, the final chunk will be the remaining elements. - * - * @param {Array} array - The array to process - * @param {number} [size=1] - The length of each chunk -` - - const messages = [ - { - role: 'system', - content: - 'You are a helpful assistant. Write the commit message in English. This commit modifies test fixtures, so begin your message with "test:" and include "update fixture for [functionality]".', - }, - { - role: 'user', - content: `Generate a Git commit message based on the following summary: ${testFixtureDiff}\n\nCommit message: `, - }, - ] - - const parameters = { - model: 'gpt-4o', - messages, - n: 1, - temperature: 0, - max_tokens: 50, - } - - const response = await openai.chat.completions.create(parameters) - const message = response.choices[0].message.content.trim() - - const isValidCommitMessage = validateTestFixtureCommitMessage( - message, - 'array', - ) - - expect(isValidCommitMessage).toBe(true) - }) - - it('should reject invalid commit messages for fixture changes', async () => { - if (!process.env.OPENAI_API_KEY) { - console.warn('Skipping test: No OpenAI API key available') - return - } - - const testFixtureDiff = ` -diff --git a/test/fixtures/string/camelCase.js b/test/fixtures/string/camelCase.js -index 1234567..abcdefg 100644 ---- a/test/fixtures/string/camelCase.js -+++ b/test/fixtures/string/camelCase.js -@@ -1,4 +1,5 @@ - /** -+ * Improved documentation. - * Converts string to camel case. - * - * @param {string} string - The string to convert -` - - const messages = [ - { - role: 'system', - content: - 'You are a helpful assistant. Write the commit message in English. This is a bugfix, so begin your message with "fix:".', - }, - { - role: 'user', - content: `Generate a Git commit message based on the following summary: ${testFixtureDiff}\n\nCommit message: `, - }, - ] - - const parameters = { - model: 'gpt-4o', - messages, - n: 1, - temperature: 0, - max_tokens: 50, - } - - const response = await openai.chat.completions.create(parameters) - const message = response.choices[0].message.content.trim() - - const isValidCommitMessage = validateTestFixtureCommitMessage( - message, - 'string', - ) - - expect(isValidCommitMessage).toBe(false) - }) - - it('should recognize test fixture directory changes', () => { - const fixturesPath = path.join(process.cwd(), 'test', 'fixtures') - const exists = fs.existsSync(fixturesPath) - - expect(exists).toBe(true) - - const arrayDirExists = fs.existsSync(path.join(fixturesPath, 'array')) - const objectDirExists = fs.existsSync(path.join(fixturesPath, 'object')) - const stringDirExists = fs.existsSync(path.join(fixturesPath, 'string')) - - expect(arrayDirExists).toBe(true) - expect(objectDirExists).toBe(true) - expect(stringDirExists).toBe(true) - }) -}) diff --git a/test/fixtures/array/chunk.js b/test/fixtures/array/chunk.js deleted file mode 100644 index 503fff1..0000000 --- a/test/fixtures/array/chunk.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Creates an array of elements split into groups the length of size. - * If array can't be split evenly, the final chunk will be the remaining elements. - * - * @param {Array} array - The array to process - * @param {number} [size=1] - The length of each chunk - * @returns {Array} Returns the new array of chunks - */ -export function chunk(array, size = 1) { - const length = array == null ? 0 : array.length - if (!length || size < 1) { - return [] - } - - const result = [] - let index = 0 - - while (index < length) { - result.push(array.slice(index, (index += size))) - } - - return result -} diff --git a/test/fixtures/object/pick.js b/test/fixtures/object/pick.js deleted file mode 100644 index ba747a7..0000000 --- a/test/fixtures/object/pick.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Creates an object composed of the picked object properties. - * - * @param {Object} object - The source object - * @param {...(string|string[])} [paths] - The property paths to pick - * @returns {Object} Returns the new object - */ -export function pick(object, ...paths) { - const result = {} - - if (object == null) { - return result - } - - const flatPaths = [].concat(...paths) - - flatPaths.forEach((path) => { - if (path in object) { - result[path] = object[path] - } - }) - - return result -} diff --git a/test/fixtures/string/camelCase.js b/test/fixtures/string/camelCase.js deleted file mode 100644 index 8576285..0000000 --- a/test/fixtures/string/camelCase.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Converts string to camel case. - * - * @param {string} string - The string to convert - * @returns {string} Returns the camel cased string - */ -export function camelCase(string) { - if (!string) { - return '' - } - - return string - .replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase()) - .replace(/^[A-Z]/, (c) => c.toLowerCase()) -} diff --git a/utils/sanitizeCommitMessage.js b/utils/sanitizeCommitMessage.js index 6a002a9..ebeba8f 100644 --- a/utils/sanitizeCommitMessage.js +++ b/utils/sanitizeCommitMessage.js @@ -1,4 +1,4 @@ -// +// TODO should allow emojis export function sanitizeCommitMessage(message) { // Unicode regex: Allow only all characters (including Japanese and Traditional Chinese), numbers, spaces, and symbols. return message.replace(/[^\p{L}\p{N}\s.:@<>\/-]/gu, '') diff --git a/utils/sanitizeCommitMessage.test.js b/utils/sanitizeCommitMessage.test.js index e1bbda0..e2415a2 100644 --- a/utils/sanitizeCommitMessage.test.js +++ b/utils/sanitizeCommitMessage.test.js @@ -42,6 +42,7 @@ describe('sanitizeCommitMessage', () => { ).toBe('refactor: move code @
/src/utils - done.') }) + // TODO should allow emojis it('should remove emojis and unsupported unicode', () => { expect(sanitizeCommitMessage('fix: bug 🐛🔥💥')).toBe('fix: bug ') }) diff --git a/utils/validateTestFixtureCommitMessage.js b/utils/validateTestFixtureCommitMessage.js deleted file mode 100644 index 30bbba3..0000000 --- a/utils/validateTestFixtureCommitMessage.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Validates that commit messages for test fixture changes follow the required format - * Format: "test: update fixture for [functionality]" - * - * @param {string} message - The commit message to validate - * @param {string} [fixtureType] - Optional fixture type to validate against - * @returns {boolean} Returns true if the message is valid, false otherwise - */ -export function validateTestFixtureCommitMessage(message, fixtureType = null) { - if (!message) { - return false - } - - const basicFormatRegex = /^test(\(fixtures\))?:/i - if (!basicFormatRegex.test(message)) { - return false - } - - const updateFixtureRegex = - /update fixture|add fixture|modify fixture|fixture change/i - if (!updateFixtureRegex.test(message)) { - return false - } - - if ( - fixtureType && - !message.toLowerCase().includes(fixtureType.toLowerCase()) - ) { - return false - } - - return true -} diff --git a/utils/validateTestFixtureCommitMessage.test.js b/utils/validateTestFixtureCommitMessage.test.js deleted file mode 100644 index 76ad842..0000000 --- a/utils/validateTestFixtureCommitMessage.test.js +++ /dev/null @@ -1,53 +0,0 @@ -import { describe, it, expect } from 'vitest' -import { validateTestFixtureCommitMessage } from './validateTestFixtureCommitMessage' - -describe('validateTestFixtureCommitMessage', () => { - it('should return false for an empty commit message', () => { - expect(validateTestFixtureCommitMessage('')).toBe(false) - }) - - it('should return true for valid test fixture commit messages', () => { - expect( - validateTestFixtureCommitMessage( - 'test: update fixture for array methods', - ), - ).toBe(true) - expect( - validateTestFixtureCommitMessage( - 'test(fixtures): add fixture for object utility', - ), - ).toBe(true) - expect( - validateTestFixtureCommitMessage( - 'test: modify fixture for string camelCase', - ), - ).toBe(true) - }) - - it('should return false for invalid test fixture commit messages', () => { - expect(validateTestFixtureCommitMessage('feat: add new feature')).toBe( - false, - ) - expect(validateTestFixtureCommitMessage('fix: update test fixture')).toBe( - false, - ) - expect(validateTestFixtureCommitMessage('test: fix bug in main code')).toBe( - false, - ) - }) - - it('should validate specific fixture types if provided', () => { - expect( - validateTestFixtureCommitMessage( - 'test: update fixture for array methods', - 'array', - ), - ).toBe(true) - expect( - validateTestFixtureCommitMessage( - 'test: update fixture for string methods', - 'array', - ), - ).toBe(false) - }) -})