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

test: isolate tests from global config store #5696

Closed
wants to merge 1 commit into from

Conversation

thisislawatts
Copy link
Member

@thisislawatts thisislawatts commented Jan 29, 2025

Pull Request Submission Checklist

  • Follows CONTRIBUTING guidelines
  • Includes detailed description of changes
  • Contains risk assessment (Low)
  • Highlights breaking API changes (if applicable)
  • Links to automated tests covering new functionality
  • Includes manual testing instructions (if necessary)
  • Updates relevant GitBook documentation (PR link: ___)

What does this PR do?

Introduces configuration isolation for E2E tests by creating a temporary Snyk configuration file for each test run. This ensures tests run with a clean configuration state and don't interfere with existing local configurations.

Key changes:

  • Creates an isolated config file in OS temp directory if neither SNYK_CONFIG_FILE nor TEST_CONFIG_FILE is specified
  • Adds logging of config file location via TEST_CONFIG_FILE for better debugging
  • Implements cleanup of temporary files after test completion

Considered, but not implemented:

  • Introducing unique configuration per CLI invocation. Seems like a reasonable next step but would be a more involved change.

Where should the reviewer start?

  1. Review the Jest config changes in jest.config.js adding the new globalTeardown
  2. Check the setup logic in test/setup.js for temporary config file creation
  3. Examine the cleanup implementation in test/teardown.ts

How should this be manually tested?

  1. Run E2E test suite without any config environment variables set
    • Verify a temporary config is created
    • Confirm the location is logged in test output
  2. Run tests with SNYK_CONFIG_FILE set
    • Verify the specified config is used instead of creating a temporary one
  3. Run tests with TEST_CONFIG_FILE set
    • Verify the specified config is used
  4. After test completion, verify temporary config directories are cleaned up

@thisislawatts thisislawatts marked this pull request as ready for review January 29, 2025 12:43
@thisislawatts thisislawatts requested a review from a team as a code owner January 29, 2025 12:43
console.info(
'\n------------------------------------------------------------------------------------------------------' +
'\n Binary under test [TEST_SNYK_COMMAND] .............. ' +
process.env.TEST_SNYK_COMMAND +
'\n Snyk configuration [TEST_CONFIG_FILE] ............... ' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: is this on purpose that the log says TEST_CONFIG_FILE and the env var used is SNYK_CONFIG_FILE?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is TEST_CONFIG_FILE used somewhere?

@PeterSchafer
Copy link
Collaborator

I have never see SNYK_CONFIG_FILE before, are you sure it is supported in Golang and Typescript?

@thisislawatts thisislawatts marked this pull request as draft January 29, 2025 13:00
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.

2 participants