diff --git a/.gitlab/ci/frontend.gitlab-ci.yml b/.gitlab/ci/frontend.gitlab-ci.yml index 73d45d10b01..b00d2f46088 100644 --- a/.gitlab/ci/frontend.gitlab-ci.yml +++ b/.gitlab/ci/frontend.gitlab-ci.yml @@ -137,6 +137,7 @@ karma: paths: - chrome_debug.log - coverage-javascript/ + - tmp/tests/frontend/ # see https://gitlab.com/gitlab-org/gitlab-ce/issues/64756 # reports: # junit: junit_karma.xml @@ -151,7 +152,7 @@ jest: script: - scripts/gitaly-test-spawn - date - - bundle exec rake karma:fixtures + - bundle exec rake frontend:fixtures - date - yarn jest --ci --coverage artifacts: @@ -161,6 +162,7 @@ jest: paths: - coverage-frontend/ - junit_jest.xml + - tmp/tests/frontend/ # see https://gitlab.com/gitlab-org/gitlab-ce/issues/64756 # reports: # junit: junit_jest.xml diff --git a/.rubocop.yml b/.rubocop.yml index e5fe527e611..79e06439ac2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -60,8 +60,8 @@ Style/FrozenStringLiteralComment: RSpec/FilePath: Exclude: - 'qa/**/*' - - 'spec/javascripts/fixtures/*' - - 'ee/spec/javascripts/fixtures/*' + - 'spec/frontend/fixtures/*' + - 'ee/spec/frontend/fixtures/*' - 'spec/requests/api/v3/*' Naming/FileName: diff --git a/config/karma.config.js b/config/karma.config.js index 2a5bf3581e0..97794225a3f 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -107,7 +107,8 @@ if (specFilters.length) { module.exports = function(config) { process.env.TZ = 'Etc/UTC'; - const fixturesPath = `${IS_EE ? 'ee/' : ''}spec/javascripts/fixtures`; + const fixturesPath = `tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`; + const staticFixturesPath = 'spec/frontend/fixtures/static'; const karmaConfig = { basePath: ROOT_PATH, @@ -131,8 +132,13 @@ module.exports = function(config) { frameworks: ['jasmine'], files: [ { pattern: 'spec/javascripts/test_bundle.js', watched: false }, - { pattern: `${fixturesPath}/**/*@(.json|.html|.png|.bmpr|.pdf)`, included: false }, + { pattern: `${fixturesPath}/**/*`, included: false }, + { pattern: `${staticFixturesPath}/**/*`, included: false }, ], + proxies: { + '/fixtures/': `/base/${fixturesPath}/`, + '/fixtures/static/': `/base/${staticFixturesPath}/`, + }, preprocessors: { 'spec/javascripts/**/*.js': ['webpack', 'sourcemap'], 'ee/spec/javascripts/**/*.js': ['webpack', 'sourcemap'], diff --git a/doc/development/testing_guide/frontend_testing.md b/doc/development/testing_guide/frontend_testing.md index c909745b1ab..ff28c2ea5e2 100644 --- a/doc/development/testing_guide/frontend_testing.md +++ b/doc/development/testing_guide/frontend_testing.md @@ -80,18 +80,20 @@ describe('Component', () => { Remember that the performance of each test depends on the environment. ### Manual module mocks + Jest supports [manual module mocks](https://jestjs.io/docs/en/manual-mocks) by placing a mock in a `__mocks__/` directory next to the source module. **Don't do this.** We want to keep all of our test-related code in one place (the `spec/` folder), and the logic that Jest uses to apply mocks from `__mocks__/` is rather inconsistent. Instead, our test runner detects manual mocks from `spec/frontend/mocks/`. Any mock placed here is automatically picked up and injected whenever you import its source module. - Files in `spec/frontend/mocks/ce` will mock the corresponding CE module from `app/assets/javascripts`, mirroring the source module's path. - - Example: `spec/frontend/mocks/ce/lib/utils/axios_utils` will mock the module `~/lib/utils/axios_utils`. + - Example: `spec/frontend/mocks/ce/lib/utils/axios_utils` will mock the module `~/lib/utils/axios_utils`. - Files in `spec/frontend/mocks/node` will mock NPM packages of the same name or path. - We don't support mocking EE modules yet. If a mock is found for which a source module doesn't exist, the test suite will fail. 'Virtual' mocks, or mocks that don't have a 1-to-1 association with a source module, are not supported yet. #### Writing a mock + Create a JS module in the appropriate place in `spec/frontend/mocks/`. That's it. It will automatically mock its source package in all tests. Make sure that your mock's export has the same format as the mocked module. So, if you're mocking a CommonJS module, you'll need to use `module.exports` instead of the ES6 `export`. @@ -99,14 +101,15 @@ Make sure that your mock's export has the same format as the mocked module. So, It might be useful for a mock to expose a property that indicates if the mock was loaded. This way, tests can assert the presence of a mock without calling any logic and causing side-effects. The `~/lib/utils/axios_utils` module mock has such a property, `isMock`, that is `true` in the mock and undefined in the original class. Jest's mock functions also have a `mock` property that you can test. #### Bypassing mocks + If you ever need to import the original module in your tests, use [`jest.requireActual()`](https://jestjs.io/docs/en/jest-object#jestrequireactualmodulename) (or `jest.requireActual().default` for the default export). The `jest.mock()` and `jest.unmock()` won't have an effect on modules that have a manual mock, because mocks are imported and cached before any tests are run. #### Keep mocks light + Global mocks introduce magic and can affect how modules are imported in your tests. Try to keep them as light as possible and dependency-free. A global mock should be useful for any unit test. For example, the `axios_utils` and `jquery` module mocks throw an error when an HTTP request is attempted, since this is useful behaviour in >99% of tests. When in doubt, construct mocks in your test file using [`jest.mock()`](https://jestjs.io/docs/en/jest-object#jestmockmodulename-factory-options), [`jest.spyOn()`](https://jestjs.io/docs/en/jest-object#jestspyonobject-methodname), etc. - ## Karma test suite GitLab uses the [Karma][karma] test runner with [Jasmine] as its test @@ -462,7 +465,7 @@ See this [section][vue-test]. For running the frontend tests, you need the following commands: -- `rake karma:fixtures` (re-)generates [fixtures](#frontend-test-fixtures). +- `rake frontend:fixtures` (re-)generates [fixtures](#frontend-test-fixtures). - `yarn test` executes the tests. As long as the fixtures don't change, `yarn test` is sufficient (and saves you some time). @@ -515,8 +518,8 @@ Information on setting up and running RSpec integration tests with Code that is added to HAML templates (in `app/views/`) or makes Ajax requests to the backend has tests that require HTML or JSON from the backend. Fixtures for these tests are located at: -- `spec/javascripts/fixtures/`, for running tests in CE. -- `ee/spec/javascripts/fixtures/`, for running tests in EE. +- `spec/frontend/fixtures/`, for running tests in CE. +- `ee/spec/frontend/fixtures/`, for running tests in EE. Fixture files in: @@ -527,7 +530,7 @@ The following are examples of tests that work for both Karma and Jest: ```javascript it('makes a request', () => { - const responseBody = getJSONFixture('some/fixture.json'); // loads spec/javascripts/fixtures/some/fixture.json + const responseBody = getJSONFixture('some/fixture.json'); // loads spec/frontend/fixtures/some/fixture.json axiosMock.onGet(endpoint).reply(200, responseBody); myButton.click(); @@ -536,7 +539,7 @@ it('makes a request', () => { }); it('uses some HTML element', () => { - loadFixtures('some/page.html'); // loads spec/javascripts/fixtures/some/page.html and adds it to the DOM + loadFixtures('some/page.html'); // loads spec/frontend/fixtures/some/page.html and adds it to the DOM const element = document.getElementById('#my-id'); @@ -544,12 +547,12 @@ it('uses some HTML element', () => { }); ``` -HTML and JSON fixtures are generated from backend views and controllers using RSpec (see `spec/javascripts/fixtures/*.rb`). +HTML and JSON fixtures are generated from backend views and controllers using RSpec (see `spec/frontend/fixtures/*.rb`). For each fixture, the content of the `response` variable is stored in the output file. This variable gets automagically set if the test is marked as `type: :request` or `type: :controller`. -Fixtures are regenerated using the `bin/rake karma:fixtures` command but you can also generate them individually, -for example `bin/rspec spec/javascripts/fixtures/merge_requests.rb`. +Fixtures are regenerated using the `bin/rake frontend:fixtures` command but you can also generate them individually, +for example `bin/rspec spec/frontend/fixtures/merge_requests.rb`. When creating a new fixture, it often makes sense to take a look at the corresponding tests for the endpoint in `(ee/)spec/controllers/` or `(ee/)spec/requests/`. ## Gotchas diff --git a/lib/tasks/frontend.rake b/lib/tasks/frontend.rake new file mode 100644 index 00000000000..1cac7520227 --- /dev/null +++ b/lib/tasks/frontend.rake @@ -0,0 +1,21 @@ +unless Rails.env.production? + namespace :frontend do + desc 'GitLab | Frontend | Generate fixtures for JavaScript tests' + RSpec::Core::RakeTask.new(:fixtures, [:pattern]) do |t, args| + args.with_defaults(pattern: '{spec,ee/spec}/frontend/fixtures/*.rb') + ENV['NO_KNAPSACK'] = 'true' + t.pattern = args[:pattern] + t.rspec_opts = '--format documentation' + end + + desc 'GitLab | Frontend | Run JavaScript tests' + task tests: ['yarn:check'] do + sh "yarn test" do |ok, res| + abort('rake frontend:tests failed') unless ok + end + end + end + + desc 'GitLab | Frontend | Shortcut for frontend:fixtures and frontend:tests' + task frontend: ['frontend:fixtures', 'frontend:tests'] +end diff --git a/lib/tasks/karma.rake b/lib/tasks/karma.rake index 2dc14183fa3..36590010406 100644 --- a/lib/tasks/karma.rake +++ b/lib/tasks/karma.rake @@ -1,15 +1,8 @@ unless Rails.env.production? namespace :karma do + # alias exists for legacy reasons desc 'GitLab | Karma | Generate fixtures for JavaScript tests' - task fixtures: ['karma:rspec_fixtures'] - - desc 'GitLab | Karma | Generate fixtures using RSpec' - RSpec::Core::RakeTask.new(:rspec_fixtures, [:pattern]) do |t, args| - args.with_defaults(pattern: '{spec,ee/spec}/javascripts/fixtures/*.rb') - ENV['NO_KNAPSACK'] = 'true' - t.pattern = args[:pattern] - t.rspec_opts = '--format documentation' - end + task fixtures: ['frontend:fixtures'] desc 'GitLab | Karma | Run JavaScript tests' task tests: ['yarn:check'] do diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js index a8c8688441d..290c0e797cb 100644 --- a/spec/frontend/environment.js +++ b/spec/frontend/environment.js @@ -1,8 +1,11 @@ /* eslint-disable import/no-commonjs */ +const path = require('path'); const { ErrorWithStack } = require('jest-util'); const JSDOMEnvironment = require('jest-environment-jsdom'); +const ROOT_PATH = path.resolve(__dirname, '../..'); + class CustomEnvironment extends JSDOMEnvironment { constructor(config, context) { super(config, context); @@ -35,9 +38,8 @@ class CustomEnvironment extends JSDOMEnvironment { this.rejectedPromises.push(error); }; - this.global.fixturesBasePath = `${process.cwd()}/${ - IS_EE ? 'ee/' : '' - }spec/javascripts/fixtures`; + this.global.fixturesBasePath = `${ROOT_PATH}/tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`; + this.global.staticFixturesBasePath = `${ROOT_PATH}/spec/frontend/fixtures`; // Not yet supported by JSDOM: https://github.com/jsdom/jsdom/issues/317 this.global.document.createRange = () => ({ diff --git a/spec/javascripts/fixtures/abuse_reports.rb b/spec/frontend/fixtures/abuse_reports.rb similarity index 94% rename from spec/javascripts/fixtures/abuse_reports.rb rename to spec/frontend/fixtures/abuse_reports.rb index e0aaecf626a..21356390cae 100644 --- a/spec/javascripts/fixtures/abuse_reports.rb +++ b/spec/frontend/fixtures/abuse_reports.rb @@ -21,6 +21,6 @@ describe Admin::AbuseReportsController, '(JavaScript fixtures)', type: :controll it 'abuse_reports/abuse_reports_list.html' do get :index - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/admin_users.rb b/spec/frontend/fixtures/admin_users.rb similarity index 93% rename from spec/javascripts/fixtures/admin_users.rb rename to spec/frontend/fixtures/admin_users.rb index 22a5de66577..0209594dadc 100644 --- a/spec/javascripts/fixtures/admin_users.rb +++ b/spec/frontend/fixtures/admin_users.rb @@ -23,6 +23,6 @@ describe Admin::UsersController, '(JavaScript fixtures)', type: :controller do get :new - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/application_settings.rb b/spec/frontend/fixtures/application_settings.rb similarity index 95% rename from spec/javascripts/fixtures/application_settings.rb rename to spec/frontend/fixtures/application_settings.rb index d4651fa6ece..38a060580c1 100644 --- a/spec/javascripts/fixtures/application_settings.rb +++ b/spec/frontend/fixtures/application_settings.rb @@ -28,6 +28,6 @@ describe Admin::ApplicationSettingsController, '(JavaScript fixtures)', type: :c get :show - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/autocomplete_sources.rb b/spec/frontend/fixtures/autocomplete_sources.rb similarity index 96% rename from spec/javascripts/fixtures/autocomplete_sources.rb rename to spec/frontend/fixtures/autocomplete_sources.rb index b20a0159d7d..9e04328e2b9 100644 --- a/spec/javascripts/fixtures/autocomplete_sources.rb +++ b/spec/frontend/fixtures/autocomplete_sources.rb @@ -34,6 +34,6 @@ describe Projects::AutocompleteSourcesController, '(JavaScript fixtures)', type: type_id: issue.id } - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/blob.rb b/spec/frontend/fixtures/blob.rb similarity index 95% rename from spec/javascripts/fixtures/blob.rb rename to spec/frontend/fixtures/blob.rb index 07670552cd5..ce5030efbf8 100644 --- a/spec/javascripts/fixtures/blob.rb +++ b/spec/frontend/fixtures/blob.rb @@ -29,6 +29,6 @@ describe Projects::BlobController, '(JavaScript fixtures)', type: :controller do id: 'add-ipython-files/files/ipython/basic.ipynb' }) - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/boards.rb b/spec/frontend/fixtures/boards.rb similarity index 93% rename from spec/javascripts/fixtures/boards.rb rename to spec/frontend/fixtures/boards.rb index 5835721d3d5..f257d80390f 100644 --- a/spec/javascripts/fixtures/boards.rb +++ b/spec/frontend/fixtures/boards.rb @@ -23,6 +23,6 @@ describe Projects::BoardsController, '(JavaScript fixtures)', type: :controller project_id: project }) - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/branches.rb b/spec/frontend/fixtures/branches.rb similarity index 94% rename from spec/javascripts/fixtures/branches.rb rename to spec/frontend/fixtures/branches.rb index 204aa9b7c7a..197fe42c52a 100644 --- a/spec/javascripts/fixtures/branches.rb +++ b/spec/frontend/fixtures/branches.rb @@ -27,6 +27,6 @@ describe Projects::BranchesController, '(JavaScript fixtures)', type: :controlle project_id: project } - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/clusters.rb b/spec/frontend/fixtures/clusters.rb similarity index 95% rename from spec/javascripts/fixtures/clusters.rb rename to spec/frontend/fixtures/clusters.rb index 1076404e0e3..f15ef010807 100644 --- a/spec/javascripts/fixtures/clusters.rb +++ b/spec/frontend/fixtures/clusters.rb @@ -29,6 +29,6 @@ describe Projects::ClustersController, '(JavaScript fixtures)', type: :controlle id: cluster } - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/commit.rb b/spec/frontend/fixtures/commit.rb similarity index 94% rename from spec/javascripts/fixtures/commit.rb rename to spec/frontend/fixtures/commit.rb index ff9a4bc1adc..a328c455356 100644 --- a/spec/javascripts/fixtures/commit.rb +++ b/spec/frontend/fixtures/commit.rb @@ -28,6 +28,6 @@ describe Projects::CommitController, '(JavaScript fixtures)', type: :controller get :show, params: params - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/deploy_keys.rb b/spec/frontend/fixtures/deploy_keys.rb similarity index 97% rename from spec/javascripts/fixtures/deploy_keys.rb rename to spec/frontend/fixtures/deploy_keys.rb index 38eab853da2..fca233c6f59 100644 --- a/spec/javascripts/fixtures/deploy_keys.rb +++ b/spec/frontend/fixtures/deploy_keys.rb @@ -38,6 +38,6 @@ describe Projects::DeployKeysController, '(JavaScript fixtures)', type: :control project_id: project }, format: :json - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/groups.rb b/spec/frontend/fixtures/groups.rb similarity index 90% rename from spec/javascripts/fixtures/groups.rb rename to spec/frontend/fixtures/groups.rb index 4d0afc3ce1a..c1bb2d43332 100644 --- a/spec/javascripts/fixtures/groups.rb +++ b/spec/frontend/fixtures/groups.rb @@ -21,7 +21,7 @@ describe 'Groups (JavaScript fixtures)', type: :controller do it 'groups/edit.html' do get :edit, params: { id: group } - expect(response).to be_success + expect(response).to be_successful end end @@ -29,7 +29,7 @@ describe 'Groups (JavaScript fixtures)', type: :controller do it 'groups/ci_cd_settings.html' do get :show, params: { group_id: group } - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/javascripts/fixtures/issues.rb b/spec/frontend/fixtures/issues.rb similarity index 96% rename from spec/javascripts/fixtures/issues.rb rename to spec/frontend/fixtures/issues.rb index d8d77f767de..b5eb38e0023 100644 --- a/spec/javascripts/fixtures/issues.rb +++ b/spec/frontend/fixtures/issues.rb @@ -48,7 +48,7 @@ describe Projects::IssuesController, '(JavaScript fixtures)', type: :controller project_id: project } - expect(response).to be_success + expect(response).to be_successful end private @@ -60,7 +60,7 @@ describe Projects::IssuesController, '(JavaScript fixtures)', type: :controller id: issue.to_param } - expect(response).to be_success + expect(response).to be_successful end end @@ -117,6 +117,6 @@ describe API::Issues, '(JavaScript fixtures)', type: :request do get_related_merge_requests(project.id, issue.iid, user) - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/jobs.rb b/spec/frontend/fixtures/jobs.rb similarity index 95% rename from spec/javascripts/fixtures/jobs.rb rename to spec/frontend/fixtures/jobs.rb index 46ccd6f8c8a..a3a7759c85b 100644 --- a/spec/javascripts/fixtures/jobs.rb +++ b/spec/frontend/fixtures/jobs.rb @@ -39,7 +39,7 @@ describe Projects::JobsController, '(JavaScript fixtures)', type: :controller do id: build_with_artifacts.to_param } - expect(response).to be_success + expect(response).to be_successful end it 'jobs/delayed.json' do @@ -49,6 +49,6 @@ describe Projects::JobsController, '(JavaScript fixtures)', type: :controller do id: delayed_job.to_param }, format: :json - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/labels.rb b/spec/frontend/fixtures/labels.rb similarity index 95% rename from spec/javascripts/fixtures/labels.rb rename to spec/frontend/fixtures/labels.rb index 4d1b7317274..a312287970f 100644 --- a/spec/javascripts/fixtures/labels.rb +++ b/spec/frontend/fixtures/labels.rb @@ -35,7 +35,7 @@ describe 'Labels (JavaScript fixtures)' do group_id: group }, format: 'json' - expect(response).to be_success + expect(response).to be_successful end end @@ -52,7 +52,7 @@ describe 'Labels (JavaScript fixtures)' do project_id: project }, format: 'json' - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/javascripts/fixtures/merge_requests.rb b/spec/frontend/fixtures/merge_requests.rb similarity index 99% rename from spec/javascripts/fixtures/merge_requests.rb rename to spec/frontend/fixtures/merge_requests.rb index 05860be2291..88706e96676 100644 --- a/spec/javascripts/fixtures/merge_requests.rb +++ b/spec/frontend/fixtures/merge_requests.rb @@ -129,6 +129,6 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont id: merge_request.to_param }, format: :html - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/merge_requests_diffs.rb b/spec/frontend/fixtures/merge_requests_diffs.rb similarity index 98% rename from spec/javascripts/fixtures/merge_requests_diffs.rb rename to spec/frontend/fixtures/merge_requests_diffs.rb index 03b9b713fd8..b633a0495a6 100644 --- a/spec/javascripts/fixtures/merge_requests_diffs.rb +++ b/spec/frontend/fixtures/merge_requests_diffs.rb @@ -1,4 +1,3 @@ - require 'spec_helper' describe Projects::MergeRequests::DiffsController, '(JavaScript fixtures)', type: :controller do @@ -65,6 +64,6 @@ describe Projects::MergeRequests::DiffsController, '(JavaScript fixtures)', type **extra_params }, format: :json - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/pipeline_schedules.rb b/spec/frontend/fixtures/pipeline_schedules.rb similarity index 94% rename from spec/javascripts/fixtures/pipeline_schedules.rb rename to spec/frontend/fixtures/pipeline_schedules.rb index aecd56e6198..a70091a3919 100644 --- a/spec/javascripts/fixtures/pipeline_schedules.rb +++ b/spec/frontend/fixtures/pipeline_schedules.rb @@ -28,7 +28,7 @@ describe Projects::PipelineSchedulesController, '(JavaScript fixtures)', type: : id: pipeline_schedule.id } - expect(response).to be_success + expect(response).to be_successful end it 'pipeline_schedules/edit_with_variables.html' do @@ -38,6 +38,6 @@ describe Projects::PipelineSchedulesController, '(JavaScript fixtures)', type: : id: pipeline_schedule_populated.id } - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/pipelines.rb b/spec/frontend/fixtures/pipelines.rb similarity index 96% rename from spec/javascripts/fixtures/pipelines.rb rename to spec/frontend/fixtures/pipelines.rb index 6b6b0eefab9..ed57eb0aa80 100644 --- a/spec/javascripts/fixtures/pipelines.rb +++ b/spec/frontend/fixtures/pipelines.rb @@ -29,6 +29,6 @@ describe Projects::PipelinesController, '(JavaScript fixtures)', type: :controll project_id: project }, format: :json - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/projects.rb b/spec/frontend/fixtures/projects.rb similarity index 88% rename from spec/javascripts/fixtures/projects.rb rename to spec/frontend/fixtures/projects.rb index 94c59207898..b6c29003e57 100644 --- a/spec/javascripts/fixtures/projects.rb +++ b/spec/frontend/fixtures/projects.rb @@ -18,6 +18,8 @@ describe 'Projects (JavaScript fixtures)', type: :controller do end before do + stub_licensed_features(variable_environment_scope: true) + project.add_maintainer(admin) sign_in(admin) allow(SecureRandom).to receive(:hex).and_return('securerandomhex:thereisnospoon') @@ -34,7 +36,7 @@ describe 'Projects (JavaScript fixtures)', type: :controller do id: project } - expect(response).to be_success + expect(response).to be_successful end it 'projects/overview.html' do @@ -43,7 +45,7 @@ describe 'Projects (JavaScript fixtures)', type: :controller do id: project_with_repo } - expect(response).to be_success + expect(response).to be_successful end it 'projects/edit.html' do @@ -52,7 +54,7 @@ describe 'Projects (JavaScript fixtures)', type: :controller do id: project } - expect(response).to be_success + expect(response).to be_successful end end @@ -63,7 +65,7 @@ describe 'Projects (JavaScript fixtures)', type: :controller do project_id: project } - expect(response).to be_success + expect(response).to be_successful end it 'projects/ci_cd_settings_with_variables.html' do @@ -75,7 +77,7 @@ describe 'Projects (JavaScript fixtures)', type: :controller do project_id: project_variable_populated } - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/javascripts/fixtures/prometheus_service.rb b/spec/frontend/fixtures/prometheus_service.rb similarity index 95% rename from spec/javascripts/fixtures/prometheus_service.rb rename to spec/frontend/fixtures/prometheus_service.rb index f3171fdd97b..93ee81120d7 100644 --- a/spec/javascripts/fixtures/prometheus_service.rb +++ b/spec/frontend/fixtures/prometheus_service.rb @@ -29,6 +29,6 @@ describe Projects::ServicesController, '(JavaScript fixtures)', type: :controlle id: service.to_param } - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/raw.rb b/spec/frontend/fixtures/raw.rb similarity index 100% rename from spec/javascripts/fixtures/raw.rb rename to spec/frontend/fixtures/raw.rb diff --git a/spec/javascripts/fixtures/search.rb b/spec/frontend/fixtures/search.rb similarity index 87% rename from spec/javascripts/fixtures/search.rb rename to spec/frontend/fixtures/search.rb index 22fc546d761..c26c6998ae9 100644 --- a/spec/javascripts/fixtures/search.rb +++ b/spec/frontend/fixtures/search.rb @@ -12,6 +12,6 @@ describe SearchController, '(JavaScript fixtures)', type: :controller do it 'search/show.html' do get :show - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/services.rb b/spec/frontend/fixtures/services.rb similarity index 95% rename from spec/javascripts/fixtures/services.rb rename to spec/frontend/fixtures/services.rb index 2237702ccca..ee1e088f158 100644 --- a/spec/javascripts/fixtures/services.rb +++ b/spec/frontend/fixtures/services.rb @@ -29,6 +29,6 @@ describe Projects::ServicesController, '(JavaScript fixtures)', type: :controlle id: service.to_param } - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/javascripts/fixtures/sessions.rb b/spec/frontend/fixtures/sessions.rb similarity index 91% rename from spec/javascripts/fixtures/sessions.rb rename to spec/frontend/fixtures/sessions.rb index 92b74c01c89..18574ea06b5 100644 --- a/spec/javascripts/fixtures/sessions.rb +++ b/spec/frontend/fixtures/sessions.rb @@ -19,7 +19,7 @@ describe 'Sessions (JavaScript fixtures)' do it 'sessions/new.html' do get :new - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/javascripts/fixtures/snippet.rb b/spec/frontend/fixtures/snippet.rb similarity index 96% rename from spec/javascripts/fixtures/snippet.rb rename to spec/frontend/fixtures/snippet.rb index ace84b14eb7..23bcdb47ac6 100644 --- a/spec/javascripts/fixtures/snippet.rb +++ b/spec/frontend/fixtures/snippet.rb @@ -28,6 +28,6 @@ describe SnippetsController, '(JavaScript fixtures)', type: :controller do get(:show, params: { id: snippet.to_param }) - expect(response).to be_success + expect(response).to be_successful end end diff --git a/spec/frontend/fixtures/static/README.md b/spec/frontend/fixtures/static/README.md new file mode 100644 index 00000000000..011601d0df8 --- /dev/null +++ b/spec/frontend/fixtures/static/README.md @@ -0,0 +1,3 @@ +# Please do not add new files here! + +Instead use a Ruby file in the fixtures root directory (`spec/frontend/fixtures/`). diff --git a/spec/javascripts/fixtures/static/ajax_loading_spinner.html b/spec/frontend/fixtures/static/ajax_loading_spinner.html similarity index 100% rename from spec/javascripts/fixtures/static/ajax_loading_spinner.html rename to spec/frontend/fixtures/static/ajax_loading_spinner.html diff --git a/spec/javascripts/fixtures/static/balsamiq_viewer.html b/spec/frontend/fixtures/static/balsamiq_viewer.html similarity index 100% rename from spec/javascripts/fixtures/static/balsamiq_viewer.html rename to spec/frontend/fixtures/static/balsamiq_viewer.html diff --git a/spec/javascripts/fixtures/static/create_item_dropdown.html b/spec/frontend/fixtures/static/create_item_dropdown.html similarity index 100% rename from spec/javascripts/fixtures/static/create_item_dropdown.html rename to spec/frontend/fixtures/static/create_item_dropdown.html diff --git a/spec/javascripts/fixtures/static/environments/table.html b/spec/frontend/fixtures/static/environments/table.html similarity index 100% rename from spec/javascripts/fixtures/static/environments/table.html rename to spec/frontend/fixtures/static/environments/table.html diff --git a/spec/frontend/fixtures/static/environments_logs.html b/spec/frontend/fixtures/static/environments_logs.html new file mode 100644 index 00000000000..6179d3dbc23 --- /dev/null +++ b/spec/frontend/fixtures/static/environments_logs.html @@ -0,0 +1,29 @@ +
+
+
+
+ + +
+
+ +
+
+ +
+
+
+ +
+
+
+
+
+
+
+
diff --git a/spec/javascripts/fixtures/static/event_filter.html b/spec/frontend/fixtures/static/event_filter.html similarity index 100% rename from spec/javascripts/fixtures/static/event_filter.html rename to spec/frontend/fixtures/static/event_filter.html diff --git a/spec/javascripts/fixtures/static/gl_dropdown.html b/spec/frontend/fixtures/static/gl_dropdown.html similarity index 100% rename from spec/javascripts/fixtures/static/gl_dropdown.html rename to spec/frontend/fixtures/static/gl_dropdown.html diff --git a/spec/javascripts/fixtures/static/gl_field_errors.html b/spec/frontend/fixtures/static/gl_field_errors.html similarity index 100% rename from spec/javascripts/fixtures/static/gl_field_errors.html rename to spec/frontend/fixtures/static/gl_field_errors.html diff --git a/spec/javascripts/fixtures/static/images/green_box.png b/spec/frontend/fixtures/static/images/green_box.png similarity index 100% rename from spec/javascripts/fixtures/static/images/green_box.png rename to spec/frontend/fixtures/static/images/green_box.png diff --git a/spec/javascripts/fixtures/static/images/one_white_pixel.png b/spec/frontend/fixtures/static/images/one_white_pixel.png similarity index 100% rename from spec/javascripts/fixtures/static/images/one_white_pixel.png rename to spec/frontend/fixtures/static/images/one_white_pixel.png diff --git a/spec/javascripts/fixtures/static/images/red_box.png b/spec/frontend/fixtures/static/images/red_box.png similarity index 100% rename from spec/javascripts/fixtures/static/images/red_box.png rename to spec/frontend/fixtures/static/images/red_box.png diff --git a/spec/javascripts/fixtures/static/issuable_filter.html b/spec/frontend/fixtures/static/issuable_filter.html similarity index 100% rename from spec/javascripts/fixtures/static/issuable_filter.html rename to spec/frontend/fixtures/static/issuable_filter.html diff --git a/spec/javascripts/fixtures/static/issue_sidebar_label.html b/spec/frontend/fixtures/static/issue_sidebar_label.html similarity index 100% rename from spec/javascripts/fixtures/static/issue_sidebar_label.html rename to spec/frontend/fixtures/static/issue_sidebar_label.html diff --git a/spec/javascripts/fixtures/static/line_highlighter.html b/spec/frontend/fixtures/static/line_highlighter.html similarity index 100% rename from spec/javascripts/fixtures/static/line_highlighter.html rename to spec/frontend/fixtures/static/line_highlighter.html diff --git a/spec/javascripts/fixtures/static/linked_tabs.html b/spec/frontend/fixtures/static/linked_tabs.html similarity index 100% rename from spec/javascripts/fixtures/static/linked_tabs.html rename to spec/frontend/fixtures/static/linked_tabs.html diff --git a/spec/javascripts/fixtures/static/merge_requests_show.html b/spec/frontend/fixtures/static/merge_requests_show.html similarity index 100% rename from spec/javascripts/fixtures/static/merge_requests_show.html rename to spec/frontend/fixtures/static/merge_requests_show.html diff --git a/spec/javascripts/fixtures/static/mini_dropdown_graph.html b/spec/frontend/fixtures/static/mini_dropdown_graph.html similarity index 100% rename from spec/javascripts/fixtures/static/mini_dropdown_graph.html rename to spec/frontend/fixtures/static/mini_dropdown_graph.html diff --git a/spec/javascripts/fixtures/static/notebook_viewer.html b/spec/frontend/fixtures/static/notebook_viewer.html similarity index 100% rename from spec/javascripts/fixtures/static/notebook_viewer.html rename to spec/frontend/fixtures/static/notebook_viewer.html diff --git a/spec/javascripts/fixtures/static/oauth_remember_me.html b/spec/frontend/fixtures/static/oauth_remember_me.html similarity index 100% rename from spec/javascripts/fixtures/static/oauth_remember_me.html rename to spec/frontend/fixtures/static/oauth_remember_me.html diff --git a/spec/javascripts/fixtures/static/pdf_viewer.html b/spec/frontend/fixtures/static/pdf_viewer.html similarity index 100% rename from spec/javascripts/fixtures/static/pdf_viewer.html rename to spec/frontend/fixtures/static/pdf_viewer.html diff --git a/spec/javascripts/fixtures/static/pipeline_graph.html b/spec/frontend/fixtures/static/pipeline_graph.html similarity index 100% rename from spec/javascripts/fixtures/static/pipeline_graph.html rename to spec/frontend/fixtures/static/pipeline_graph.html diff --git a/spec/javascripts/fixtures/static/pipelines.html b/spec/frontend/fixtures/static/pipelines.html similarity index 100% rename from spec/javascripts/fixtures/static/pipelines.html rename to spec/frontend/fixtures/static/pipelines.html diff --git a/spec/javascripts/fixtures/static/project_select_combo_button.html b/spec/frontend/fixtures/static/project_select_combo_button.html similarity index 100% rename from spec/javascripts/fixtures/static/project_select_combo_button.html rename to spec/frontend/fixtures/static/project_select_combo_button.html diff --git a/spec/javascripts/fixtures/static/projects.json b/spec/frontend/fixtures/static/projects.json similarity index 100% rename from spec/javascripts/fixtures/static/projects.json rename to spec/frontend/fixtures/static/projects.json diff --git a/spec/javascripts/fixtures/static/search_autocomplete.html b/spec/frontend/fixtures/static/search_autocomplete.html similarity index 100% rename from spec/javascripts/fixtures/static/search_autocomplete.html rename to spec/frontend/fixtures/static/search_autocomplete.html diff --git a/spec/javascripts/fixtures/static/signin_tabs.html b/spec/frontend/fixtures/static/signin_tabs.html similarity index 100% rename from spec/javascripts/fixtures/static/signin_tabs.html rename to spec/frontend/fixtures/static/signin_tabs.html diff --git a/spec/javascripts/fixtures/static/sketch_viewer.html b/spec/frontend/fixtures/static/sketch_viewer.html similarity index 100% rename from spec/javascripts/fixtures/static/sketch_viewer.html rename to spec/frontend/fixtures/static/sketch_viewer.html diff --git a/spec/javascripts/fixtures/todos.rb b/spec/frontend/fixtures/todos.rb similarity index 94% rename from spec/javascripts/fixtures/todos.rb rename to spec/frontend/fixtures/todos.rb index d0c8a6eca01..a7c183d2414 100644 --- a/spec/javascripts/fixtures/todos.rb +++ b/spec/frontend/fixtures/todos.rb @@ -29,7 +29,7 @@ describe 'Todos (JavaScript fixtures)' do it 'todos/todos.html' do get :index - expect(response).to be_success + expect(response).to be_successful end end @@ -48,7 +48,7 @@ describe 'Todos (JavaScript fixtures)' do issuable_id: issue_2.id }, format: 'json' - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/javascripts/fixtures/u2f.rb b/spec/frontend/fixtures/u2f.rb similarity index 92% rename from spec/javascripts/fixtures/u2f.rb rename to spec/frontend/fixtures/u2f.rb index f52832b6efb..8ecbc0390cd 100644 --- a/spec/javascripts/fixtures/u2f.rb +++ b/spec/frontend/fixtures/u2f.rb @@ -23,7 +23,7 @@ context 'U2F' do post :create, params: { user: { login: user.username, password: user.password } } - expect(response).to be_success + expect(response).to be_successful end end @@ -38,7 +38,7 @@ context 'U2F' do it 'u2f/register.html' do get :show - expect(response).to be_success + expect(response).to be_successful end end end diff --git a/spec/frontend/helpers/fixtures.js b/spec/frontend/helpers/fixtures.js index b77bcd6266e..778196843db 100644 --- a/spec/frontend/helpers/fixtures.js +++ b/spec/frontend/helpers/fixtures.js @@ -4,12 +4,15 @@ import path from 'path'; import { ErrorWithStack } from 'jest-util'; export function getFixture(relativePath) { - const absolutePath = path.join(global.fixturesBasePath, relativePath); + const basePath = relativePath.startsWith('static/') + ? global.staticFixturesBasePath + : global.fixturesBasePath; + const absolutePath = path.join(basePath, relativePath); if (!fs.existsSync(absolutePath)) { throw new ErrorWithStack( `Fixture file ${relativePath} does not exist. -Did you run bin/rake karma:fixtures?`, +Did you run bin/rake frontend:fixtures?`, getFixture, ); } diff --git a/spec/javascripts/fixtures/.gitignore b/spec/javascripts/fixtures/.gitignore index bed020f5b0a..d6b7ef32c84 100644 --- a/spec/javascripts/fixtures/.gitignore +++ b/spec/javascripts/fixtures/.gitignore @@ -1,5 +1,2 @@ -*.html.raw -*.html -*.json -*.pdf -*.bmpr +* +!.gitignore diff --git a/spec/javascripts/fixtures/static/README.md b/spec/javascripts/fixtures/static/README.md deleted file mode 100644 index b5c2f8233bf..00000000000 --- a/spec/javascripts/fixtures/static/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not add new files here! - -Instead use a Ruby file in the fixtures root directory (`spec/javascripts/fixtures/`). diff --git a/spec/javascripts/test_constants.js b/spec/javascripts/test_constants.js index 77c206585fe..c97d47a6406 100644 --- a/spec/javascripts/test_constants.js +++ b/spec/javascripts/test_constants.js @@ -1,6 +1,4 @@ -export const FIXTURES_PATH = `/base/${ - process.env.IS_GITLAB_EE ? 'ee/' : '' -}spec/javascripts/fixtures`; +export const FIXTURES_PATH = `/fixtures`; export const TEST_HOST = 'http://test.host'; export const DUMMY_IMAGE_URL = `${FIXTURES_PATH}/static/images/one_white_pixel.png`; diff --git a/spec/support/helpers/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb index cdd7724cc13..e9129bd263e 100644 --- a/spec/support/helpers/javascript_fixtures_helpers.rb +++ b/spec/support/helpers/javascript_fixtures_helpers.rb @@ -19,7 +19,7 @@ module JavaScriptFixturesHelpers end def fixture_root_path - (Gitlab.ee? ? 'ee/' : '') + 'spec/javascripts/fixtures' + 'tmp/tests/frontend/fixtures' + (Gitlab.ee? ? '-ee' : '') end # Public: Removes all fixture files from given directory diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb index 16938da50cc..b062631b995 100644 --- a/spec/support/helpers/test_env.rb +++ b/spec/support/helpers/test_env.rb @@ -130,7 +130,7 @@ module TestEnv # Keeps gitlab-shell and gitlab-test def clean_test_path Dir[TMP_TEST_PATH].each do |entry| - unless File.basename(entry) =~ /\A(gitaly|gitlab-(shell|test|test_bare|test-fork|test-fork_bare))\z/ + unless test_dirs.include?(File.basename(entry)) FileUtils.rm_rf(entry) end end @@ -316,6 +316,7 @@ module TestEnv # These are directories that should be preserved at cleanup time def test_dirs @test_dirs ||= %w[ + frontend gitaly gitlab-shell gitlab-test