From 5fb3d75412762c556b6208819febf5738f039d5d Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Mon, 14 Apr 2025 04:57:53 -0400 Subject: [PATCH 1/4] fix tests Signed-off-by: Tiger Kaovilai --- jest.config.ts | 7 + package-lock.json | 311 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- test/jest-setup.ts | 8 +- 4 files changed, 325 insertions(+), 4 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index ee0d3971..fcb18849 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -14,6 +14,13 @@ const config: Config = { testEnvironment: 'node', testRegex: ['.*\\.test\\.ts$'], transformIgnorePatterns: ['node_modules/(?!cli-testing-library)'], + + // Tell Jest to ignore the specific duplicate package.json files + // that are causing Haste module naming collisions + modulePathIgnorePatterns: [ + '/test/e2e/prompt-module/data/commitlint_18/', + '/test/e2e/prompt-module/data/commitlint_19/' + ], transform: { '^.+\\.(ts|tsx)$': [ 'ts-jest', diff --git a/package-lock.json b/package-lock.json index 930dae3c..5b867990 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,6 +50,7 @@ "eslint": "^9.24.0", "jest": "^29.7.0", "prettier": "^2.8.4", + "rimraf": "^5.0.5", "ts-jest": "^29.1.2", "ts-node": "^10.9.1", "typescript": "^4.9.3" @@ -1225,6 +1226,109 @@ "node": ">=18" } }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@isaacs/cliui/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@isaacs/cliui/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -2024,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", @@ -3476,6 +3591,13 @@ "node": ">= 0.4" } }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true, + "license": "MIT" + }, "node_modules/ejs": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", @@ -4580,6 +4702,36 @@ } } }, + "node_modules/foreground-child": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz", + "integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==", + "dev": true, + "license": "ISC", + "dependencies": { + "cross-spawn": "^7.0.6", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/foreground-child/node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/form-data": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", @@ -5272,6 +5424,22 @@ "node": ">=8" } }, + "node_modules/jackspeak": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", + "integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, "node_modules/jake": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.2.tgz", @@ -6980,6 +7148,16 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/minipass": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -7278,6 +7456,13 @@ "node": ">=6" } }, + "node_modules/package-json-from-dist": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", + "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -7346,6 +7531,30 @@ "dev": true, "license": "MIT" }, + "node_modules/path-scurry": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "lru-cache": "^10.2.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" + }, + "engines": { + "node": ">=16 || 14 >=14.18" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/path-scurry/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true, + "license": "ISC" + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -7726,6 +7935,43 @@ "node": ">=0.10.0" } }, + "node_modules/rimraf": { + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.10.tgz", + "integrity": "sha512-l0OE8wL34P4nJH/H2ffoaniAokM2qSmrtXHmlpvYr5AVVX8msAyW0l8NVJFDxlSK4u3Uh/f41cQheDVdnYijwQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "glob": "^10.3.7" + }, + "bin": { + "rimraf": "dist/esm/bin.mjs" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/rimraf/node_modules/glob": { + "version": "10.4.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", + "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", + "dev": true, + "license": "ISC", + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/run-async": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/run-async/-/run-async-3.0.0.tgz", @@ -7972,6 +8218,22 @@ "node": ">=8" } }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -7984,6 +8246,20 @@ "node": ">=8" } }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-bom": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-4.0.0.tgz", @@ -8522,6 +8798,41 @@ "node": ">=8" } }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/wrap-ansi/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", diff --git a/package.json b/package.json index 08907305..a9c5ce7d 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", @@ -75,6 +75,7 @@ "eslint": "^9.24.0", "jest": "^29.7.0", "prettier": "^2.8.4", + "rimraf": "^5.0.5", "ts-jest": "^29.1.2", "ts-node": "^10.9.1", "typescript": "^4.9.3" diff --git a/test/jest-setup.ts b/test/jest-setup.ts index 29280f78..2ed7b225 100644 --- a/test/jest-setup.ts +++ b/test/jest-setup.ts @@ -1,10 +1,12 @@ -import 'cli-testing-library/extend-expect' -import { configure } from 'cli-testing-library' +// Using dynamic imports for ESM compatibility +import 'cli-testing-library/extend-expect'; +import { configure } from 'cli-testing-library'; import { jest } from '@jest/globals'; +// Make Jest available globally global.jest = jest; /** * Adjusted the wait time for waitFor/findByText to 2000ms, because the default 1000ms makes the test results flaky */ -configure({ asyncUtilTimeout: 2000 }) +configure({ asyncUtilTimeout: 2000 }); From 6bc1d90469dc93541009c8aaa60cf24b4d87d858 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Mon, 14 Apr 2025 05:06:45 -0400 Subject: [PATCH 2/4] `npm run test:unit` passing locally Signed-off-by: Tiger Kaovilai --- test/jest-setup.ts | 10 ++++++++-- tsconfig.json | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test/jest-setup.ts b/test/jest-setup.ts index 2ed7b225..84a1e016 100644 --- a/test/jest-setup.ts +++ b/test/jest-setup.ts @@ -1,5 +1,11 @@ -// Using dynamic imports for ESM compatibility -import 'cli-testing-library/extend-expect'; +// Using Node.js module interop for ESM/CommonJS compatibility +import { createRequire } from 'module'; + +// Create a require function scoped to this module +const moduleRequire = createRequire(import.meta.url); + +// Use the scoped require to import CommonJS modules +moduleRequire('cli-testing-library/extend-expect'); import { configure } from 'cli-testing-library'; import { jest } from '@jest/globals'; 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, From aad62d4fa108d0cdf4ebeccee000ee7e66df4745 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Thu, 29 May 2025 12:05:13 -0500 Subject: [PATCH 3/4] fix: remove duplicate modulePathIgnorePatterns in Jest config - Fixed Jest configuration error by removing duplicate modulePathIgnorePatterns property - Consolidated the ignore patterns into a single declaration - This resolves the TypeScript compilation error preventing tests from running --- jest.config.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index e8d07fe3..001e0ef9 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -16,8 +16,7 @@ const config: Config = { // Tell Jest to ignore the specific duplicate package.json files // that are causing Haste module naming collisions modulePathIgnorePatterns: [ - '/test/e2e/prompt-module/data/commitlint_18/', - '/test/e2e/prompt-module/data/commitlint_19/' + '/test/e2e/prompt-module/data/' ], transformIgnorePatterns: [ 'node_modules/(?!(cli-testing-library|@clack|cleye)/.*)' @@ -35,10 +34,6 @@ const config: Config = { } ] }, - // Fix Haste module naming collision - modulePathIgnorePatterns: [ - '/test/e2e/prompt-module/data/' - ], moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1' } From 3b868ce6dfab9ff85516590305ae49066aad266e Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Thu, 29 May 2025 12:05:28 -0500 Subject: [PATCH 4/4] fix: enable git push functionality in e2e tests - Added OCO_GITPUSH='true' environment variable to all e2e test commands - Fixed ESM module import issues in commitlint tests by using process.cwd() - Replaced import.meta.url usage with relative paths from project root - All e2e tests now properly test the git push prompt functionality --- test/e2e/gitPush.test.ts | 6 +++--- test/e2e/oneFile.test.ts | 4 ++-- test/e2e/prompt-module/commitlint.test.ts | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) 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')} \ `, [],