Skip to content

Commit 0775a2b

Browse files
committed
test(CRC-184): Fix unit tests
1 parent 9b03f8a commit 0775a2b

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ inputs:
6565
cwd:
6666
description: 'Current working directory. Path from where the library resolve docsDir, filesPattern, and searches for configuration files'
6767
type: string
68-
6968
runs:
7069
using: docker
71-
main: Dockerfile
70+
image: Dockerfile

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { MarkdownConfluenceSync } from "@tid-xcut/markdown-confluence-sync";
66
import { parse } from "yaml";
77
import { join, isAbsolute } from "path";
88

9-
//const BASE_CWD = "/github/workspace";
10-
const BASE_CWD = "test-action";
9+
const BASE_CWD = "/github/workspace";
10+
// const BASE_CWD = "test-action";
1111

1212
function valueIfDefined<T = string>(value: T | undefined): T | undefined {
1313
return value === "" ? undefined : value;
@@ -71,7 +71,7 @@ export async function run(): Promise<void> {
7171
);
7272
}
7373

74-
const fullCwd = cwd ? join(BASE_CWD,cwd) : BASE_CWD;
74+
const fullCwd = cwd ? join(BASE_CWD, cwd) : BASE_CWD;
7575

7676
const markdownToConfluence = new MarkdownConfluenceSync({
7777
cwd: fullCwd,

test/unit/specs/index.spec.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/unit/specs/main.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import * as core from "@actions/core";
55
import * as main from "../../../src/main";
66
import { MarkdownConfluenceSync } from "@tid-xcut/markdown-confluence-sync";
7+
import { resolve } from "path";
78

89
jest.mock<typeof import("@tid-xcut/markdown-confluence-sync")>(
910
"@tid-xcut/markdown-confluence-sync",
@@ -37,7 +38,7 @@ describe("action", () => {
3738
key: "cwd",
3839
value: "foo-cwd",
3940
expected: {
40-
cwd: "foo-cwd",
41+
cwd: resolve("/github", "workspace", "foo-cwd"),
4142
},
4243
},
4344
{
@@ -220,6 +221,26 @@ describe("action", () => {
220221
});
221222
});
222223

224+
describe("when cwd is absolute", () => {
225+
it("should set action as failed", async () => {
226+
getInputMock.mockImplementation((name: string) => {
227+
// eslint-disable-next-line jest/no-conditional-in-test
228+
if (name === "cwd") {
229+
return "/foo-cwd";
230+
}
231+
return "";
232+
});
233+
234+
await main.run();
235+
236+
expect(runMock).toHaveReturned();
237+
expect(setFailedMock).toHaveBeenNthCalledWith(
238+
1,
239+
"The cwd input must be a relative path, but it is an absolute path: /foo-cwd",
240+
);
241+
});
242+
});
243+
223244
describe("when any error occurs", () => {
224245
it("should set action as failed", async () => {
225246
jest.mocked(MarkdownConfluenceSync).mockImplementation(() => {

0 commit comments

Comments
 (0)