Skip to content

Commit 0a87725

Browse files
committed
feat: Allow passing a custom handler to flushDeprecations
1 parent 3c6f52d commit 0a87725

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

addon/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ export function detectWorkflow(config, message, options) {
4747
}
4848
}
4949

50-
export function flushDeprecations() {
50+
export function flushDeprecations({ handler = 'silence' } = {}) {
5151
let messages = self.deprecationWorkflow.deprecationLog.messages;
5252
let logs = [];
5353

5454
for (let [deprecation, matcher] of Object.entries(messages)) {
5555
logs.push(
56-
` { handler: "silence", ${matcher}: ${JSON.stringify(deprecation)} }`,
56+
` { handler: ${JSON.stringify(handler)}, ${matcher}: ${JSON.stringify(
57+
deprecation,
58+
)} }`,
5759
);
5860
}
5961

tests/unit/flush-deprecations-test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module('flushDeprecations', function (hooks) {
2727
console.warn = originalWarn;
2828
});
2929

30-
test('calling flushDeprecations returns string of deprecations', function (assert) {
30+
test('calling flushDeprecations returns workflow config', function (assert) {
3131
self.deprecationWorkflow.deprecationLog.messages = {
3232
first: 'matchId',
3333
second: 'matchId',
@@ -43,6 +43,26 @@ setupDeprecationWorkflow({
4343
{ handler: "silence", matchId: "first" },
4444
{ handler: "silence", matchId: "second" }
4545
]
46+
});`,
47+
);
48+
});
49+
50+
test('calling flushDeprecations with custom handler returns workflow config', function (assert) {
51+
self.deprecationWorkflow.deprecationLog.messages = {
52+
first: 'matchId',
53+
second: 'matchId',
54+
};
55+
56+
let deprecationsPayload = flushDeprecations({ handler: 'log' });
57+
assert.strictEqual(
58+
deprecationsPayload,
59+
`import setupDeprecationWorkflow from 'ember-cli-deprecation-workflow';
60+
61+
setupDeprecationWorkflow({
62+
workflow: [
63+
{ handler: "log", matchId: "first" },
64+
{ handler: "log", matchId: "second" }
65+
]
4666
});`,
4767
);
4868
});

0 commit comments

Comments
 (0)