Commit af3307f7 authored by Winnie Hellmann's avatar Winnie Hellmann

Add getJSONFixture() helper to Jest

parent aeffdd2a
...@@ -18,7 +18,6 @@ module.exports = { ...@@ -18,7 +18,6 @@ module.exports = {
moduleNameMapper: { moduleNameMapper: {
'^~(.*)$': '<rootDir>/app/assets/javascripts$1', '^~(.*)$': '<rootDir>/app/assets/javascripts$1',
'^ee(.*)$': '<rootDir>/ee/app/assets/javascripts$1', '^ee(.*)$': '<rootDir>/ee/app/assets/javascripts$1',
'^fixtures(.*)$': '<rootDir>/spec/javascripts/fixtures$1',
'^helpers(.*)$': '<rootDir>/spec/frontend/helpers$1', '^helpers(.*)$': '<rootDir>/spec/frontend/helpers$1',
'^vendor(.*)$': '<rootDir>/vendor/assets/javascripts$1', '^vendor(.*)$': '<rootDir>/vendor/assets/javascripts$1',
'\\.(jpg|jpeg|png|svg)$': '<rootDir>/spec/frontend/__mocks__/file_mock.js', '\\.(jpg|jpeg|png|svg)$': '<rootDir>/spec/frontend/__mocks__/file_mock.js',
......
...@@ -8,11 +8,12 @@ import 'vendor/jquery.atwho'; ...@@ -8,11 +8,12 @@ import 'vendor/jquery.atwho';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { setTestTimeout } from 'helpers/timeout'; import { setTestTimeout } from 'helpers/timeout';
import { getJSONFixture } from 'helpers/fixtures';
import labelsFixture from 'fixtures/autocomplete_sources/labels.json'; // eslint-disable-line import/no-unresolved
setTestTimeout(500); setTestTimeout(500);
const labelsFixture = getJSONFixture('autocomplete_sources/labels.json');
describe('GfmAutoComplete', () => { describe('GfmAutoComplete', () => {
const gfmAutoCompleteCallbacks = GfmAutoComplete.prototype.getDefaultCallbacks.call({ const gfmAutoCompleteCallbacks = GfmAutoComplete.prototype.getDefaultCallbacks.call({
fetchData: () => {}, fetchData: () => {},
......
/* 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);
}
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