This documentation provides a detailed, step-by-step guide on how to run tests for the gitlab-org/gitlab project. Below are the instructions tailored for expert developers familiar with the project’s structure.

Prerequisites

Make sure you have the following dependencies installed on your local machine:

  • Ruby (version as specified in the Gemfile)
  • Node.js (version as specified in the package.json)
  • Yarn (recommended for JavaScript packages)

Setting Up Your Environment

  1. Clone the Repository

    Clone the GitLab repository to your local environment:

    git clone https://gitlab.com/gitlab-org/gitlab.git
    cd gitlab
    
  2. Install Dependencies

    Install the Ruby and JavaScript dependencies required for the project:

    bundle install
    yarn install
    
  3. Set Up the Database

    Set up your database for testing. Execute the following commands to create and migrate the database:

    bundle exec rake db:create
    bundle exec rake db:migrate
    

    Seed the database with test data:

    bundle exec rake db:seed RAILS_ENV=test
    
  4. Setting Up Environment Variables

    Ensure the necessary environment variables are set. You may create a .env.test file in the root directory, based on the example provided in .env.example.

Running Tests

1. Unit Tests

To run the unit tests for Ruby code, you can use RSpec. Execute the following command:

bundle exec rspec

2. Feature Tests

Feature tests can also be run using RSpec; specify the spec/features directory if needed:

bundle exec rspec spec/features

3. JavaScript Tests

JavaScript tests can be run using Jest. Run the following command:

yarn test

4. Running All Tests Together

For convenience, you can run all tests (Ruby unit tests and JavaScript tests) using a single command:

bundle exec rspec && yarn test

Running Tests with Specific Tags

If you need to run tests with specific tags, you can use RSpec’s tagging feature. For example, if you want to run tests marked with slow, you can do so with the command:

bundle exec rspec --tag slow

Debugging Tests

In case you need to debug a specific test, you can use byebug in your test file. Set a breakpoint within your RSpec tests:

it 'does something' do
  byebug
  expect(some_method).to eq(some_value)
end

This will allow you to step through the code interactively.

Analyzing Test Coverage

To analyze test coverage, you may use SimpleCov. Run your tests with coverage reporting enabled:

COVERAGE=true bundle exec rspec

Coverage reports will be generated in the coverage directory.

Conclusion

Following these instructions will help you set up a local environment for testing the gitlab-org/gitlab project effectively. Ensure that you regularly update your local repository and dependencies to keep up with the project’s evolving structure and requirements.

Source: Internal GitLab documentation for setting up and running tests in the gitlab-org/gitlab repository.