UNPKG

@applicaster/zapplicaster-cli

Version:

CLI Tool for the zapp app and Quick Brick project

95 lines (72 loc) 2.88 kB
const getConf = (config = {}) => ({ pluginPath: "plugins/my-plugin", skipGit: false, dryRun: false, version: "1.5.0", pluginPackageJson: { name: "my-plugin", version: "1.4.1" }, ...config, }); const mocked_gitInstance = { add: jest.fn(() => Promise.resolve()), commit: jest.fn((version) => version.includes("fail") ? Promise.reject(new Error("fail")) : Promise.resolve() ), }; jest.mock("simple-git/promise", () => jest.fn(() => mocked_gitInstance)); jest.mock("../../../logger", () => ({ log: jest.fn(), })); const { commitToGit } = require("../commitToGit"); const logger = require("../../../logger"); function clearMocks() { logger.log.mockClear(); mocked_gitInstance.add.mockClear(); mocked_gitInstance.commit.mockClear(); } describe("commit to git", () => { beforeEach(clearMocks); it("commits the changes to git", async () => { const configuration = getConf(); expect(await commitToGit(configuration)).toEqual(true); expect(logger.log).not.toHaveBeenCalled(); expect(mocked_gitInstance.add).toHaveBeenCalledWith("."); expect(mocked_gitInstance.commit).toHaveBeenCalledWith( `chore: publish ${configuration.pluginPackageJson.name}@${configuration.version}`, ["*", "../../packages/quick-brick-core-plugins"], { "--no-verify": undefined } ); }); it("doesn't commit with skip git flag", async () => { const configuration = getConf({ skipGit: true }); expect(await commitToGit(configuration)).toEqual(true); expect(logger.log).toHaveBeenCalledWith( "Running with --skip-git, --dry-run or --manifest-only flag changes won't be commited" ); expect(mocked_gitInstance.add).not.toHaveBeenCalled(); expect(mocked_gitInstance.commit).not.toHaveBeenCalled(); }); it("doesn't commit with dry run flag", async () => { const configuration = getConf({ dryRun: true }); expect(await commitToGit(configuration)).toEqual(true); expect(logger.log).toHaveBeenCalledWith( "Running with --skip-git, --dry-run or --manifest-only flag changes won't be commited" ); expect(mocked_gitInstance.add).not.toHaveBeenCalled(); expect(mocked_gitInstance.commit).not.toHaveBeenCalled(); }); it("doesn't commit with manifest only flag", async () => { const configuration = getConf({ manifestOnly: true }); expect(await commitToGit(configuration)).toEqual(true); expect(logger.log).toHaveBeenCalledWith( "Running with --skip-git, --dry-run or --manifest-only flag changes won't be commited" ); expect(mocked_gitInstance.add).not.toHaveBeenCalled(); expect(mocked_gitInstance.commit).not.toHaveBeenCalled(); }); it("throws if committing fails", async () => { const configuration = getConf({ version: "fail" }); expect(commitToGit(configuration)).rejects.toMatchSnapshot(); }); });