debian-mirror-gitlab/spec/frontend_integration/test_helpers/fixtures.js

59 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
/* eslint-disable global-require */
// We use "require" rather than `fs` so that this works in a browser environment.
/* eslint "import/no-unresolved": 0 */
// We don't want to require *all* fixtures to be generated (especailly in a local environment).
// We use `eslint` instead of `eslint-disable`, so that we also don't trigger an `Unused eslint-disable directive` when all fixtures are present.
2020-10-24 23:57:45 +05:30
import { memoize } from 'lodash';
2021-02-22 17:27:13 +05:30
const createFactoryWithDefault = (fn, defaultValue) => () => {
try {
return fn();
} catch {
return defaultValue;
}
};
const factory = {
2021-03-08 18:12:59 +05:30
json: (fn) => createFactoryWithDefault(fn, { error: 'fixture not found' }),
text: (fn) => createFactoryWithDefault(fn, 'Hello world\nHow are you today?\n'),
binary: (fn) => createFactoryWithDefault(fn, ''),
2021-02-22 17:27:13 +05:30
};
export const getProject = factory.json(() => require('test_fixtures/api/projects/get.json'));
export const getEmptyProject = factory.json(() =>
require('test_fixtures/api/projects/get_empty.json'),
);
export const getBranch = factory.json(() =>
require('test_fixtures/api/projects/branches/get.json'),
);
export const getMergeRequests = factory.json(() =>
require('test_fixtures/api/merge_requests/get.json'),
);
2021-03-11 19:13:27 +05:30
export const getMergeRequestWithChanges = factory.json(() =>
require('test_fixtures/api/merge_requests/changes.json'),
);
export const getMergeRequestVersions = factory.json(() =>
require('test_fixtures/api/merge_requests/versions.json'),
);
2021-02-22 17:27:13 +05:30
export const getRepositoryFiles = factory.json(() =>
require('test_fixtures/projects_json/files.json'),
);
2021-04-29 21:17:54 +05:30
export const getDiffsMetadata = factory.json(() =>
require('test_fixtures/merge_request_diffs/diffs_metadata.json'),
);
export const getDiffsBatch = factory.json(() =>
require('test_fixtures/merge_request_diffs/diffs_batch.json'),
);
2021-02-22 17:27:13 +05:30
export const getPipelinesEmptyResponse = factory.json(() =>
require('test_fixtures/projects_json/pipelines_empty.json'),
);
2020-10-24 23:57:45 +05:30
export const getCommit = memoize(() => getBranch().commit);
2021-02-22 17:27:13 +05:30
export const getBlobReadme = factory.text(() => require('test_fixtures/blob/text/README.md'));
export const getBlobZip = factory.binary(() => require('test_fixtures/blob/binary/Gemfile.zip'));
export const getBlobImage = factory.binary(() =>
require('test_fixtures/blob/images/logo-white.png'),
);