summaryrefslogtreecommitdiff
path: root/spec/frontend/helpers/fixtures.js
blob: f96f27c4d80d11407056491307a21b4f0f358d50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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);
}