Exemplo n.º 1
0
  it("can change the origin", () => {
    childProcess.execSync.mockReturnValue("git@github.com:org/lerna.git");

    parseGitRepo("upstream");

    expect(childProcess.execSync).toHaveBeenCalledWith(
      "git",
      ["config", "--get", "remote.upstream.url"],
      undefined
    );
  });
Exemplo n.º 2
0
  it("detects dirty fallback and returns partial metadata", () => {
    childProcess.execSync.mockReturnValueOnce("456");

    const result = describeRef.parse("a1b2c3d-dirty");

    expect(childProcess.execSync).toHaveBeenLastCalledWith("git", ["rev-list", "--count", "a1b2c3d"], {});
    expect(result).toEqual({
      isDirty: true,
      refCount: "456",
      sha: "a1b2c3d",
    });
  });
Exemplo n.º 3
0
  it("detects fallback and returns partial metadata", () => {
    childProcess.execSync.mockReturnValueOnce("123");

    const options = { cwd: "bar" };
    const result = describeRef.parse("a1b2c3d", options);

    expect(childProcess.execSync).toHaveBeenLastCalledWith(
      "git",
      ["rev-list", "--count", "a1b2c3d"],
      options
    );
    expect(result).toEqual({
      isDirty: false,
      refCount: "123",
      sha: "a1b2c3d",
    });
  });
Exemplo n.º 4
0
  it("returns a parsed URL", () => {
    childProcess.execSync.mockReturnValue("git@github.com:org/lerna.git");

    const repo = parseGitRepo();

    expect(childProcess.execSync).toHaveBeenCalledWith(
      "git",
      ["config", "--get", "remote.origin.url"],
      undefined
    );

    expect(repo).toEqual(
      expect.objectContaining({
        name: "lerna",
        owner: "org",
      })
    );
  });
Exemplo n.º 5
0
"use strict";

jest.mock("@lerna/child-process");

const childProcess = require("@lerna/child-process");
const describeRef = require("../lib/describe-ref");

const DEFAULT_ARGS = ["describe", "--always", "--long", "--dirty", "--first-parent"];

childProcess.exec.mockResolvedValue({ stdout: "v1.2.3-4-g567890a" });
childProcess.execSync.mockReturnValue("v1.2.3-4-g567890a");

describe("describeRef()", () => {
  it("resolves parsed metadata", async () => {
    const result = await describeRef();

    expect(childProcess.exec).toHaveBeenLastCalledWith("git", DEFAULT_ARGS, {});
    expect(result).toEqual({
      isDirty: false,
      lastTagName: "v1.2.3",
      lastVersion: "v1.2.3",
      refCount: "4",
      sha: "567890a",
    });
  });

  it("accepts options.cwd", async () => {
    const options = { cwd: "foo" };
    await describeRef(options);

    expect(childProcess.exec).toHaveBeenLastCalledWith("git", DEFAULT_ARGS, options);
Exemplo n.º 6
0
  it("throws an error if no URL returned", () => {
    childProcess.execSync.mockReturnValue("");

    expect(() => parseGitRepo()).toThrow('Git remote URL could not be found using "origin".');
  });
Exemplo n.º 7
0
"use strict";

jest.mock("@octokit/rest");
jest.mock("@lerna/child-process");

const Octokit = require("@octokit/rest");
const childProcess = require("@lerna/child-process");
const { createGitHubClient, parseGitRepo } = require("../lib/github-client");

childProcess.execSync.mockReturnValue("5.6.0");

describe("createGitHubClient", () => {
  const oldEnv = Object.assign({}, process.env);

  afterEach(() => {
    process.env = oldEnv;
  });

  it("errors if no GH_TOKEN env var", () => {
    expect(() => {
      createGitHubClient();
    }).toThrow("A GH_TOKEN environment variable is required.");
  });

  it("doesnt error if GH_TOKEN env var is set", () => {
    process.env.GH_TOKEN = "TOKEN";

    expect(() => {
      createGitHubClient();
    }).not.toThrow();
  });