Add getJSONFixture() helper to Jest
This commit is contained in:
parent
aeffdd2acd
commit
af3307f7b4
|
@ -18,7 +18,6 @@ module.exports = {
|
|||
moduleNameMapper: {
|
||||
'^~(.*)$': '<rootDir>/app/assets/javascripts$1',
|
||||
'^ee(.*)$': '<rootDir>/ee/app/assets/javascripts$1',
|
||||
'^fixtures(.*)$': '<rootDir>/spec/javascripts/fixtures$1',
|
||||
'^helpers(.*)$': '<rootDir>/spec/frontend/helpers$1',
|
||||
'^vendor(.*)$': '<rootDir>/vendor/assets/javascripts$1',
|
||||
'\\.(jpg|jpeg|png|svg)$': '<rootDir>/spec/frontend/__mocks__/file_mock.js',
|
||||
|
|
|
@ -8,11 +8,12 @@ import 'vendor/jquery.atwho';
|
|||
|
||||
import { TEST_HOST } from 'helpers/test_constants';
|
||||
import { setTestTimeout } from 'helpers/timeout';
|
||||
|
||||
import labelsFixture from 'fixtures/autocomplete_sources/labels.json'; // eslint-disable-line import/no-unresolved
|
||||
import { getJSONFixture } from 'helpers/fixtures';
|
||||
|
||||
setTestTimeout(500);
|
||||
|
||||
const labelsFixture = getJSONFixture('autocomplete_sources/labels.json');
|
||||
|
||||
describe('GfmAutoComplete', () => {
|
||||
const gfmAutoCompleteCallbacks = GfmAutoComplete.prototype.getDefaultCallbacks.call({
|
||||
fetchData: () => {},
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/* eslint-disable import/prefer-default-export, global-require, import/no-dynamic-require */
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// jest-util is part of Jest
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { ErrorWithStack } from 'jest-util';
|
||||
|
||||
const fixturesBasePath = path.join(process.cwd(), 'spec', 'javascripts', 'fixtures');
|
||||
|
||||
export function getJSONFixture(relativePath, ee = false) {
|
||||
const absolutePath = path.join(fixturesBasePath, ee ? 'ee' : '', relativePath);
|
||||
if (!fs.existsSync(absolutePath)) {
|
||||
throw new ErrorWithStack(
|
||||
`Fixture file ${relativePath} does not exist.
|
||||
|
||||
Did you run bin/rake karma:fixtures?`,
|
||||
getJSONFixture,
|
||||
);
|
||||
}
|
||||
|
||||
return require(absolutePath);
|
||||
}
|
Loading…
Reference in New Issue