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
Boxiang Sun
gitlab-ce
Commits
c0e743bf
Commit
c0e743bf
authored
Jun 05, 2019
by
Martin Hanzel
Committed by
Mike Greiling
Jun 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate old notes app test from Karma to Jest
parent
fabca7ab
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
291 additions
and
250 deletions
+291
-250
app/assets/javascripts/notes.js
app/assets/javascripts/notes.js
+4
-0
spec/frontend/helpers/jest_helpers.js
spec/frontend/helpers/jest_helpers.js
+24
-0
spec/frontend/helpers/timeout.js
spec/frontend/helpers/timeout.js
+18
-2
spec/frontend/notes/old_notes_spec.js
spec/frontend/notes/old_notes_spec.js
+245
-248
No files found.
app/assets/javascripts/notes.js
View file @
c0e743bf
...
@@ -7,6 +7,10 @@ no-unused-vars, no-shadow, no-useless-escape, class-methods-use-this */
...
@@ -7,6 +7,10 @@ no-unused-vars, no-shadow, no-useless-escape, class-methods-use-this */
/* global ResolveService */
/* global ResolveService */
/* global mrRefreshWidgetUrl */
/* global mrRefreshWidgetUrl */
/*
old_notes_spec.js is the spec for the legacy, jQuery notes application. It has nothing to do with the new, fancy Vue notes app.
*/
import
$
from
'
jquery
'
;
import
$
from
'
jquery
'
;
import
_
from
'
underscore
'
;
import
_
from
'
underscore
'
;
import
Cookies
from
'
js-cookie
'
;
import
Cookies
from
'
js-cookie
'
;
...
...
spec/frontend/helpers/jest_helpers.js
0 → 100644
View file @
c0e743bf
/* eslint-disable import/prefer-default-export */
/*
@module
This method provides convenience functions to help migrating from Karma/Jasmine to Jest.
Try not to use these in new tests - this module is provided primarily for convenience of migrating tests.
*/
/**
* Creates a plain JS object pre-populated with Jest spy functions. Useful for making simple mocks classes.
*
* @see https://jasmine.github.io/2.0/introduction.html#section-Spies:_%3Ccode%3EcreateSpyObj%3C/code%3E
* @param {string} baseName Human-readable name of the object. This is used for reporting purposes.
* @param methods {string[]} List of method names that will be added to the spy object.
*/
export
function
createSpyObj
(
baseName
,
methods
)
{
const
obj
=
{};
methods
.
forEach
(
method
=>
{
obj
[
method
]
=
jest
.
fn
().
mockName
(
`
${
baseName
}
#
${
method
}
`
);
});
return
obj
;
}
spec/frontend/helpers/timeout.js
View file @
c0e743bf
const
NS_PER_SEC
=
1
e9
;
const
NS_PER_SEC
=
1
e9
;
const
NS_PER_MS
=
1
e6
;
const
NS_PER_MS
=
1
e6
;
const
IS_DEBUGGING
=
process
.
execArgv
.
join
(
'
'
).
includes
(
'
--inspect-brk
'
);
let
testTimeoutNS
;
let
testTimeoutNS
;
...
@@ -8,6 +9,13 @@ export const setTestTimeout = newTimeoutMS => {
...
@@ -8,6 +9,13 @@ export const setTestTimeout = newTimeoutMS => {
jest
.
setTimeout
(
newTimeoutMS
);
jest
.
setTimeout
(
newTimeoutMS
);
};
};
// Allows slow tests to set their own timeout.
// Useful for tests with jQuery, which is very slow in big DOMs.
let
temporaryTimeoutNS
=
null
;
export
const
setTestTimeoutOnce
=
newTimeoutMS
=>
{
temporaryTimeoutNS
=
newTimeoutMS
*
NS_PER_MS
;
};
export
const
initializeTestTimeout
=
defaultTimeoutMS
=>
{
export
const
initializeTestTimeout
=
defaultTimeoutMS
=>
{
setTestTimeout
(
defaultTimeoutMS
);
setTestTimeout
(
defaultTimeoutMS
);
...
@@ -19,12 +27,20 @@ export const initializeTestTimeout = defaultTimeoutMS => {
...
@@ -19,12 +27,20 @@ export const initializeTestTimeout = defaultTimeoutMS => {
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
let
timeoutNS
=
testTimeoutNS
;
if
(
Number
.
isFinite
(
temporaryTimeoutNS
))
{
timeoutNS
=
temporaryTimeoutNS
;
temporaryTimeoutNS
=
null
;
}
const
[
seconds
,
remainingNs
]
=
process
.
hrtime
(
testStartTime
);
const
[
seconds
,
remainingNs
]
=
process
.
hrtime
(
testStartTime
);
const
elapsedNS
=
seconds
*
NS_PER_SEC
+
remainingNs
;
const
elapsedNS
=
seconds
*
NS_PER_SEC
+
remainingNs
;
if
(
elapsedNS
>
testTimeoutNS
)
{
// Disable the timeout error when debugging. It is meaningless because
// debugging always takes longer than the test timeout.
if
(
elapsedNS
>
timeoutNS
&&
!
IS_DEBUGGING
)
{
throw
new
Error
(
throw
new
Error
(
`Test took too long (
${
elapsedNS
/
NS_PER_MS
}
ms >
${
t
estT
imeoutNS
/
NS_PER_MS
}
ms)!`
,
`Test took too long (
${
elapsedNS
/
NS_PER_MS
}
ms >
${
timeoutNS
/
NS_PER_MS
}
ms)!`
,
);
);
}
}
});
});
...
...
spec/
javascripts/
notes_spec.js
→
spec/
frontend/notes/old_
notes_spec.js
View file @
c0e743bf
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