Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
9c223756
Commit
9c223756
authored
5 years ago
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add helpers for HTML fixtures to Jest
parent
346f7027
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
6 deletions
+20
-6
spec/frontend/helpers/fixtures.js
spec/frontend/helpers/fixtures.js
+20
-6
No files found.
spec/frontend/helpers/fixtures.js
View file @
9c223756
/* eslint-disable import/prefer-default-export, global-require, import/no-dynamic-require */
import
fs
from
'
fs
'
;
import
path
from
'
path
'
;
...
...
@@ -7,16 +5,32 @@ import { ErrorWithStack } from 'jest-util';
const
fixturesBasePath
=
path
.
join
(
process
.
cwd
(),
'
spec
'
,
'
javascripts
'
,
'
fixtures
'
);
export
function
get
JSONFixture
(
relativePath
,
ee
=
false
)
{
const
absolutePath
=
path
.
join
(
fixturesBasePath
,
ee
?
'
ee
'
:
''
,
relativePath
);
export
function
get
Fixture
(
relativePath
)
{
const
absolutePath
=
path
.
join
(
fixturesBasePath
,
relativePath
);
if
(
!
fs
.
existsSync
(
absolutePath
))
{
throw
new
ErrorWithStack
(
`Fixture file
${
relativePath
}
does not exist.
Did you run bin/rake karma:fixtures?`
,
get
JSON
Fixture
,
getFixture
,
);
}
return
require
(
absolutePath
);
return
fs
.
readFileSync
(
absolutePath
,
'
utf8
'
);
}
export
const
getJSONFixture
=
relativePath
=>
JSON
.
parse
(
getFixture
(
relativePath
));
export
const
resetHTMLFixture
=
()
=>
{
document
.
body
.
textContent
=
''
;
};
export
const
setHTMLFixture
=
(
htmlContent
,
resetHook
=
afterEach
)
=>
{
document
.
body
.
outerHTML
=
htmlContent
;
resetHook
(
resetHTMLFixture
);
};
export
const
loadHTMLFixture
=
(
relativePath
,
resetHook
=
afterEach
)
=>
{
const
fileContent
=
getFixture
(
relativePath
);
setHTMLFixture
(
fileContent
,
resetHook
);
};
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment