diff --git a/jest.config.ts b/jest.config.ts index e1007604..001e0ef9 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -13,6 +13,11 @@ const config: Config = { setupFilesAfterEnv: ['/test/jest-setup.ts'], testEnvironment: 'node', testRegex: ['.*\\.test\\.ts$'], + // Tell Jest to ignore the specific duplicate package.json files + // that are causing Haste module naming collisions + modulePathIgnorePatterns: [ + '/test/e2e/prompt-module/data/' + ], transformIgnorePatterns: [ 'node_modules/(?!(cli-testing-library|@clack|cleye)/.*)' ], @@ -29,10 +34,6 @@ const config: Config = { } ] }, - // Fix Haste module naming collision - modulePathIgnorePatterns: [ - '/test/e2e/prompt-module/data/' - ], moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1' } diff --git a/package-lock.json b/package-lock.json index a7f82d43..4fa9d36f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2128,6 +2128,17 @@ "integrity": "sha512-AanzbulOHljrku1NGfafxdpTCfw2ENaWzH01N2vqQM+cUFbk868Cgh0xylz0JIM9BoKbfI++bdD6EYX0Q/UTEw==", "license": "MIT" }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "license": "MIT", + "optional": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -5422,12 +5433,15 @@ "dependencies": { "@isaacs/cliui": "^8.0.2" }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + }, "engines": { "node": "20 || >=22" }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } }, "node_modules/jake": { "version": "10.9.2", @@ -7521,6 +7535,7 @@ "license": "MIT" }, "node_modules/path-scurry": { + "version": "2.0.0", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.0.tgz", "integrity": "sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==", @@ -7538,6 +7553,7 @@ } }, "node_modules/path-scurry/node_modules/lru-cache": { + "version": "11.1.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.1.0.tgz", "integrity": "sha512-QIXZUBJUx+2zHUdQujWejBkcD9+cs94tLn0+YL8UrCh+D5sCXZ4c7LaEH48pNwRY3MLDgqUFyhlCyjJPf1WP0A==", @@ -7546,6 +7562,7 @@ "engines": { "node": "20 || >=22" } + }, "node_modules/picocolors": { "version": "1.1.1", @@ -7928,6 +7945,7 @@ } }, "node_modules/rimraf": { + "version": "6.0.1", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-6.0.1.tgz", "integrity": "sha512-9dkvaxAsk/xNXSJzMgFqqMCuFgt2+KsOFek3TMLfo8NCPfWpBmqwyNn5Y+NX56QUYfCtsyhF3ayiboEoUmJk/A==", @@ -7940,30 +7958,37 @@ "bin": { "rimraf": "dist/esm/bin.mjs" }, + "engines": { "node": "20 || >=22" }, + "funding": { "url": "https://github.com/sponsors/isaacs" } }, "node_modules/rimraf/node_modules/glob": { + "version": "11.0.1", "resolved": "https://registry.npmjs.org/glob/-/glob-11.0.1.tgz", "integrity": "sha512-zrQDm8XPnYEKawJScsnM0QzobJxlT/kHOOlRTio8IH/GrmxRE5fjllkzdaHclIuNjUQTJYH2xHNIGfdpJkDJUw==", + "dev": true, "license": "ISC", "dependencies": { "foreground-child": "^3.1.0", + "jackspeak": "^4.0.1", "minimatch": "^10.0.0", "minipass": "^7.1.2", "package-json-from-dist": "^1.0.0", "path-scurry": "^2.0.0" + }, "bin": { "glob": "dist/esm/bin.mjs" }, + "engines": { "node": "20 || >=22" }, @@ -7983,6 +8008,7 @@ "engines": { "node": "20 || >=22" }, + "funding": { "url": "https://github.com/sponsors/isaacs" } diff --git a/package.json b/package.json index 6c47a6b1..8d65a41a 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "ollama:start": "OCO_AI_PROVIDER='ollama' node ./out/cli.cjs", "dev": "ts-node ./src/cli.ts", "dev:gemini": "OCO_AI_PROVIDER='gemini' ts-node ./src/cli.ts", - "build": "rimraf out && node esbuild.config.js", + "build": "npx rimraf out && node esbuild.config.js", "build:push": "npm run build && git add . && git commit -m 'build' && git push", "deploy": "npm publish --tag latest", "deploy:build": "npm run build:push && git push --tags && npm run deploy", diff --git a/test/e2e/gitPush.test.ts b/test/e2e/gitPush.test.ts index 611f8d04..7062ef0a 100644 --- a/test/e2e/gitPush.test.ts +++ b/test/e2e/gitPush.test.ts @@ -125,7 +125,7 @@ describe('cli flow to push git branch', () => { await render('git', ['add index.ts'], { cwd: gitDir }); const { queryByText, findByText, userEvent } = await render( - `OCO_AI_PROVIDER='test' node`, + `OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [resolve('./out/cli.cjs')], { cwd: gitDir } ); @@ -158,7 +158,7 @@ describe('cli flow to push git branch', () => { await render('git', ['add index.ts'], { cwd: gitDir }); const { findByText, userEvent } = await render( - `OCO_AI_PROVIDER='test' node`, + `OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [resolve('./out/cli.cjs')], { cwd: gitDir } ); @@ -186,7 +186,7 @@ describe('cli flow to push git branch', () => { await render('git', ['add index.ts'], { cwd: gitDir }); const { findByText, userEvent } = await render( - `OCO_AI_PROVIDER='test' node`, + `OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [resolve('./out/cli.cjs')], { cwd: gitDir } ); diff --git a/test/e2e/oneFile.test.ts b/test/e2e/oneFile.test.ts index b3e25f96..1e6c4d46 100644 --- a/test/e2e/oneFile.test.ts +++ b/test/e2e/oneFile.test.ts @@ -9,7 +9,7 @@ it('cli flow to generate commit message for 1 new file (staged)', async () => { await render('echo' ,[`'console.log("Hello World");' > index.ts`], { cwd: gitDir }); await render('git' ,['add index.ts'], { cwd: gitDir }); - const { queryByText, findByText, userEvent } = await render(`OCO_AI_PROVIDER='test' node`, [resolve('./out/cli.cjs')], { cwd: gitDir }); + const { queryByText, findByText, userEvent } = await render(`OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [resolve('./out/cli.cjs')], { cwd: gitDir }); expect(await queryByText('No files are staged')).not.toBeInTheConsole(); expect(await queryByText('Do you want to stage all files and generate commit message?')).not.toBeInTheConsole(); @@ -34,7 +34,7 @@ it('cli flow to generate commit message for 1 changed file (not staged)', async await render('echo' ,[`'console.log("Good night World");' >> index.ts`], { cwd: gitDir }); - const { findByText, userEvent } = await render(`OCO_AI_PROVIDER='test' node`, [resolve('./out/cli.cjs')], { cwd: gitDir }); + const { findByText, userEvent } = await render(`OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [resolve('./out/cli.cjs')], { cwd: gitDir }); expect(await findByText('No files are staged')).toBeInTheConsole(); expect(await findByText('Do you want to stage all files and generate commit message?')).toBeInTheConsole(); diff --git a/test/e2e/prompt-module/commitlint.test.ts b/test/e2e/prompt-module/commitlint.test.ts index ab849994..643db37b 100644 --- a/test/e2e/prompt-module/commitlint.test.ts +++ b/test/e2e/prompt-module/commitlint.test.ts @@ -5,8 +5,8 @@ import { prepareEnvironment, wait } from '../utils'; import path from 'path'; function getAbsolutePath(relativePath: string) { - const scriptDir = path.dirname(__filename); - return path.resolve(scriptDir, relativePath); + // Use process.cwd() which should be the project root during test execution + return path.resolve(process.cwd(), 'test/e2e/prompt-module', relativePath); } async function setupCommitlint(dir: string, ver: 9 | 18 | 19) { let packagePath, packageJsonPath, configPath; @@ -47,7 +47,7 @@ describe('cli flow to run "oco commitlint force"', () => { ` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ - OCO_AI_PROVIDER='test' \ + OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${resolve('./out/cli.cjs')} commitlint force \ `, [], @@ -83,7 +83,7 @@ describe('cli flow to run "oco commitlint force"', () => { ` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ - OCO_AI_PROVIDER='test' \ + OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${resolve('./out/cli.cjs')} commitlint force \ `, [], @@ -119,7 +119,7 @@ describe('cli flow to run "oco commitlint force"', () => { ` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ - OCO_AI_PROVIDER='test' \ + OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${resolve('./out/cli.cjs')} commitlint force \ `, [], @@ -160,7 +160,7 @@ describe('cli flow to generate commit message using @commitlint prompt-module', ` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ - OCO_AI_PROVIDER='test' \ + OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${resolve('./out/cli.cjs')} commitlint force \ `, [], @@ -175,7 +175,7 @@ describe('cli flow to generate commit message using @commitlint prompt-module', ` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ - OCO_AI_PROVIDER='test' \ + OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${resolve('./out/cli.cjs')} commitlint get \ `, [], @@ -193,7 +193,7 @@ describe('cli flow to generate commit message using @commitlint prompt-module', ` OCO_TEST_MOCK_TYPE='commit-message' \ OCO_PROMPT_MODULE='@commitlint' \ - OCO_AI_PROVIDER='test' \ + OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${resolve('./out/cli.cjs')} \ `, [], diff --git a/test/jest-setup.ts b/test/jest-setup.ts index cd7b6996..392354c1 100644 --- a/test/jest-setup.ts +++ b/test/jest-setup.ts @@ -2,6 +2,7 @@ import { jest } from '@jest/globals'; import 'cli-testing-library/extend-expect'; import { configure } from 'cli-testing-library'; +// Make Jest available globally global.jest = jest; /** diff --git a/tsconfig.json b/tsconfig.json index d99dc94e..00b61d9b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,10 @@ "target": "ES2020", "lib": ["ES6", "ES2020"], - "module": "CommonJS", + "module": "NodeNext", "resolveJsonModule": true, - "moduleResolution": "Node", + "moduleResolution": "NodeNext", "allowJs": true,