Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
4ce814ba
Unverified
Commit
4ce814ba
authored
Jul 29, 2019
by
Ryan McKinley
Committed by
GitHub
Jul 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Utils: avoid calling console.warn() too often for deprecation warnings (#18269)
parent
8c49d277
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
1 deletions
+45
-1
packages/grafana-ui/src/utils/deprecationWarning.test.ts
+34
-0
packages/grafana-ui/src/utils/deprecationWarning.ts
+10
-0
public/app/core/utils/kbn.ts
+1
-1
No files found.
packages/grafana-ui/src/utils/deprecationWarning.test.ts
0 → 100644
View file @
4ce814ba
import
{
deprecationWarning
}
from
'./deprecationWarning'
;
test
(
'It should not output deprecation warnings too often'
,
()
=>
{
let
dateNowValue
=
10000000
;
const
spyConsoleWarn
=
jest
.
spyOn
(
console
,
'warn'
).
mockImplementation
();
const
spyDateNow
=
jest
.
spyOn
(
global
.
Date
,
'now'
).
mockImplementation
(()
=>
dateNowValue
);
// Make sure the mock works
expect
(
Date
.
now
()).
toEqual
(
dateNowValue
);
expect
(
console
.
warn
).
toHaveBeenCalledTimes
(
0
);
// Call the deprecation many times
deprecationWarning
(
'file'
,
'oldName'
,
'newName'
);
deprecationWarning
(
'file'
,
'oldName'
,
'newName'
);
deprecationWarning
(
'file'
,
'oldName'
,
'newName'
);
deprecationWarning
(
'file'
,
'oldName'
,
'newName'
);
deprecationWarning
(
'file'
,
'oldName'
,
'newName'
);
expect
(
console
.
warn
).
toHaveBeenCalledTimes
(
1
);
// Increment the time by 1min
dateNowValue
+=
60000
;
deprecationWarning
(
'file'
,
'oldName'
,
'newName'
);
deprecationWarning
(
'file'
,
'oldName'
,
'newName'
);
expect
(
console
.
warn
).
toHaveBeenCalledTimes
(
2
);
deprecationWarning
(
'file2'
,
'oldName'
,
'newName'
);
deprecationWarning
(
'file2'
,
'oldName'
,
'newName'
);
deprecationWarning
(
'file2'
,
'oldName'
,
'newName'
);
expect
(
console
.
warn
).
toHaveBeenCalledTimes
(
3
);
// or restoreMocks automatically?
spyConsoleWarn
.
mockRestore
();
spyDateNow
.
mockRestore
();
});
packages/grafana-ui/src/utils/deprecationWarning.ts
View file @
4ce814ba
import
{
KeyValue
}
from
'../types/index'
;
// Avoid writing the warning message more than once every 10s
const
history
:
KeyValue
<
number
>
=
{};
export
const
deprecationWarning
=
(
file
:
string
,
oldName
:
string
,
newName
?:
string
)
=>
{
let
message
=
`[Deprecation warning]
${
file
}
:
${
oldName
}
is deprecated`
;
if
(
newName
)
{
message
+=
`. Use
${
newName
}
instead`
;
}
const
now
=
Date
.
now
();
const
last
=
history
[
message
];
if
(
!
last
||
now
-
last
>
10000
)
{
console
.
warn
(
message
);
history
[
message
]
=
now
;
}
};
public/app/core/utils/kbn.ts
View file @
4ce814ba
...
...
@@ -229,7 +229,7 @@ kbn.slugifyForUrl = str => {
.replace(/ +/g, '-');
};
/** deprecated since 6.1, use grafana/
ui
*/
/** deprecated since 6.1, use grafana/
data
*/
kbn.stringToJsRegex = str => {
deprecationWarning('kbn.ts', 'kbn.stringToJsRegex()', '@grafana/data');
return stringToJsRegex(str);
...
...
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