Commit 97b8f85e authored by Mike Greiling's avatar Mike Greiling

Move frontend fixtures into spec/frontend

Moves every fixture source file from
spec/javascripts to spec/frontend
parent 1abe3e51
...@@ -60,8 +60,8 @@ Style/FrozenStringLiteralComment: ...@@ -60,8 +60,8 @@ Style/FrozenStringLiteralComment:
RSpec/FilePath: RSpec/FilePath:
Exclude: Exclude:
- 'qa/**/*' - 'qa/**/*'
- 'spec/javascripts/fixtures/*' - 'spec/frontend/fixtures/*'
- 'ee/spec/javascripts/fixtures/*' - 'ee/spec/frontend/fixtures/*'
- 'spec/requests/api/v3/*' - 'spec/requests/api/v3/*'
Naming/FileName: Naming/FileName:
......
...@@ -108,7 +108,7 @@ module.exports = function(config) { ...@@ -108,7 +108,7 @@ module.exports = function(config) {
process.env.TZ = 'Etc/UTC'; process.env.TZ = 'Etc/UTC';
const fixturesPath = `tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`; const fixturesPath = `tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`;
const staticFixturesPath = 'spec/javascripts/fixtures/static'; const staticFixturesPath = 'spec/frontend/fixtures/static';
const karmaConfig = { const karmaConfig = {
basePath: ROOT_PATH, basePath: ROOT_PATH,
......
...@@ -518,8 +518,8 @@ Information on setting up and running RSpec integration tests with ...@@ -518,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. 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: Fixtures for these tests are located at:
- `spec/javascripts/fixtures/`, for running tests in CE. - `spec/frontend/fixtures/`, for running tests in CE.
- `ee/spec/javascripts/fixtures/`, for running tests in EE. - `ee/spec/frontend/fixtures/`, for running tests in EE.
Fixture files in: Fixture files in:
...@@ -530,7 +530,7 @@ The following are examples of tests that work for both Karma and Jest: ...@@ -530,7 +530,7 @@ The following are examples of tests that work for both Karma and Jest:
```javascript ```javascript
it('makes a request', () => { 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); axiosMock.onGet(endpoint).reply(200, responseBody);
myButton.click(); myButton.click();
...@@ -539,7 +539,7 @@ it('makes a request', () => { ...@@ -539,7 +539,7 @@ it('makes a request', () => {
}); });
it('uses some HTML element', () => { 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'); const element = document.getElementById('#my-id');
...@@ -547,12 +547,12 @@ it('uses some HTML element', () => { ...@@ -547,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. 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`. This variable gets automagically set if the test is marked as `type: :request` or `type: :controller`.
Fixtures are regenerated using the `bin/rake frontend:fixtures` command but you can also generate them individually, Fixtures are regenerated using the `bin/rake frontend:fixtures` command but you can also generate them individually,
for example `bin/rspec spec/javascripts/fixtures/merge_requests.rb`. 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/`. 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 ## Gotchas
......
...@@ -2,7 +2,7 @@ unless Rails.env.production? ...@@ -2,7 +2,7 @@ unless Rails.env.production?
namespace :frontend do namespace :frontend do
desc 'GitLab | Frontend | Generate fixtures for JavaScript tests' desc 'GitLab | Frontend | Generate fixtures for JavaScript tests'
RSpec::Core::RakeTask.new(:fixtures, [:pattern]) do |t, args| RSpec::Core::RakeTask.new(:fixtures, [:pattern]) do |t, args|
args.with_defaults(pattern: '{spec,ee/spec}/javascripts/fixtures/*.rb') args.with_defaults(pattern: '{spec,ee/spec}/frontend/fixtures/*.rb')
ENV['NO_KNAPSACK'] = 'true' ENV['NO_KNAPSACK'] = 'true'
t.pattern = args[:pattern] t.pattern = args[:pattern]
t.rspec_opts = '--format documentation' t.rspec_opts = '--format documentation'
......
...@@ -39,7 +39,7 @@ class CustomEnvironment extends JSDOMEnvironment { ...@@ -39,7 +39,7 @@ class CustomEnvironment extends JSDOMEnvironment {
}; };
this.global.fixturesBasePath = `${ROOT_PATH}/tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`; this.global.fixturesBasePath = `${ROOT_PATH}/tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`;
this.global.staticFixturesBasePath = `${ROOT_PATH}/spec/javascripts/fixtures`; this.global.staticFixturesBasePath = `${ROOT_PATH}/spec/frontend/fixtures`;
// Not yet supported by JSDOM: https://github.com/jsdom/jsdom/issues/317 // Not yet supported by JSDOM: https://github.com/jsdom/jsdom/issues/317
this.global.document.createRange = () => ({ this.global.document.createRange = () => ({
......
require 'spec_helper' require 'spec_helper'
describe Projects::MergeRequests::DiffsController, '(JavaScript fixtures)', type: :controller do describe Projects::MergeRequests::DiffsController, '(JavaScript fixtures)', type: :controller do
......
# Please do not add new files here!
Instead use a Ruby file in the fixtures root directory (`spec/frontend/fixtures/`).
*.html.raw *
*.html !.gitignore
*.json
*.pdf
*.bmpr
# Please do not add new files here!
Instead use a Ruby file in the fixtures root directory (`spec/javascripts/fixtures/`).
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment