mirror of
https://github.com/threeal/cmake-action.git
synced 2025-06-09 18:51:21 +00:00
test: use test case in inputs.test.ts
testing
This commit is contained in:
parent
1ac900e15c
commit
6802dab2a1
@ -8,77 +8,38 @@ jest.unstable_mockModule("@actions/core", () => ({
|
||||
}));
|
||||
|
||||
describe("get action inputs", () => {
|
||||
const defaultInputs: Inputs = {
|
||||
sourceDir: ".",
|
||||
buildDir: "build",
|
||||
generator: "",
|
||||
cCompiler: "",
|
||||
cxxCompiler: "",
|
||||
cFlags: "",
|
||||
cxxFlags: "",
|
||||
options: [],
|
||||
args: [],
|
||||
runBuild: true,
|
||||
buildArgs: [],
|
||||
};
|
||||
interface TestCase {
|
||||
name: string;
|
||||
booleanInputs?: { [key: string]: boolean };
|
||||
stringInputs?: { [key: string]: string };
|
||||
multilineInputs?: { [key: string]: string[] };
|
||||
expectedInputs?: Partial<Inputs>;
|
||||
}
|
||||
|
||||
let booleanInputs: { [key: string]: boolean };
|
||||
let stringInputs: { [key: string]: string };
|
||||
let multilineInputs: { [key: string]: string[] };
|
||||
|
||||
beforeEach(async () => {
|
||||
const core = await import("@actions/core");
|
||||
|
||||
booleanInputs = { "run-build": true };
|
||||
stringInputs = {};
|
||||
multilineInputs = {};
|
||||
|
||||
jest.mocked(core.getBooleanInput).mockImplementation((name) => {
|
||||
return booleanInputs[name] ?? false;
|
||||
});
|
||||
|
||||
jest.mocked(core.getInput).mockImplementation((name) => {
|
||||
return stringInputs[name] ?? "";
|
||||
});
|
||||
|
||||
jest.mocked(core.getMultilineInput).mockImplementation((name) => {
|
||||
return multilineInputs[name] ?? [];
|
||||
});
|
||||
});
|
||||
|
||||
it("should get the action inputs with nothing specified", async () => {
|
||||
const { getInputs } = await import("./inputs.js");
|
||||
|
||||
expect(getInputs()).toStrictEqual(defaultInputs);
|
||||
});
|
||||
|
||||
it("should get the action inputs with all specified", async () => {
|
||||
const { getInputs } = await import("./inputs.js");
|
||||
|
||||
booleanInputs = {
|
||||
...booleanInputs,
|
||||
const testCases: TestCase[] = [
|
||||
{
|
||||
name: "with nothing specified",
|
||||
},
|
||||
{
|
||||
name: "with all specified",
|
||||
booleanInputs: {
|
||||
"run-build": false,
|
||||
};
|
||||
|
||||
stringInputs = {
|
||||
...stringInputs,
|
||||
},
|
||||
stringInputs: {
|
||||
"source-dir": "project",
|
||||
"build-dir": "output",
|
||||
generator: "Ninja",
|
||||
"c-compiler": "clang",
|
||||
"cxx-compiler": "clang++",
|
||||
};
|
||||
|
||||
multilineInputs = {
|
||||
...multilineInputs,
|
||||
},
|
||||
multilineInputs: {
|
||||
"c-flags": ["-Werror -Wall", "-Wextra"],
|
||||
"cxx-flags": ["-Werror -Wall", "-Wextra -Wpedantic"],
|
||||
options: ["BUILD_TESTING=ON BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"],
|
||||
args: ["-Wdev -Wdeprecated", "--fresh"],
|
||||
"build-args": ["--target foo", "--parallel 8"],
|
||||
};
|
||||
|
||||
expect(getInputs()).toStrictEqual({
|
||||
},
|
||||
expectedInputs: {
|
||||
sourceDir: "project",
|
||||
buildDir: "output",
|
||||
generator: "Ninja",
|
||||
@ -90,6 +51,44 @@ describe("get action inputs", () => {
|
||||
args: ["-Wdev", "-Wdeprecated", "--fresh"],
|
||||
runBuild: false,
|
||||
buildArgs: ["--target", "foo", "--parallel", "8"],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
it(`should get the action inputs ${testCase.name}`, async () => {
|
||||
const { getInputs } = await import("./inputs.js");
|
||||
const core = await import("@actions/core");
|
||||
|
||||
const booleanInputs = { "run-build": true, ...testCase.booleanInputs };
|
||||
jest.mocked(core.getBooleanInput).mockImplementation((name) => {
|
||||
return booleanInputs[name] ?? false;
|
||||
});
|
||||
|
||||
const stringInputs = { ...testCase.stringInputs };
|
||||
jest.mocked(core.getInput).mockImplementation((name) => {
|
||||
return stringInputs[name] ?? "";
|
||||
});
|
||||
|
||||
const multilineInputs = { ...testCase.multilineInputs };
|
||||
jest.mocked(core.getMultilineInput).mockImplementation((name) => {
|
||||
return multilineInputs[name] ?? [];
|
||||
});
|
||||
|
||||
expect(getInputs()).toStrictEqual({
|
||||
sourceDir: ".",
|
||||
buildDir: "build",
|
||||
generator: "",
|
||||
cCompiler: "",
|
||||
cxxCompiler: "",
|
||||
cFlags: "",
|
||||
cxxFlags: "",
|
||||
options: [],
|
||||
args: [],
|
||||
runBuild: true,
|
||||
buildArgs: [],
|
||||
...testCase.expectedInputs,
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user