Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand test coverage for required status scenarios #9

Merged
merged 10 commits into from
May 24, 2024

Conversation

jnewland
Copy link
Member

@jnewland jnewland commented May 24, 2024

Related to #8

Adds comprehensive tests and updates test scripts to enhance the project's testing framework.

  • Implements new test cases in __tests__/required.test.ts to cover scenarios including all required statuses completing successfully, only one of the required statuses reporting success, one of the required statuses reporting failure, and handling replication lag.
  • Updates package.json scripts to run Jest tests, including coverage, replacing placeholders with actual test execution commands. This ensures that the newly added tests are executed as part of the project's continuous integration process.

For more details, open the Copilot Workspace session.

jnewland added 2 commits May 23, 2024 19:23
Adds unit tests for handling workflow run statuses and updates Jest configuration for testing.

- **Unit Tests**: Implements tests in `__tests__/required.test.ts` to simulate different scenarios including all required statuses completing successfully, only one required status reporting success, one required status reporting failure, and a replication lag scenario. Each test checks if the correct commit status is created with the expected state and description.
- **Environment Variable**: Sets the `GITHUB_REPOSITORY` environment variable in the test setup to mimic the GitHub Actions environment.
- **Error Handling**: Adds error handling in the mocked `listWorkflowRunsForRepo` method to simulate a scenario where `data` is undefined, preventing `TypeError`.
- **Jest Configuration**: Modifies the `ci-test` and `test` scripts in `package.json` to use Jest for running tests and generating coverage reports.


---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/urcomputeringpal/optional-required-workflows/pull/9?shareId=dcb656a4-22f3-448f-a591-6dd98310352a).
@jnewland
Copy link
Member Author

Adds unit tests for handling workflow run statuses and updates Jest configuration for testing.

  • Unit Tests: Implements tests in __tests__/required.test.ts to simulate different scenarios including all required statuses completing successfully, only one required status reporting success, one required status reporting failure, and a replication lag scenario. Each test checks if the correct commit status is created with the expected state and description.
  • Environment Variable: Sets the GITHUB_REPOSITORY environment variable in the test setup to mimic the GitHub Actions environment.
  • Error Handling: Adds error handling in the mocked listWorkflowRunsForRepo method to simulate a scenario where data is undefined, preventing TypeError.
  • Jest Configuration: Modifies the ci-test and test scripts in package.json to use Jest for running tests and generating coverage reports.

For more details, open the Copilot Workspace session.

@jnewland
Copy link
Member Author

Implements additional test cases and updates existing ones in __tests__/required.test.ts to enhance testing of the required function with a focus on mocking getWorkflowRun.

  • Adds a mock implementation for getWorkflowRun to return a specific workflow run object, simulating a successful workflow run scenario.
  • Introduces a new test case that explicitly verifies the behavior of the required function when getWorkflowRun returns a specific workflow run object. This test ensures that the function processes the mocked response correctly and sets the commit status as expected.
  • Updates the beforeEach setup to include the new mock implementation for getWorkflowRun, ensuring all tests have access to the mocked function.
  • Adjusts the ci-test and test scripts in package.json to run Jest tests, including coverage reporting for the test script.

For more details, open the Copilot Workspace session.

Implements additional test cases and updates existing ones in `__tests__/required.test.ts` to enhance testing of the `required` function with a focus on mocking `getWorkflowRun`.

- Adds a mock implementation for `getWorkflowRun` to return a specific workflow run object, simulating a successful workflow run scenario.
- Introduces a new test case that explicitly verifies the behavior of the `required` function when `getWorkflowRun` returns a specific workflow run object. This test ensures that the function processes the mocked response correctly and sets the commit status as expected.
- Updates the `beforeEach` setup to include the new mock implementation for `getWorkflowRun`, ensuring all tests have access to the mocked function.
- Adjusts the `ci-test` and `test` scripts in `package.json` to run Jest tests, including coverage reporting for the `test` script.


---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/urcomputeringpal/optional-required-workflows/pull/9?shareId=d4edab1d-8713-4535-ab11-3f0a826b4df1).
@jnewland
Copy link
Member Author

Fix test failures related to replication lag scenario and getWorkflowRun behavior, and ensure proper handling of undefined workflow data.

  • Update the expectation in the "should handle replication lag scenario" test to correctly assert the pending state and description.
  • Modify the "verifies behavior with getWorkflowRun returning a specific workflow run object" test to simulate a successful response for listWorkflowRunsForRepo, ensuring the test passes by addressing the "Workflow runs data is undefined" error.
  • Add checks in src/required.ts for undefined workflow.data and workflowRuns.data to prevent errors when accessing properties of undefined data.

For more details, open the Copilot Workspace session.

jnewland and others added 5 commits May 23, 2024 19:37
Fix test failures related to replication lag scenario and getWorkflowRun behavior, and ensure proper handling of undefined workflow data.

- Update the expectation in the "should handle replication lag scenario" test to correctly assert the pending state and description.
- Modify the "verifies behavior with getWorkflowRun returning a specific workflow run object" test to simulate a successful response for `listWorkflowRunsForRepo`, ensuring the test passes by addressing the "Workflow runs data is undefined" error.
- Add checks in `src/required.ts` for undefined `workflow.data` and `workflowRuns.data` to prevent errors when accessing properties of undefined data.


---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/urcomputeringpal/optional-required-workflows/pull/9?shareId=46bddfa4-9d6b-4092-92fb-66cf68c0a1ce).
@jnewland jnewland marked this pull request as ready for review May 24, 2024 12:52
@jnewland jnewland enabled auto-merge May 24, 2024 12:53
@jnewland jnewland merged commit 6dbb937 into main May 24, 2024
13 of 14 checks passed
@jnewland jnewland deleted the jnewland/expand-tests branch May 24, 2024 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant