debian-mirror-gitlab/spec/frontend/__helpers__/fixtures.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1 KiB
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
import fs from 'fs';
import path from 'path';
import { ErrorWithStack } from 'jest-util';
export function getFixture(relativePath) {
2019-10-12 21:52:04 +05:30
const basePath = relativePath.startsWith('static/')
? global.staticFixturesBasePath
: global.fixturesBasePath;
const absolutePath = path.join(basePath, relativePath);
2019-07-07 11:18:12 +05:30
if (!fs.existsSync(absolutePath)) {
throw new ErrorWithStack(
`Fixture file ${relativePath} does not exist.
2023-07-09 08:55:56 +05:30
Did you run bin/rake frontend:fixtures? You can also download fixtures from the gitlab-org/gitlab package registry.
See https://docs.gitlab.com/ee/development/testing_guide/frontend_testing.html#download-fixtures for more info.
`,
2019-07-07 11:18:12 +05:30
getFixture,
);
}
return fs.readFileSync(absolutePath, 'utf8');
}
export const resetHTMLFixture = () => {
2020-05-24 23:13:21 +05:30
document.head.innerHTML = '';
document.body.innerHTML = '';
2019-07-07 11:18:12 +05:30
};
2022-07-16 23:28:13 +05:30
export const setHTMLFixture = (htmlContent) => {
2020-05-24 23:13:21 +05:30
document.body.innerHTML = htmlContent;
2019-07-07 11:18:12 +05:30
};
2022-07-16 23:28:13 +05:30
export const loadHTMLFixture = (relativePath) => {
setHTMLFixture(getFixture(relativePath));
2019-07-07 11:18:12 +05:30
};