"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const cli_testing_library_1 = require("cli-testing-library"); require("cli-testing-library/extend-expect"); const utils_1 = require("../utils"); const path_2 = __importDefault(require("path")); function getAbsolutePath(relativePath) { // Use process.cwd() which should be the project root during test execution return path_2.default.resolve(process.cwd(), 'test/e2e/prompt-module', relativePath); } async function setupCommitlint(dir, ver) { let packagePath, packageJsonPath, configPath; switch (ver) { case 9: packagePath = getAbsolutePath('./data/commitlint_9/node_modules'); packageJsonPath = getAbsolutePath('./data/commitlint_9/package.json'); configPath = getAbsolutePath('./data/commitlint_9/commitlint.config.js'); break; case 18: packagePath = getAbsolutePath('./data/commitlint_18/node_modules'); packageJsonPath = getAbsolutePath('./data/commitlint_18/package.json'); configPath = getAbsolutePath('./data/commitlint_18/commitlint.config.js'); break; case 19: packagePath = getAbsolutePath('./data/commitlint_19/node_modules'); packageJsonPath = getAbsolutePath('./data/commitlint_19/package.json'); configPath = getAbsolutePath('./data/commitlint_19/commitlint.config.js'); break; } await (0, cli_testing_library_1.render)('cp', ['-r', packagePath, '.'], { cwd: dir }); await (0, cli_testing_library_1.render)('cp', [packageJsonPath, '.'], { cwd: dir }); await (0, cli_testing_library_1.render)('cp', [configPath, '.'], { cwd: dir }); await (0, utils_1.wait)(3000); // Avoid flakiness by waiting } describe('cli flow to run "oco commitlint force"', () => { it('on commitlint@9 using CJS', async () => { const { gitDir, cleanup } = await (0, utils_1.prepareEnvironment)(); await setupCommitlint(gitDir, 9); const npmList = await (0, cli_testing_library_1.render)('npm', ['list', '@commitlint/load'], { cwd: gitDir }); expect(await npmList.findByText('@commitlint/load@9')).toBeInTheConsole(); const { findByText } = await (0, cli_testing_library_1.render)(` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${(0, path_1.resolve)('./out/cli.cjs')} commitlint force \ `, [], { cwd: gitDir }); expect(await findByText('opencommit — configure @commitlint')).toBeInTheConsole(); expect(await findByText('Read @commitlint configuration')).toBeInTheConsole(); expect(await findByText('Generating consistency with given @commitlint rules')).toBeInTheConsole(); expect(await findByText('Done - please review contents of')).toBeInTheConsole(); await cleanup(); }); it('on commitlint@18 using CJS', async () => { const { gitDir, cleanup } = await (0, utils_1.prepareEnvironment)(); await setupCommitlint(gitDir, 18); const npmList = await (0, cli_testing_library_1.render)('npm', ['list', '@commitlint/load'], { cwd: gitDir }); expect(await npmList.findByText('@commitlint/load@18')).toBeInTheConsole(); const { findByText } = await (0, cli_testing_library_1.render)(` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${(0, path_1.resolve)('./out/cli.cjs')} commitlint force \ `, [], { cwd: gitDir }); expect(await findByText('opencommit — configure @commitlint')).toBeInTheConsole(); expect(await findByText('Read @commitlint configuration')).toBeInTheConsole(); expect(await findByText('Generating consistency with given @commitlint rules')).toBeInTheConsole(); expect(await findByText('Done - please review contents of')).toBeInTheConsole(); await cleanup(); }); it('on commitlint@19 using ESM', async () => { const { gitDir, cleanup } = await (0, utils_1.prepareEnvironment)(); await setupCommitlint(gitDir, 19); const npmList = await (0, cli_testing_library_1.render)('npm', ['list', '@commitlint/load'], { cwd: gitDir }); expect(await npmList.findByText('@commitlint/load@19')).toBeInTheConsole(); const { findByText } = await (0, cli_testing_library_1.render)(` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${(0, path_1.resolve)('./out/cli.cjs')} commitlint force \ `, [], { cwd: gitDir }); expect(await findByText('opencommit — configure @commitlint')).toBeInTheConsole(); expect(await findByText('Read @commitlint configuration')).toBeInTheConsole(); expect(await findByText('Generating consistency with given @commitlint rules')).toBeInTheConsole(); expect(await findByText('Done - please review contents of')).toBeInTheConsole(); await cleanup(); }); }); describe('cli flow to generate commit message using @commitlint prompt-module', () => { it('on commitlint@19 using ESM', async () => { const { gitDir, cleanup } = await (0, utils_1.prepareEnvironment)(); // Setup commitlint@19 await setupCommitlint(gitDir, 19); const npmList = await (0, cli_testing_library_1.render)('npm', ['list', '@commitlint/load'], { cwd: gitDir }); expect(await npmList.findByText('@commitlint/load@19')).toBeInTheConsole(); // Run `oco commitlint force` const commitlintForce = await (0, cli_testing_library_1.render)(` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${(0, path_1.resolve)('./out/cli.cjs')} commitlint force \ `, [], { cwd: gitDir }); expect(await commitlintForce.findByText('Done - please review contents of')).toBeInTheConsole(); // Run `oco commitlint get` const commitlintGet = await (0, cli_testing_library_1.render)(` OCO_TEST_MOCK_TYPE='prompt-module-commitlint-config' \ OCO_PROMPT_MODULE='@commitlint' \ OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${(0, path_1.resolve)('./out/cli.cjs')} commitlint get \ `, [], { cwd: gitDir }); expect(await commitlintGet.findByText('consistency')).toBeInTheConsole(); // Run 'oco' using .opencommit-commitlint await (0, cli_testing_library_1.render)('echo', [`'console.log("Hello World");' > index.ts`], { cwd: gitDir }); await (0, cli_testing_library_1.render)('git', ['add index.ts'], { cwd: gitDir }); const oco = await (0, cli_testing_library_1.render)(` OCO_TEST_MOCK_TYPE='commit-message' \ OCO_PROMPT_MODULE='@commitlint' \ OCO_AI_PROVIDER='test' OCO_GITPUSH='true' \ node ${(0, path_1.resolve)('./out/cli.cjs')} \ `, [], { cwd: gitDir }); expect(await oco.findByText('Generating the commit message')).toBeInTheConsole(); expect(await oco.findByText('Confirm the commit message?')).toBeInTheConsole(); oco.userEvent.keyboard('[Enter]'); expect(await oco.findByText('Do you want to run `git push`?')).toBeInTheConsole(); oco.userEvent.keyboard('[Enter]'); expect(await oco.findByText('Successfully pushed all commits to origin')).toBeInTheConsole(); await cleanup(); }); });