Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Sep 21, 2020
1 parent 2c08f4b commit 2c37dc0
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 90 deletions.
Empty file removed packages/cli/auto
Empty file.
12 changes: 4 additions & 8 deletions plugins/all-contributors/__tests__/all-contributors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ addContributor.mockImplementation(addContributorMock);
// @ts-ignore
env.mockImplementation(envMock);
// @ts-ignore
jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => gitShow(...args),
}));
jest.mock("../../../packages/core/dist/utils/get-lerna-packages", () => ({
// @ts-ignore
default: (...args) => getLernaPackages(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args) =>
gitShow(...args)
);
jest.mock("../../../packages/core/dist/utils/get-lerna-packages", () => (...args: any[]) => getLernaPackages(...args));
jest.spyOn(process, "chdir").mockReturnValue();

const mockRead = (result: string) =>
Expand Down
70 changes: 40 additions & 30 deletions plugins/cocoapods/__tests__/cocoapods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const mockPodspec = (contents: string) => {
};

let exec = jest.fn().mockResolvedValueOnce("");
jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => exec(...args),
}));
// @ts-ignore
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args) =>
exec(...args)
);

describe("Cocoapods Plugin", () => {
let hooks: Auto.IAutoHooks;
Expand Down Expand Up @@ -210,7 +210,7 @@ describe("Cocoapods Plugin", () => {
test("should push with different pod command if in options", async () => {
mockPodspec(specWithVersion("0.0.1"));

const plugin = new CocoapodsPlugin({...options, podCommand: 'notpod'});
const plugin = new CocoapodsPlugin({ ...options, podCommand: "notpod" });
const hook = makeHooks();
plugin.apply({
hooks: hook,
Expand All @@ -221,13 +221,20 @@ describe("Cocoapods Plugin", () => {
await hook.publish.promise(Auto.SEMVER.patch);

expect(exec).toBeCalledTimes(2);
expect(exec).lastCalledWith("notpod", ["trunk", "push", "./Test.podspec"]);
expect(exec).lastCalledWith("notpod", [
"trunk",
"push",
"./Test.podspec",
]);
});

test("should push with different pod command with spaces if in options", async () => {
mockPodspec(specWithVersion("0.0.1"));

const plugin = new CocoapodsPlugin({...options, podCommand: 'bundle exec pod'});
const plugin = new CocoapodsPlugin({
...options,
podCommand: "bundle exec pod",
});
const hook = makeHooks();
plugin.apply({
hooks: hook,
Expand All @@ -238,13 +245,22 @@ describe("Cocoapods Plugin", () => {
await hook.publish.promise(Auto.SEMVER.patch);

expect(exec).toBeCalledTimes(2);
expect(exec).lastCalledWith("bundle", ["exec", "pod", "trunk", "push", "./Test.podspec"]);
expect(exec).lastCalledWith("bundle", [
"exec",
"pod",
"trunk",
"push",
"./Test.podspec",
]);
});

test("should push to trunk if no specsRepo in options with flags", async () => {
mockPodspec(specWithVersion("0.0.1"));

const plugin = new CocoapodsPlugin({ ...options, flags: ["--sources", "someOtherSpecsRepo"]});
const plugin = new CocoapodsPlugin({
...options,
flags: ["--sources", "someOtherSpecsRepo"],
});
const hook = makeHooks();
plugin.apply({
hooks: hook,
Expand All @@ -255,7 +271,13 @@ describe("Cocoapods Plugin", () => {
await hook.publish.promise(Auto.SEMVER.patch);

expect(exec).toBeCalledTimes(2);
expect(exec).lastCalledWith("pod", ["trunk", "push", "--sources", "someOtherSpecsRepo", "./Test.podspec"]);
expect(exec).lastCalledWith("pod", [
"trunk",
"push",
"--sources",
"someOtherSpecsRepo",
"./Test.podspec",
]);
});

test("should push to specs repo if specsRepo in options", async () => {
Expand All @@ -275,10 +297,7 @@ describe("Cocoapods Plugin", () => {
await hook.publish.promise(Auto.SEMVER.patch);

expect(exec).toBeCalledTimes(5);
expect(exec).toHaveBeenNthCalledWith(2, "pod", [
"repo",
"list"
]);
expect(exec).toHaveBeenNthCalledWith(2, "pod", ["repo", "list"]);
expect(exec).toHaveBeenNthCalledWith(3, "pod", [
"repo",
"add",
Expand All @@ -304,10 +323,7 @@ describe("Cocoapods Plugin", () => {
const plugin = new CocoapodsPlugin({
...options,
specsRepo: "someSpecsRepo",
flags: [
"--sources",
"someOtherSpecsRepo"
]
flags: ["--sources", "someOtherSpecsRepo"],
});
const hook = makeHooks();
plugin.apply({
Expand All @@ -319,10 +335,7 @@ describe("Cocoapods Plugin", () => {
await hook.publish.promise(Auto.SEMVER.patch);

expect(exec).toBeCalledTimes(5);
expect(exec).toHaveBeenNthCalledWith(2, "pod", [
"repo",
"list"
]);
expect(exec).toHaveBeenNthCalledWith(2, "pod", ["repo", "list"]);
expect(exec).toHaveBeenNthCalledWith(3, "pod", [
"repo",
"add",
Expand All @@ -347,7 +360,7 @@ describe("Cocoapods Plugin", () => {
mockPodspec(specWithVersion("0.0.1"));

exec = jest.fn().mockImplementation((...args) => {
if (args[1]?.[1] === 'list') {
if (args[1]?.[1] === "list") {
return `
autoPublishRepo
- Type: git (master)
Expand All @@ -363,9 +376,9 @@ trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/someUser/.cocoapods/repos/trunk
`
`;
}
})
});

const plugin = new CocoapodsPlugin({
...options,
Expand All @@ -381,14 +394,11 @@ trunk
await hook.publish.promise(Auto.SEMVER.patch);

expect(exec).toBeCalledTimes(6);
expect(exec).toHaveBeenNthCalledWith(2, "pod", [
"repo",
"list"
]);
expect(exec).toHaveBeenNthCalledWith(2, "pod", ["repo", "list"]);
expect(exec).toHaveBeenNthCalledWith(3, "pod", [
"repo",
"remove",
"autoPublishRepo"
"autoPublishRepo",
]);
expect(exec).toHaveBeenNthCalledWith(4, "pod", [
"repo",
Expand Down
7 changes: 3 additions & 4 deletions plugins/crates/__tests__/crates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ const writeFile = jest.fn();
const writeFileSync = jest.fn();
const readResult = "{}";

jest.mock('../../../packages/core/dist/utils/exec-promise', () => ({
// @ts-ignore
default: (...args) => exec(...args)
}))
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) =>
exec(...args)
);
// @ts-ignore
jest.mock("env-ci", () => () => ({ isCi: false }));
jest.mock("fs", () => ({
Expand Down
7 changes: 3 additions & 4 deletions plugins/docker/__tests__/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const exec = jest.fn();
jest.mock("../../../packages/core/dist/utils/get-current-branch", () => ({
getCurrentBranch: () => "next",
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => exec(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) =>
exec(...args)
);

const registry = "registry.io/app";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ const graphql = jest.fn();
const exec = jest.fn();
exec.mockReturnValue("");
// @ts-ignore
jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => exec(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) =>
exec(...args)
);

const setup = (
contributors: Array<
Expand Down
7 changes: 3 additions & 4 deletions plugins/gem/__tests__/gem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ const execSpy = jest.fn();
execSpy.mockReturnValue("");

// @ts-ignore
jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => execSpy(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) =>
execSpy(...args)
);

const globSpy = jest.fn();
jest.mock("fast-glob");
Expand Down
7 changes: 3 additions & 4 deletions plugins/git-tag/__tests__/git-tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const exec = jest.fn();
jest.mock("../../../packages/core/dist/utils/get-current-branch", () => ({
getCurrentBranch: () => "next",
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => exec(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) =>
exec(...args)
);

const setup = (mockGit?: any) => {
const plugin = new GitTag();
Expand Down
7 changes: 3 additions & 4 deletions plugins/gradle/__tests__/gradle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import GradleReleasePlugin, {

const exec = jest.fn();

jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => exec(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) =>
exec(...args)
);

describe("Gradle Plugin", () => {
let hooks: Auto.IAutoHooks;
Expand Down
7 changes: 3 additions & 4 deletions plugins/maven/__tests__/maven.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ const mockReadFile = (result: string) =>
// @ts-ignore
execSync.mockImplementation(exec);

jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => exec(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) =>
exec(...args)
);

describe("maven", () => {
let hooks: Auto.IAutoHooks;
Expand Down
12 changes: 4 additions & 8 deletions plugins/npm/__tests__/monorepo-log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ jest.mock("child_process");
// @ts-ignore
execSync.mockImplementation(exec);

jest.mock("../../../packages/core/dist/utils/get-lerna-packages", () => ({
// @ts-ignore
default: (...args) => getLernaPackages(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => execPromise(...args),
}));
jest.mock("../../../packages/core/dist/utils/get-lerna-packages", () => (...args: any[]) => getLernaPackages(...args));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) =>
execPromise(...args)
);
jest.mock("fs", () => ({
// @ts-ignore
existsSync: jest.fn().mockReturnValue(true),
Expand Down
10 changes: 2 additions & 8 deletions plugins/npm/__tests__/npm-next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@ execPromise.mockResolvedValue("");
let readResult = "{}";
readFileSync.mockReturnValue("{}");

jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => execPromise(...args),
}));
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args: any[]) => execPromise(...args));
jest.mock("../../../packages/core/dist/utils/get-current-branch", () => ({
getCurrentBranch: () => "next",
}));
jest.mock("../../../packages/core/dist/utils/get-lerna-packages", () => ({
// @ts-ignore
default: (...args) => getLernaPackages(...args),
}));
jest.mock("../../../packages/core/dist/utils/get-lerna-packages", () => (...args: any[]) => getLernaPackages(...args));
jest.mock("env-ci", () => () => ({ isCi: false }));
jest.mock("get-monorepo-packages", () => () => monorepoPackages());
jest.mock("fs", () => ({
Expand Down
16 changes: 8 additions & 8 deletions plugins/npm/__tests__/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ let readResult = "{}";
readFileSync.mockReturnValue("{}");

jest.mock("../src/set-npm-token.ts");
jest.mock("../../../packages/core/dist/utils/exec-promise", () => ({
// @ts-ignore
default: (...args) => execPromise(...args),
}));
jest.mock(
"../../../packages/core/dist/utils/exec-promise",
() => (...args: any[]) => execPromise(...args)
);
jest.mock("../../../packages/core/dist/utils/get-current-branch", () => ({
getCurrentBranch: () => "master",
}));
jest.mock("../../../packages/core/dist/utils/get-lerna-packages", () => ({
// @ts-ignore
default: (...args) => getLernaPackages(...args),
}));
jest.mock(
"../../../packages/core/dist/utils/get-lerna-packages",
() => (...args: any[]) => getLernaPackages(...args)
);
jest.mock("env-ci", () => () => ({ isCi: false }));
jest.mock("get-monorepo-packages", () => () => monorepoPackages());
jest.mock("fs", () => ({
Expand Down

0 comments on commit 2c37dc0

Please sign in to comment.