Skip to content

Commit 69abb5b

Browse files
committed
chore: remove support for collecting deprecations without id
Simplifies the internal collector logic, to just collect a `Set` of ids.
1 parent bf20a15 commit 69abb5b

File tree

5 files changed

+26
-29
lines changed

5 files changed

+26
-29
lines changed

addon/index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const LOG_LIMIT = 100;
55
export default function setupDeprecationWorkflow(config) {
66
self.deprecationWorkflow = self.deprecationWorkflow || {};
77
self.deprecationWorkflow.deprecationLog = {
8-
messages: {},
8+
messages: new Set(),
99
};
1010

1111
registerDeprecationHandler((message, options, next) =>
@@ -51,10 +51,10 @@ export function flushDeprecations({ handler = 'silence' } = {}) {
5151
let messages = self.deprecationWorkflow.deprecationLog.messages;
5252
let logs = [];
5353

54-
for (let [deprecation, matcher] of Object.entries(messages)) {
54+
for (let id of messages.values()) {
5555
logs.push(
56-
` { handler: ${JSON.stringify(handler)}, ${matcher}: ${JSON.stringify(
57-
deprecation,
56+
` { handler: ${JSON.stringify(handler)}, matchId: ${JSON.stringify(
57+
id,
5858
)} }`,
5959
);
6060
}
@@ -108,10 +108,7 @@ export function handleDeprecationWorkflow(config, message, options, next) {
108108
}
109109

110110
export function deprecationCollector(message, options, next) {
111-
let key = (options && options.id) || message;
112-
let matchKey = options && key === options.id ? 'matchId' : 'matchMessage';
113-
114-
self.deprecationWorkflow.deprecationLog.messages[key] = matchKey;
111+
self.deprecationWorkflow.deprecationLog.messages.add(options.id);
115112

116113
next(message, options);
117114
}

tests/acceptance/flush-deprecations-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module('flushDeprecations', function (hooks) {
1010
});
1111

1212
hooks.afterEach(function () {
13-
window.deprecationWorkflow.deprecationLog = { messages: {} };
13+
window.deprecationWorkflow.deprecationLog = { messages: new Set() };
1414
window.Testem.handleConsoleMessage = originalWarn;
1515
});
1616

tests/acceptance/workflow-config-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module('workflow config', function (hooks) {
1212
});
1313

1414
hooks.afterEach(function () {
15-
window.deprecationWorkflow.deprecationLog = { messages: {} };
15+
window.deprecationWorkflow.deprecationLog = { messages: new Set() };
1616
window.Testem.handleConsoleMessage = originalWarn;
1717
});
1818

tests/unit/deprecation-collector-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module('deprecationCollector', function (hooks) {
1717
originalConfig = self.deprecationWorkflow = {
1818
config: null,
1919
deprecationLog: {
20-
messages: {},
20+
messages: new Set(),
2121
},
2222
};
2323
});
@@ -50,10 +50,10 @@ module('deprecationCollector', function (hooks) {
5050
() => {},
5151
);
5252

53-
assert.deepEqual(self.deprecationWorkflow.deprecationLog.messages, {
54-
first: 'matchId',
55-
second: 'matchId',
56-
});
53+
assert.deepEqual(
54+
self.deprecationWorkflow.deprecationLog.messages,
55+
new Set(['first', 'second']),
56+
);
5757
});
5858

5959
test('should call next', function (assert) {
@@ -119,9 +119,9 @@ module('deprecationCollector', function (hooks) {
119119
() => {},
120120
);
121121

122-
assert.deepEqual(self.deprecationWorkflow.deprecationLog.messages, {
123-
first: 'matchId',
124-
second: 'matchId',
125-
});
122+
assert.deepEqual(
123+
self.deprecationWorkflow.deprecationLog.messages,
124+
new Set(['first', 'second']),
125+
);
126126
});
127127
});

tests/unit/flush-deprecations-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ module('flushDeprecations', function (hooks) {
1616
originalConfig = self.deprecationWorkflow = {
1717
config: null,
1818
deprecationLog: {
19-
messages: [],
19+
messages: new Set(),
2020
},
2121
};
2222
});
2323

2424
hooks.afterEach(function () {
2525
self.deprecationWorkflow.config = originalConfig;
26-
self.deprecationWorkflow.deprecationLog = { messages: {} };
26+
self.deprecationWorkflow.deprecationLog = { messages: new Set() };
2727
console.warn = originalWarn;
2828
});
2929

3030
test('calling flushDeprecations returns workflow config', function (assert) {
31-
self.deprecationWorkflow.deprecationLog.messages = {
32-
first: 'matchId',
33-
second: 'matchId',
34-
};
31+
self.deprecationWorkflow.deprecationLog.messages = new Set([
32+
'first',
33+
'second',
34+
]);
3535

3636
let deprecationsPayload = flushDeprecations();
3737
assert.strictEqual(
@@ -48,10 +48,10 @@ setupDeprecationWorkflow({
4848
});
4949

5050
test('calling flushDeprecations with custom handler returns workflow config', function (assert) {
51-
self.deprecationWorkflow.deprecationLog.messages = {
52-
first: 'matchId',
53-
second: 'matchId',
54-
};
51+
self.deprecationWorkflow.deprecationLog.messages = new Set([
52+
'first',
53+
'second',
54+
]);
5555

5656
let deprecationsPayload = flushDeprecations({ handler: 'log' });
5757
assert.strictEqual(

0 commit comments

Comments
 (0)