Skip to content

Commit ddca44b

Browse files
author
Maxim Lobanov
committed
implement unit-tests
1 parent 9e891ea commit ddca44b

File tree

6 files changed

+76
-13
lines changed

6 files changed

+76
-13
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@ jobs:
6969
- name: setup-cocoapods
7070
uses: ./
7171
with:
72-
version: latest
72+
version: latest
73+
74+
- name: Validate version
75+
run: pod --version

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# setup-cocoapods
2+
This action sets up specific version of Cocoapods in GitHub Actions workflow.
3+
4+
# Available parameters
5+
| Argument | Description | Supported format |
6+
|---------------|-----------------------------------------|----------------------------|
7+
| version | Specify version of Cocoapods to install | `latest`, `1.5.2`, `1.9.1` |
8+
9+
# Usage
10+
```
11+
name: CI
12+
on: [push]
13+
jobs:
14+
build:
15+
name: Setup Cocoapods
16+
runs-on: macos-latest
17+
steps:
18+
- name: setup-cocoapods
19+
uses: maxim-lobanov/setup-cocoapods
20+
with:
21+
version: 1.9.1
22+
```
23+
24+
# License
25+
The scripts and documentation in this project are released under the [MIT License](LICENSE)

__tests__/installer.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as exec from "@actions/exec";
2+
import { CocoapodsInstaller } from "../src/installer";
3+
4+
jest.mock("@actions/exec");
5+
6+
describe("CocoapodsInstaller", () => {
7+
describe("install", () => {
8+
let execCommandSpy: jest.SpyInstance;
9+
10+
beforeEach(() => {
11+
execCommandSpy = jest.spyOn(exec, "exec");
12+
});
13+
14+
afterEach(() => {
15+
jest.resetAllMocks();
16+
jest.clearAllMocks();
17+
});
18+
19+
it("replace existing version", async () => {
20+
CocoapodsInstaller["getInstalledVersion"] = jest.fn().mockReturnValue("1.8.5");
21+
await CocoapodsInstaller.install("1.9.1");
22+
expect(execCommandSpy).toHaveBeenCalledWith("gem", ["uninstall", "cocoapods", expect.any(String), expect.any(String)]);
23+
expect(execCommandSpy).toHaveBeenCalledWith("gem", ["install", "cocoapods", expect.any(String), expect.any(String)]);
24+
});
25+
26+
it("version has already installed", async () => {
27+
CocoapodsInstaller["getInstalledVersion"] = jest.fn().mockReturnValue("1.9.1");
28+
await CocoapodsInstaller.install("1.9.1");
29+
expect(execCommandSpy).toHaveBeenCalledTimes(0);
30+
});
31+
32+
});
33+
});

dist/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,16 +1506,17 @@ const exec = __importStar(__webpack_require__(986));
15061506
const core = __importStar(__webpack_require__(470));
15071507
class CocoapodsInstaller {
15081508
static async install(versionSpec) {
1509+
// Checking pre-installed version of Cocoapods
15091510
const installedVersion = await this.getInstalledVersion();
15101511
if (installedVersion === versionSpec) {
15111512
core.info(`Cocoapods ${versionSpec} has already installed. Not needed to re-install.`);
15121513
return;
15131514
}
1514-
await exec.exec("gem", ["uninstll", "cocoapods", "--all", "--executables"]);
1515-
const installExitCode = await exec.exec("gem", ["install", "cocoapods", "-v", versionSpec]);
1516-
if (installExitCode !== 0) {
1517-
throw new Error(`Error during install Cocoapods ${versionSpec}`);
1518-
}
1515+
// Remove pre-installed version of Cocoapods
1516+
exec.exec("gem", ["uninstall", "cocoapods", "--all", "--executables"]);
1517+
// Install new version of Cocoapods
1518+
const versionArguments = (versionSpec === "latest") ? [] : ["-v", versionSpec];
1519+
await exec.exec("gem", ["install", "cocoapods", ...versionArguments]);
15191520
core.info(`Cocoapods ${versionSpec} has installed successfully`);
15201521
}
15211522
static getVersionFromPodfile(podfilePath) {
@@ -1573,7 +1574,7 @@ const run = async () => {
15731574
if (!!versionInput === !!podfilePathInput) {
15741575
throw new Error("Invalid input parameters. Only 'version' or 'podfile-path' should be defined");
15751576
}
1576-
const versionSpec = versionInput || installer_1.CocoapodsInstaller.getVersionFromPodfile(podfilePathInput);
1577+
const versionSpec = versionInput; // || CocoapodsInstaller.getVersionFromPodfile(podfilePathInput);
15771578
if (!versionSpec) {
15781579
throw new Error(`Invalid version format '${versionSpec}'`);
15791580
}

src/installer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import { ExecOptions } from "@actions/exec/lib/interfaces";
77

88
export class CocoapodsInstaller {
99
public static async install(versionSpec: string): Promise<void> {
10+
// Checking pre-installed version of Cocoapods
1011
const installedVersion = await this.getInstalledVersion();
1112
if (installedVersion === versionSpec) {
1213
core.info(`Cocoapods ${versionSpec} has already installed. Not needed to re-install.`);
1314
return;
1415
}
1516

16-
await exec.exec("gem", ["uninstll", "cocoapods", "--all", "--executables"]);
17+
// Remove pre-installed version of Cocoapods
18+
exec.exec("gem", ["uninstall", "cocoapods", "--all", "--executables"]);
1719

18-
const installExitCode = await exec.exec("gem", ["install", "cocoapods", "-v", versionSpec]);
19-
if (installExitCode !== 0) {
20-
throw new Error(`Error during install Cocoapods ${versionSpec}`);
21-
}
20+
// Install new version of Cocoapods
21+
const versionArguments = (versionSpec === "latest") ? [] : ["-v", versionSpec];
22+
await exec.exec("gem", ["install", "cocoapods", ...versionArguments]);
2223

2324
core.info(`Cocoapods ${versionSpec} has installed successfully`);
2425
}

src/setup-cocoapods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const run = async (): Promise<void> => {
1414
throw new Error("Invalid input parameters. Only 'version' or 'podfile-path' should be defined");
1515
}
1616

17-
const versionSpec = versionInput || CocoapodsInstaller.getVersionFromPodfile(podfilePathInput);
17+
const versionSpec = versionInput;// || CocoapodsInstaller.getVersionFromPodfile(podfilePathInput);
1818
if (!versionSpec) {
1919
throw new Error(`Invalid version format '${versionSpec}'`);
2020
}

0 commit comments

Comments
 (0)