Skip to content
Snippets Groups Projects
Unverified Commit 97b8f85e authored by Mike Greiling's avatar Mike Greiling
Browse files

Move frontend fixtures into spec/frontend

Moves every fixture source file from
spec/javascripts to spec/frontend
parent 1abe3e51
No related branches found
No related tags found
No related merge requests found
Showing
with 11 additions and 11 deletions
Loading
Loading
@@ -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:
Loading
Loading
Loading
Loading
@@ -108,7 +108,7 @@ module.exports = function(config) {
process.env.TZ = 'Etc/UTC';
 
const fixturesPath = `tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`;
const staticFixturesPath = 'spec/javascripts/fixtures/static';
const staticFixturesPath = 'spec/frontend/fixtures/static';
 
const karmaConfig = {
basePath: ROOT_PATH,
Loading
Loading
Loading
Loading
@@ -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.
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:
 
Loading
Loading
@@ -530,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();
Loading
Loading
@@ -539,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');
 
Loading
Loading
@@ -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.
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,
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/`.
 
## Gotchas
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@ 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}/javascripts/fixtures/*.rb')
args.with_defaults(pattern: '{spec,ee/spec}/frontend/fixtures/*.rb')
ENV['NO_KNAPSACK'] = 'true'
t.pattern = args[:pattern]
t.rspec_opts = '--format documentation'
Loading
Loading
Loading
Loading
@@ -39,7 +39,7 @@ class CustomEnvironment extends JSDOMEnvironment {
};
 
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
this.global.document.createRange = () => ({
Loading
Loading
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment