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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
f0666830
Commit
f0666830
authored
Mar 08, 2019
by
Winnie Hellmann
Committed by
Luke Bennett
Mar 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add setTestTimeout for Jest tests
Allows contributors to set the timeout for individual jest tests.
parent
26477f38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
16 deletions
+26
-16
spec/frontend/helpers/timeout.js
spec/frontend/helpers/timeout.js
+24
-0
spec/frontend/test_setup.js
spec/frontend/test_setup.js
+2
-16
No files found.
spec/frontend/helpers/timeout.js
0 → 100644
View file @
f0666830
let
testTimeoutInMs
;
export
const
setTestTimeout
=
newTimeoutInMs
=>
{
testTimeoutInMs
=
newTimeoutInMs
;
jest
.
setTimeout
(
newTimeoutInMs
);
};
export
const
initializeTestTimeout
=
defaultTimeoutInMs
=>
{
setTestTimeout
(
defaultTimeoutInMs
);
let
testStartTime
;
// https://github.com/facebook/jest/issues/6947
beforeEach
(()
=>
{
testStartTime
=
Date
.
now
();
});
afterEach
(()
=>
{
const
elapsedTimeInMs
=
Date
.
now
()
-
testStartTime
;
if
(
elapsedTimeInMs
>
testTimeoutInMs
)
{
throw
new
Error
(
`Test took too long (
${
elapsedTimeInMs
}
ms >
${
testTimeoutInMs
}
ms)!`
);
}
});
};
spec/frontend/test_setup.js
View file @
f0666830
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
Translate
from
'
~/vue_shared/translate
'
;
import
Translate
from
'
~/vue_shared/translate
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
initializeTestTimeout
}
from
'
./helpers/timeout
'
;
const
testTimeoutInMs
=
300
;
initializeTestTimeout
(
300
);
jest
.
setTimeout
(
testTimeoutInMs
);
let
testStartTime
;
// https://github.com/facebook/jest/issues/6947
beforeEach
(()
=>
{
testStartTime
=
Date
.
now
();
});
afterEach
(()
=>
{
const
elapsedTimeInMs
=
Date
.
now
()
-
testStartTime
;
if
(
elapsedTimeInMs
>
testTimeoutInMs
)
{
throw
new
Error
(
`Test took too long (
${
elapsedTimeInMs
}
ms >
${
testTimeoutInMs
}
ms)!`
);
}
});
// fail tests for unmocked requests
// fail tests for unmocked requests
beforeEach
(
done
=>
{
beforeEach
(
done
=>
{
...
...
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