mirror of
				https://github.com/threeal/cmake-action.git
				synced 2025-11-04 05:43:42 +00:00 
			
		
		
		
	test: add test for getInputs function
				
					
				
			This commit is contained in:
		
							parent
							
								
									30c1178974
								
							
						
					
					
						commit
						3064375fdd
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,6 +1,8 @@
 | 
			
		||||
.*
 | 
			
		||||
!.env.yarn
 | 
			
		||||
!.eslint*
 | 
			
		||||
!.git*
 | 
			
		||||
 | 
			
		||||
build/
 | 
			
		||||
coverage/
 | 
			
		||||
node_modules/
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										19
									
								
								jest.config.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								jest.config.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
{
 | 
			
		||||
  "collectCoverage": true,
 | 
			
		||||
  "coverageThreshold": {
 | 
			
		||||
    "global": {
 | 
			
		||||
      "branches": 100,
 | 
			
		||||
      "functions": 100,
 | 
			
		||||
      "lines": 100,
 | 
			
		||||
      "statements": 100
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "moduleNameMapper": {
 | 
			
		||||
    "^(\\.{1,2}/.*)\\.js$": "$1"
 | 
			
		||||
  },
 | 
			
		||||
  "preset": "ts-jest/presets/default-esm",
 | 
			
		||||
  "transform": {
 | 
			
		||||
    "^.+\\.ts$": ["ts-jest", { "useESM": true }]
 | 
			
		||||
  },
 | 
			
		||||
  "verbose": true
 | 
			
		||||
}
 | 
			
		||||
@ -4,7 +4,8 @@
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "build": "ncc build src/index.ts",
 | 
			
		||||
    "format": "prettier --write --cache . !dist !README.md",
 | 
			
		||||
    "lint": "eslint --ignore-path .gitignore ."
 | 
			
		||||
    "lint": "eslint --ignore-path .gitignore .",
 | 
			
		||||
    "test": "jest"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@actions/core": "^1.10.1",
 | 
			
		||||
@ -12,12 +13,16 @@
 | 
			
		||||
    "@actions/io": "^1.1.3"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@jest/globals": "^29.7.0",
 | 
			
		||||
    "@types/jest": "^29.5.12",
 | 
			
		||||
    "@types/node": "^20.11.24",
 | 
			
		||||
    "@typescript-eslint/eslint-plugin": "^7.1.0",
 | 
			
		||||
    "@typescript-eslint/parser": "^7.1.0",
 | 
			
		||||
    "@vercel/ncc": "^0.38.1",
 | 
			
		||||
    "eslint": "^8.57.0",
 | 
			
		||||
    "jest": "^29.7.0",
 | 
			
		||||
    "prettier": "^3.2.5",
 | 
			
		||||
    "ts-jest": "^29.1.2",
 | 
			
		||||
    "typescript": "^5.3.3"
 | 
			
		||||
  },
 | 
			
		||||
  "packageManager": "yarn@4.1.0"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										128
									
								
								src/inputs.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								src/inputs.test.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,128 @@
 | 
			
		||||
import { jest } from "@jest/globals";
 | 
			
		||||
 | 
			
		||||
jest.unstable_mockModule("@actions/core", () => ({
 | 
			
		||||
  getBooleanInput: jest.fn(),
 | 
			
		||||
  getInput: jest.fn(),
 | 
			
		||||
  getMultilineInput: jest.fn(),
 | 
			
		||||
}));
 | 
			
		||||
 | 
			
		||||
describe("get action inputs", () => {
 | 
			
		||||
  describe("with default values", () => {
 | 
			
		||||
    beforeEach(async () => {
 | 
			
		||||
      const { getBooleanInput, getInput, getMultilineInput } = await import(
 | 
			
		||||
        "@actions/core"
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      jest.mocked(getBooleanInput).mockReturnValue(false);
 | 
			
		||||
      jest.mocked(getInput).mockReturnValue("");
 | 
			
		||||
      jest.mocked(getMultilineInput).mockReturnValue([]);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("should get the action inputs", async () => {
 | 
			
		||||
      const { getInputs } = await import("./inputs.js");
 | 
			
		||||
 | 
			
		||||
      const inputs = getInputs();
 | 
			
		||||
 | 
			
		||||
      expect(inputs).toStrictEqual({
 | 
			
		||||
        sourceDir: ".",
 | 
			
		||||
        buildDir: "build",
 | 
			
		||||
        generator: "",
 | 
			
		||||
        cCompiler: "",
 | 
			
		||||
        cxxCompiler: "",
 | 
			
		||||
        cFlags: "",
 | 
			
		||||
        cxxFlags: "",
 | 
			
		||||
        options: [],
 | 
			
		||||
        args: [],
 | 
			
		||||
        runBuild: false,
 | 
			
		||||
        buildArgs: [],
 | 
			
		||||
        runTest: false,
 | 
			
		||||
        testArgs: [],
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe("with specified values", () => {
 | 
			
		||||
    beforeEach(async () => {
 | 
			
		||||
      const { getBooleanInput, getInput, getMultilineInput } = await import(
 | 
			
		||||
        "@actions/core"
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      jest.mocked(getBooleanInput).mockImplementation((name) => {
 | 
			
		||||
        switch (name) {
 | 
			
		||||
          case "run-build":
 | 
			
		||||
            return true;
 | 
			
		||||
          case "run-test":
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        throw new Error(`invalid input name: ${name}`);
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      jest.mocked(getInput).mockImplementation((name) => {
 | 
			
		||||
        switch (name) {
 | 
			
		||||
          case "source-dir":
 | 
			
		||||
            return "some-source";
 | 
			
		||||
          case "build-dir":
 | 
			
		||||
            return "some-build";
 | 
			
		||||
          case "generator":
 | 
			
		||||
            return "some-generator";
 | 
			
		||||
          case "c-compiler":
 | 
			
		||||
            return "some-c-compiler";
 | 
			
		||||
          case "cxx-compiler":
 | 
			
		||||
            return "some-cxx-compiler";
 | 
			
		||||
        }
 | 
			
		||||
        throw new Error(`invalid input name: ${name}`);
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      jest.mocked(getMultilineInput).mockImplementation((name) => {
 | 
			
		||||
        switch (name) {
 | 
			
		||||
          case "c-flags":
 | 
			
		||||
            return ["some-c-flag another-c-flag", "some-other-c-flag"];
 | 
			
		||||
          case "cxx-flags":
 | 
			
		||||
            return ["some-cxx-flag another-cxx-flag", "some-other-cxx-flag"];
 | 
			
		||||
          case "options":
 | 
			
		||||
            return ["some-options another-options", "some-other-options"];
 | 
			
		||||
          case "args":
 | 
			
		||||
            return ["some-args another-args", "some-other-args"];
 | 
			
		||||
          case "build-args":
 | 
			
		||||
            return [
 | 
			
		||||
              "some-build-args another-build-args",
 | 
			
		||||
              "some-other-build-args",
 | 
			
		||||
            ];
 | 
			
		||||
          case "test-args":
 | 
			
		||||
            return ["some-test-args another-test-args", "some-other-test-args"];
 | 
			
		||||
        }
 | 
			
		||||
        throw new Error(`invalid input name: ${name}`);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("should get the action inputs", async () => {
 | 
			
		||||
      const { getInputs } = await import("./inputs.js");
 | 
			
		||||
 | 
			
		||||
      const inputs = getInputs();
 | 
			
		||||
 | 
			
		||||
      expect(inputs).toStrictEqual({
 | 
			
		||||
        sourceDir: "some-source",
 | 
			
		||||
        buildDir: "some-build",
 | 
			
		||||
        generator: "some-generator",
 | 
			
		||||
        cCompiler: "some-c-compiler",
 | 
			
		||||
        cxxCompiler: "some-cxx-compiler",
 | 
			
		||||
        cFlags: "some-c-flag another-c-flag some-other-c-flag",
 | 
			
		||||
        cxxFlags: "some-cxx-flag another-cxx-flag some-other-cxx-flag",
 | 
			
		||||
        options: ["some-options", "another-options", "some-other-options"],
 | 
			
		||||
        args: ["some-args", "another-args", "some-other-args"],
 | 
			
		||||
        runBuild: true,
 | 
			
		||||
        buildArgs: [
 | 
			
		||||
          "some-build-args",
 | 
			
		||||
          "another-build-args",
 | 
			
		||||
          "some-other-build-args",
 | 
			
		||||
        ],
 | 
			
		||||
        runTest: true,
 | 
			
		||||
        testArgs: [
 | 
			
		||||
          "some-test-args",
 | 
			
		||||
          "another-test-args",
 | 
			
		||||
          "some-other-test-args",
 | 
			
		||||
        ],
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user