-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfind-python-projects.test.js
More file actions
91 lines (77 loc) · 2.64 KB
/
Copy pathfind-python-projects.test.js
File metadata and controls
91 lines (77 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { jest, describe, it, expect, beforeEach } from "@jest/globals";
import mapValues from "lodash/mapValues.js";
const infoMock = jest.fn();
const getInputMock = jest.fn();
const setFailedMock = jest.fn();
const setOutputMock = jest.fn();
// ESM module namespaces are frozen, so `jest.spyOn` can't replace the
// @actions/core functions the module under test imports. Register the mock
// before that module is imported instead.
jest.unstable_mockModule("@actions/core", () => ({
info: infoMock,
getInput: getInputMock,
setFailed: setFailedMock,
setOutput: setOutputMock,
}));
const { run } = await import("./find-python-projects.js");
describe("find-python-projects", () => {
const inputsDefaults = {
"additional-export-paths": "",
"exclude-commands": "",
};
let inputs = {};
let outputs = {};
beforeEach(() => {
jest.clearAllMocks();
inputs = {
...inputsDefaults,
};
outputs = {};
// Mock the action's inputs
getInputMock.mockImplementation((name) => {
return inputs[name];
});
setOutputMock.mockImplementation((name, value) => {
outputs[name] = value;
});
});
it("finds projects", async () => {
inputs["root-dir"] = "test-fixtures/multi-project";
await run();
expect(deserializeJsonValues(outputs)).toMatchSnapshot();
expect(infoMock).toHaveBeenCalled();
});
it("Calls setFailed on error", async () => {
inputs["root-dir"] = "test-fixtures/invalid-project";
await run();
expect(setFailedMock).toHaveBeenCalled();
});
it("Exports keys as instructed", async () => {
inputs["additional-export-paths"] = "tool.export.me.please,not.present";
inputs["root-dir"] = "test-fixtures/project-with-exports";
await run();
expect(deserializeJsonValues(outputs)).toMatchSnapshot();
expect(infoMock).toHaveBeenCalled();
});
it("doesn't export commands we should globally skip", async () => {
inputs["root-dir"] = "test-fixtures/multi-project";
inputs["exclude-commands"] = "test";
await run();
expect(deserializeJsonValues(outputs)).toMatchSnapshot();
expect(infoMock).toHaveBeenCalled();
});
it("doesn't export commands we should skip for certain projects", async () => {
inputs["root-dir"] = "test-fixtures/multi-project";
inputs["exclude-commands"] = `
project=sub-project-2,command=something-arbitrary
project=project-5,command=test
project=project-5,command=install
`;
await run();
expect(deserializeJsonValues(outputs)).toMatchSnapshot();
expect(infoMock).toHaveBeenCalled();
});
});
function deserializeJsonValues(obj) {
return mapValues(obj, (val) => JSON.parse(val));
}