Rebuild.
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
"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 = __importDefault(require("path"));
|
||||
require("cli-testing-library/extend-expect");
|
||||
const child_process_1 = require("child_process");
|
||||
const utils_1 = require("./utils");
|
||||
const util_1 = require("util");
|
||||
const cli_testing_library_1 = require("cli-testing-library");
|
||||
const path_2 = require("path");
|
||||
const fs_1 = require("fs");
|
||||
const fsExec = (0, util_1.promisify)(child_process_1.exec);
|
||||
const fsRemove = (0, util_1.promisify)(fs_1.rm);
|
||||
/**
|
||||
* git remote -v
|
||||
*
|
||||
* [no remotes]
|
||||
*/
|
||||
const prepareNoRemoteGitRepository = async () => {
|
||||
const tempDir = await (0, utils_1.prepareTempDir)();
|
||||
await fsExec('git init test', { cwd: tempDir });
|
||||
const gitDir = path_1.default.resolve(tempDir, 'test');
|
||||
const cleanup = async () => {
|
||||
return fsRemove(tempDir, { recursive: true });
|
||||
};
|
||||
return {
|
||||
gitDir,
|
||||
cleanup
|
||||
};
|
||||
};
|
||||
/**
|
||||
* git remote -v
|
||||
*
|
||||
* origin /tmp/remote.git (fetch)
|
||||
* origin /tmp/remote.git (push)
|
||||
*/
|
||||
const prepareOneRemoteGitRepository = async () => {
|
||||
const tempDir = await (0, utils_1.prepareTempDir)();
|
||||
await fsExec('git init --bare remote.git', { cwd: tempDir });
|
||||
await fsExec('git clone remote.git test', { cwd: tempDir });
|
||||
const gitDir = path_1.default.resolve(tempDir, 'test');
|
||||
const cleanup = async () => {
|
||||
return fsRemove(tempDir, { recursive: true });
|
||||
};
|
||||
return {
|
||||
gitDir,
|
||||
cleanup
|
||||
};
|
||||
};
|
||||
/**
|
||||
* git remote -v
|
||||
*
|
||||
* origin /tmp/remote.git (fetch)
|
||||
* origin /tmp/remote.git (push)
|
||||
* other ../remote2.git (fetch)
|
||||
* other ../remote2.git (push)
|
||||
*/
|
||||
const prepareTwoRemotesGitRepository = async () => {
|
||||
const tempDir = await (0, utils_1.prepareTempDir)();
|
||||
await fsExec('git init --bare remote.git', { cwd: tempDir });
|
||||
await fsExec('git init --bare other.git', { cwd: tempDir });
|
||||
await fsExec('git clone remote.git test', { cwd: tempDir });
|
||||
const gitDir = path_1.default.resolve(tempDir, 'test');
|
||||
await fsExec('git remote add other ../other.git', { cwd: gitDir });
|
||||
const cleanup = async () => {
|
||||
return fsRemove(tempDir, { recursive: true });
|
||||
};
|
||||
return {
|
||||
gitDir,
|
||||
cleanup
|
||||
};
|
||||
};
|
||||
describe('cli flow to push git branch', () => {
|
||||
it('do nothing when OCO_GITPUSH is set to false', async () => {
|
||||
const { gitDir, cleanup } = await prepareNoRemoteGitRepository();
|
||||
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 { queryByText, findByText, userEvent } = await (0, cli_testing_library_1.render)(`OCO_AI_PROVIDER='test' OCO_GITPUSH='false' node`, [(0, path_2.resolve)('./out/cli.cjs')], { cwd: gitDir });
|
||||
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await queryByText('Choose a remote to push to')).not.toBeInTheConsole();
|
||||
expect(await queryByText('Do you want to run `git push`?')).not.toBeInTheConsole();
|
||||
expect(await queryByText('Successfully pushed all commits to origin')).not.toBeInTheConsole();
|
||||
expect(await queryByText('Command failed with exit code 1')).not.toBeInTheConsole();
|
||||
await cleanup();
|
||||
});
|
||||
it('push and cause error when there is no remote', async () => {
|
||||
const { gitDir, cleanup } = await prepareNoRemoteGitRepository();
|
||||
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 { queryByText, findByText, userEvent } = await (0, cli_testing_library_1.render)(`OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [(0, path_2.resolve)('./out/cli.cjs')], { cwd: gitDir });
|
||||
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await queryByText('Choose a remote to push to')).not.toBeInTheConsole();
|
||||
expect(await queryByText('Do you want to run `git push`?')).not.toBeInTheConsole();
|
||||
expect(await queryByText('Successfully pushed all commits to origin')).not.toBeInTheConsole();
|
||||
expect(await findByText('Command failed with exit code 1')).toBeInTheConsole();
|
||||
await cleanup();
|
||||
});
|
||||
it('push when one remote is set', async () => {
|
||||
const { gitDir, cleanup } = await prepareOneRemoteGitRepository();
|
||||
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 { findByText, userEvent } = await (0, cli_testing_library_1.render)(`OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [(0, path_2.resolve)('./out/cli.cjs')], { cwd: gitDir });
|
||||
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Do you want to run `git push`?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Successfully pushed all commits to origin')).toBeInTheConsole();
|
||||
await cleanup();
|
||||
});
|
||||
it('push when two remotes are set', async () => {
|
||||
const { gitDir, cleanup } = await prepareTwoRemotesGitRepository();
|
||||
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 { findByText, userEvent } = await (0, cli_testing_library_1.render)(`OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [(0, path_2.resolve)('./out/cli.cjs')], { cwd: gitDir });
|
||||
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Choose a remote to push to')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Successfully pushed all commits to origin')).toBeInTheConsole();
|
||||
await cleanup();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
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");
|
||||
it('cli flow when there are no changes', async () => {
|
||||
const { gitDir, cleanup } = await (0, utils_1.prepareEnvironment)();
|
||||
const { findByText } = await (0, cli_testing_library_1.render)(`OCO_AI_PROVIDER='test' node`, [(0, path_1.resolve)('./out/cli.cjs')], { cwd: gitDir });
|
||||
expect(await findByText('No changes detected')).toBeInTheConsole();
|
||||
await cleanup();
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
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");
|
||||
it('cli flow to generate commit message for 1 new file (staged)', async () => {
|
||||
const { gitDir, cleanup } = await (0, utils_1.prepareEnvironment)();
|
||||
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 { queryByText, findByText, userEvent } = await (0, cli_testing_library_1.render)(`OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [(0, path_1.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();
|
||||
expect(await findByText('Generating the commit message')).toBeInTheConsole();
|
||||
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Do you want to run `git push`?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Successfully pushed all commits to origin')).toBeInTheConsole();
|
||||
await cleanup();
|
||||
});
|
||||
it('cli flow to generate commit message for 1 changed file (not staged)', async () => {
|
||||
const { gitDir, cleanup } = await (0, utils_1.prepareEnvironment)();
|
||||
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 });
|
||||
await (0, cli_testing_library_1.render)('git', [`commit -m 'add new file'`], { cwd: gitDir });
|
||||
await (0, cli_testing_library_1.render)('echo', [`'console.log("Good night World");' >> index.ts`], { cwd: gitDir });
|
||||
const { findByText, userEvent } = await (0, cli_testing_library_1.render)(`OCO_AI_PROVIDER='test' OCO_GITPUSH='true' node`, [(0, path_1.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();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Generating the commit message')).toBeInTheConsole();
|
||||
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Successfully committed')).toBeInTheConsole();
|
||||
expect(await findByText('Do you want to run `git push`?')).toBeInTheConsole();
|
||||
userEvent.keyboard('[Enter]');
|
||||
expect(await findByText('Successfully pushed all commits to origin')).toBeInTheConsole();
|
||||
await cleanup();
|
||||
});
|
||||
@@ -0,0 +1,142 @@
|
||||
"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();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.wait = exports.prepareTempDir = exports.prepareEnvironment = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_1 = require("fs");
|
||||
const util_1 = require("util");
|
||||
const os_1 = require("os");
|
||||
const child_process_1 = require("child_process");
|
||||
const fsMakeTempDir = (0, util_1.promisify)(fs_1.mkdtemp);
|
||||
const fsExec = (0, util_1.promisify)(child_process_1.exec);
|
||||
const fsRemove = (0, util_1.promisify)(fs_1.rm);
|
||||
/**
|
||||
* Prepare the environment for the test
|
||||
* Create a temporary git repository in the temp directory
|
||||
*/
|
||||
const prepareEnvironment = async () => {
|
||||
const tempDir = await (0, exports.prepareTempDir)();
|
||||
// Create a remote git repository int the temp directory. This is necessary to execute the `git push` command
|
||||
await fsExec('git init --bare remote.git', { cwd: tempDir });
|
||||
await fsExec('git clone remote.git test', { cwd: tempDir });
|
||||
const gitDir = path_1.default.resolve(tempDir, 'test');
|
||||
const cleanup = async () => {
|
||||
return fsRemove(tempDir, { recursive: true });
|
||||
};
|
||||
return {
|
||||
gitDir,
|
||||
cleanup,
|
||||
};
|
||||
};
|
||||
exports.prepareEnvironment = prepareEnvironment;
|
||||
const prepareTempDir = async () => {
|
||||
return await fsMakeTempDir(path_1.default.join((0, os_1.tmpdir)(), 'opencommit-test-'));
|
||||
};
|
||||
exports.prepareTempDir = prepareTempDir;
|
||||
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
exports.wait = wait;
|
||||
Reference in New Issue
Block a user